o
    UhS                     @  s  d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm Z  d dlm!Z! d dlm"Z" d dlm#Z$ d dlm%Z% d dlm&Z& d dlm'Z' d dlm(Z( d dlm)Z) d d l*m+Z+ d d!l,m-Z- dd&d'Z.ddd.d/Z/dd2d3Z0d(d4dd7d8Z1dd9d:Z2dd;d<Z3dd@dAZ4ddDdEZ5ddGdHZ6d(d(dIdJddOd"Z7ddQdRZ8ddTdUZ9ddWdXZddd[d\Z:ddd`daZ;ddcddZ<ddfdgZ=ddkdlZ>ddndoZ?ddrdsZ@ddudvZAddwdxZBddzd{ZCe
d|ed}ZDdddZEdddZFdS )    )annotationsN)Mapping)IO)Iterable)TypeVar)parse_rfc3339)	Container)UnexpectedCharError)CUSTOM_ENCODERSAoT)Array)Bool)Comment)Date)DateTime)	DottedKey)Encoder)Float)InlineTable)Integer)Item)Key)	SingleKey)String)
StringType)Table)Time)Trivia
Whitespaceitem)ParserTOMLDocumentstringstr | bytesreturnr%   c                 C     t | S )zF
    Parses a string into a TOMLDocument.

    Alias for parse().
    )parser&    r,   _/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/tomlkit/api.pyloads(   s   r.   Fdatar   	sort_keysboolstrc              
   C  sb   t | tst | trtt| |d} z|  W S  ty0 } zdt|  d}t||d}~ww )z-
    Dumps a TOMLDocument into a string.
    )
_sort_keysz%Expecting Mapping or TOML Container, z givenN)	
isinstancer   r   r"   dict	as_stringAttributeErrortype	TypeError)r/   r0   exmsgr,   r,   r-   dumps1   s   

r<   fpIO[str] | IO[bytes]c                 C  s   t |  S )z5
    Load toml document from a file-like object.
    )r*   read)r=   r,   r,   r-   loadA      r@   r0   IO[str]Nonec                C  s   | t| |d dS )a  
    Dump a TOMLDocument into a writable file stream.

    :param data: a dict-like object to dump
    :param sort_keys: if true, sort the keys in alphabetic order

    :Example:

    >>> with open("output.toml", "w") as fp:
    ...     tomlkit.dump(data, fp)
    rB   N)writer<   )r/   r=   r0   r,   r,   r-   dumpH   s   rF   c                 C     t |  S )z7
    Parses a string or bytes into a TOMLDocument.
    )r#   r*   r+   r,   r,   r-   r*   W   rA   r*   c                   C  s   t  S )z.
    Returns a new TOMLDocument instance.
    r$   r,   r,   r,   r-   document^   s   rH   raw	str | intr   c                 C     t t| S )z/Create an integer item from a number or string.)r"   intrI   r,   r,   r-   integerf      rN   str | floatr   c                 C  rK   )z-Create an float item from a number or string.)r"   floatrM   r,   r,   r-   float_k   rO   rR   r   c                 C  s   t | dkS )z+Turn `true` or `false` into a boolean item.truer!   rM   r,   r,   r-   booleanp   rO   rT   T)literal	multilineescaperU   rV   rW   r   c                C  s   t ||}t| ||S )aB  Create a string item.

    By default, this function will create *single line basic* strings, but
    boolean flags (e.g. ``literal=True`` and/or ``multiline=True``)
    can be used for personalization.

    For more information, please check the spec: `<https://toml.io/en/v1.0.0#string>`__.

    Common escaping rules will be applied for basic strings.
    This can be controlled by explicitly setting ``escape=False``.
    Please note that, if you disable escaping, you will have to make sure that
    the given strings don't contain any forbidden character or sequence.
    )_StringTypeselectr   from_raw)rI   rU   rV   rW   type_r,   r,   r-   r&   u   s   r   c                 C  $   t | }t|tjstdt|S )zCreate a TOML date.z!date() only accepts date strings.)r   r4   	_datetimedate
ValueErrorr"   rI   valuer,   r,   r-   r^         r^   r   c                 C  r\   )zCreate a TOML time.z!time() only accepts time strings.)r   r4   r]   timer_   r"   r`   r,   r,   r-   rc      rb   rc   r   c                 C  r\   )zCreate a TOML datetime.z)datetime() only accepts datetime strings.)r   r4   r]   datetimer_   r"   r`   r,   r,   r-   rd      rb   rd   []r   c                 C  r)   )zCreate an array item for its string representation.

    :Example:

    >>> array("[1, 2, 3]")  # Create from a string
    [1, 2, 3]
    >>> a = array()
    >>> a.extend([1, 2, 3])  # Create from a list
    >>> a
    [1, 2, 3]
    )ra   rM   r,   r,   r-   array   s   rf   is_super_tablebool | Noner   c                 C  s   t t t d| S )aF  Create an empty table.

    :param is_super_table: if true, the table is a super table

    :Example:

    >>> doc = document()
    >>> foo = table(True)
    >>> bar = table()
    >>> bar.update({'x': 1})
    >>> foo.append('bar', bar)
    >>> doc.append('foo', foo)
    >>> print(doc.as_string())
    [foo.bar]
    x = 1
    F)r   r   r   )rg   r,   r,   r-   table   s   ri   r   c                   C  s   t t t ddS )zCreate an inline table.

    :Example:

    >>> table = inline_table()
    >>> table.update({'x': 1, 'y': 2})
    >>> print(table.as_string())
    {x = 1, y = 2}
    T)new)r   r   r   r,   r,   r,   r-   inline_table   s   
rk   r   c                   C  s   t g S )zCreate an array of table.

    :Example:

    >>> doc = document()
    >>> aot = aot()
    >>> aot.append(item({'x': 1}))
    >>> doc.append('foo', aot)
    >>> print(doc.as_string())
    [[foo]]
    x = 1
    r   r,   r,   r,   r-   aot   s   rl   kstr | Iterable[str]r   c                 C  s$   t | tr	t| S tdd | D S )a  Create a key from a string. When a list of string is given,
    it will create a dotted key.

    :Example:

    >>> doc = document()
    >>> doc.append(key('foo'), 1)
    >>> doc.append(key(['bar', 'baz']), 2)
    >>> print(doc.as_string())
    foo = 1
    bar.baz = 2
    c                 S  s   g | ]}t |qS r,   )key).0_kr,   r,   r-   
<listcomp>   s    zkey.<locals>.<listcomp>)r4   r2   r   r   )rm   r,   r,   r-   ro      s   
ro   _Itemc                 C  s,   t | }| }| s|jt|jd|S )zParse a simple value from a string.

    :Example:

    >>> value("1")
    1
    >>> value("true")
    True
    >>> value("[1, 2, 3]")
    [1, 2, 3]
    )char)r#   _parse_valueendparse_errorr	   _current)rI   parservr,   r,   r-   ra      s
   ra   srctuple[Key, _Item]c                 C  rG   )zkParse a key-value pair from a string.

    :Example:

    >>> key_value("foo = 1")
    (Key('foo'), 1)
    )r#   _parse_key_valuer{   r,   r,   r-   	key_value  s   r   r    c                 C  s   t | ddS )z"Create a whitespace from a string.T)fixedr   r~   r,   r,   r-   ws  rO   r   c                   C  s   t dS )zCreate a newline item.
)r   r,   r,   r,   r-   nl  s   r   r   c                 C  s   t tdd|  dS )zCreate a comment item.z  z# )
comment_wscomment)r   r   r+   r,   r,   r-   r   "  s   r   E)boundencoderc                 C  s   t |  | S )zAdd a custom encoder, which should be a function that will be called
    if the value can't otherwise be converted. It should takes a single value
    and return a TOMLKit item or raise a ``TypeError``.
    )r
   appendr   r,   r,   r-   register_encoder*  s   
r   r   c                 C  s:   t t t|  W d   dS 1 sw   Y  dS )zUnregister a custom encoder.N)
contextlibsuppressr_   r
   remover   r,   r,   r-   unregister_encoder3  s   "r   )r&   r'   r(   r%   )F)r/   r   r0   r1   r(   r2   )r=   r>   r(   r%   )r/   r   r=   rC   r0   r1   r(   rD   )r(   r%   )rI   rJ   r(   r   )rI   rP   r(   r   )rI   r2   r(   r   )
rI   r2   rU   r1   rV   r1   rW   r1   r(   r   )rI   r2   r(   r   )rI   r2   r(   r   )rI   r2   r(   r   )re   )rI   r2   r(   r   )N)rg   rh   r(   r   )r(   r   )r(   r   )rm   rn   r(   r   )rI   r2   r(   rs   )r{   r2   r(   r|   )r{   r2   r(   r    )r(   r    )r&   r2   r(   r   )r   r   r(   r   )r   r   r(   rD   )G
__future__r   r   rd   r]   collections.abcr   typingr   r   r   tomlkit._utilsr   tomlkit.containerr   tomlkit.exceptionsr	   tomlkit.itemsr
   r   r   r   r   r   r   r   r   r   r   r   r   rs   r   r   r   r   rX   r   r   r   r    r"   tomlkit.parserr#   tomlkit.toml_documentr%   r.   r<   r@   rF   r*   rH   rN   rR   rT   r&   r^   rc   rf   ri   rk   rl   ro   ra   r   r   r   r   r   r   r   r,   r,   r,   r-   <module>   s~    
	







	
		








	