U
    Te                     @  sJ  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- d"d#d$d%d&Z.dd(d)d*d+d,d-Z/d.d#d/d0d1Z0d'd2d(d3d)d4d5d6d7Z1d"d#d$d8d9Z2d#d:d;d<Z3d=d>d?d@dAZ4dBdCd?dDdEZ5d*dFd?dGdHZ6d'd'dIdJd*d)d)d)dKdLdMdNZ7d*dOd?dPdQZ8d*dRd?dSdTZ9d*dUd?dVdWZdd*dXd?dYdZZ:dd[d\d]d^d_Z;d`d:dadbZ<dcd:dddeZ=dfdgdhdidjZ>d*dkd?dldmZ?d*dndodpdqZ@d*drdodsdtZAdrd:dudvZBd*dwd$dxdyZCe
dzed{ZDdzdzd|d}d~ZEdd4d|dd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TOMLDocumentzstr | bytesr%   )stringreturnc                 C  s   t | S )zF
    Parses a string into a TOMLDocument.

    Alias for parse().
    )parser&    r*   j/mounts/lovelace/software/anaconda3/envs/qiime2-amplicon-2024.2/lib/python3.8/site-packages/tomlkit/api.pyloads(   s    r,   Fr   boolstr)data	sort_keysr'   c              
   C  sp   t | ts$t | tr$tt| |d} z
|  W S  tk
rj } zdt|  d}t||W 5 d}~X Y nX dS )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:   zIO[str] | IO[bytes])fpr'   c                 C  s   t |  S )z5
    Load toml document from a file-like object.
    )r(   read)r;   r*   r*   r+   loadA   s    r=   r0   zIO[str]None)r/   r;   r0   r'   c                C  s   | t| |d dS )z
    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
    r>   N)writer:   )r/   r;   r0   r*   r*   r+   dumpH   s    rA   c                 C  s   t |  S )z7
    Parses a string or bytes into a TOMLDocument.
    )r#   r(   r)   r*   r*   r+   r(   R   s    r(   )r'   c                   C  s   t  S )z.
    Returns a new TOMLDocument instance.
    r$   r*   r*   r*   r+   documentY   s    rB   z	str | intr   )rawr'   c                 C  s   t t| S )z/Create an integer item from a number or string.)r"   intrC   r*   r*   r+   integera   s    rF   zstr | floatr   c                 C  s   t t| S )z-Create an float item from a number or string.)r"   floatrE   r*   r*   r+   float_f   s    rH   r   c                 C  s   t | dkS )z+Turn `true` or `false` into a boolean item.truer!   rE   r*   r*   r+   booleank   s    rJ   T)literal	multilineescaper   )rC   rK   rL   rM   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   Zfrom_raw)rC   rK   rL   rM   type_r*   r*   r+   r&   p   s    r&   r   c                 C  s$   t | }t|tjstdt|S )zCreate a TOML date.z!date() only accepts date strings.)r   r2   	_datetimedate
ValueErrorr"   rC   valuer*   r*   r+   rR      s    rR   r   c                 C  s$   t | }t|tjstdt|S )zCreate a TOML time.z!time() only accepts time strings.)r   r2   rQ   timerS   r"   rT   r*   r*   r+   rV      s    rV   r   c                 C  s$   t | }t|tjstdt|S )zCreate a TOML datetime.z)datetime() only accepts datetime strings.)r   r2   rQ   datetimerS   r"   rT   r*   r*   r+   rW      s    rW   r   c                 C  s   | dkrd} t | S )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]
    Nz[])rU   rE   r*   r*   r+   array   s    rX   zbool | Noner   )is_super_tabler'   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   )rY   r*   r*   r+   table   s    rZ   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    
r\   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    r]   zstr | Iterable[str]r   )kr'   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>)r2   r.   r   r   )r^   r*   r*   r+   r_      s    
r_   _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#   Z_parse_valueendZparse_errorr	   _current)rC   parservr*   r*   r+   rU      s
    rU   ztuple[Key, _Item])srcr'   c                 C  s   t |  S )zkParse a key-value pair from a string.

    :Example:

    >>> key_value("foo = 1")
    (Key('foo'), 1)
    )r#   Z_parse_key_valueri   r*   r*   r+   	key_value  s    rk   r    c                 C  s   t | ddS )z"Create a whitespace from a string.T)fixedr   rj   r*   r*   r+   ws  s    rm   c                   C  s   t dS )zCreate a newline item.
)rm   r*   r*   r*   r+   nl  s    ro   r   c                 C  s   t tdd|  dS )zCreate a comment item.z  z# )Z
comment_wscomment)r   r   r)   r*   r*   r+   rp      s    rp   E)bound)encoderr'   c                 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rs   r*   r*   r+   register_encoder(  s    
rv   r   c              	   C  s$   t t t|  W 5 Q R X dS )zUnregister a custom encoder.N)
contextlibsuppressrS   r
   removeru   r*   r*   r+   unregister_encoder1  s    rz   )F)N)N)G
__future__r   rw   rW   rQ   collections.abcr   typingr   r   r   Ztomlkit._utilsr   Ztomlkit.containerr   Ztomlkit.exceptionsr	   Ztomlkit.itemsr
   r   r   r   r   r   r   r   r   r   r   r   r   rc   r   r   r   r   rN   r   r   r   r    r"   Ztomlkit.parserr#   Ztomlkit.toml_documentr%   r,   r:   r=   rA   r(   rB   rF   rH   rJ   r&   rR   rV   rX   rZ   r\   r]   r_   rU   rk   rm   ro   rp   rq   rv   rz   r*   r*   r*   r+   <module>   s|   	
				