o
    >@i                      @  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- e
rd d"lm.Z. ed#e.d$Z/dd)d*Z0ddd1d2Z1dd5d6Z2d+d7dd:d;Z3dd<d=Z4dd>d?Z5ddCdDZ6ddGdHZ7ddKdLZ8d+d+dMdNddSd%Z9ddUdVZ:ddXdYZ;dd[d\Zddd_d`Z<dddddeZ=ddgdhZ>ddjdkZ?ddodpZ@ddrdsZAddvdwZBddydzZCdd{d|ZDdd~dZEdddZFdddZGdS )    )annotationsN)Iterable)Mapping)IO)TYPE_CHECKING)TypeVar)parse_rfc3339)	Container)UnexpectedCharError)CUSTOM_ENCODERSAoT)Array)Bool)Comment)Date)DateTime)	DottedKey)Float)InlineTable)Integer)Item)Key)	SingleKey)String)
StringType)Table)Time)Trivia
Whitespace)item)ParserTOMLDocument)EncoderE)boundstringstr | bytesreturnr$   c                 C     t | S )zF
    Parses a string into a TOMLDocument.

    Alias for parse().
    )parser(    r.   I/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/tomlkit/api.pyloads.   s   r0   Fdatar   	sort_keysboolstrc              
   C  sh   t | tttfst | trtt| |d} z|  W S  ty3 } zdt	|  d}t
||d}~ww )z-
    Dumps a TOMLDocument into a string.
    )
_sort_keysz.Expecting Mapping or TOML Table or Container, z givenN)
isinstancer   r   r	   r   r!   dict	as_stringAttributeErrortype	TypeError)r1   r2   exmsgr.   r.   r/   dumps7   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/   loadI      rB   r2   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)
    rD   N)writer>   )r1   r?   r2   r.   r.   r/   dumpP   s   rH   c                 C     t |  S )z7
    Parses a string or bytes into a TOMLDocument.
    )r"   r,   r-   r.   r.   r/   r,   _   rC   r,   c                   C  s   t  S )z.
    Returns a new TOMLDocument instance.
    r#   r.   r.   r.   r/   documentf   s   rJ   raw	str | intr   c                 C     t t| S )z/Create an integer item from a number or string.)r!   intrK   r.   r.   r/   integern      rP   str | floatr   c                 C  rM   )z-Create an float item from a number or string.)r!   floatrO   r.   r.   r/   float_s   rQ   rT   
str | boolr   c                 C  s   t t| tr| dkS | S )z+Turn `true` or `false` into a boolean item.true)r!   r6   r4   rO   r.   r.   r/   booleanx   s   rW   T)literal	multilineescaperX   rY   rZ   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)rK   rX   rY   rZ   type_r.   r.   r/   r(   }   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   r6   	_datetimedate
ValueErrorr!   rK   valuer.   r.   r/   ra         ra   r   c                 C  r_   )zCreate a TOML time.z!time() only accepts time strings.)r   r6   r`   timerb   r!   rc   r.   r.   r/   rf      re   rf   r   c                 C  r_   )zCreate a TOML datetime.z)datetime() only accepts datetime strings.)r   r6   r`   datetimerb   r!   rc   r.   r.   r/   rg      re   rg   []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]
    )rd   rO   r.   r.   r/   array   s   ri   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   )rj   r.   r.   r/   table   s   rl   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   
rn   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   ro   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>)r6   r4   r   r   )rp   r.   r.   r/   rr      s   
rr   _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)rK   parservr.   r.   r/   rd     s
   rd   srctuple[Key, _Item]c                 C  rI   )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   rQ   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   encoderc                 C  s   t |  | S )a  Add a custom encoder, which should be a function that will be called
    if the value can't otherwise be converted.

    The encoder should return a TOMLKit item or raise a ``ConvertError``.

    Example:
        @register_encoder
        def encode_custom_dict(obj, _parent=None, _sort_keys=False):
            if isinstance(obj, CustomDict):
                tbl = table()
                for key, value in obj.items():
                    # Pass along parameters when encoding nested values
                    tbl[key] = item(value, _parent=tbl, _sort_keys=_sort_keys)
                return tbl
            raise ConvertError("Not a CustomDict")
    )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suppressrb   r   remover   r.   r.   r/   unregister_encoderD  s   "r   )r(   r)   r*   r$   )F)r1   r   r2   r3   r*   r4   )r?   r@   r*   r$   )r1   r   r?   rE   r2   r3   r*   rF   )r*   r$   )rK   rL   r*   r   )rK   rR   r*   r   )rK   rU   r*   r   )
rK   r4   rX   r3   rY   r3   rZ   r3   r*   r   )rK   r4   r*   r   )rK   r4   r*   r   )rK   r4   r*   r   )rh   )rK   r4   r*   r   )N)rj   rk   r*   r   )r*   r   )r*   r   )rp   rq   r*   r   )rK   r4   r*   rv   )r~   r4   r*   r   )r~   r4   r*   r    )r*   r    )r(   r4   r*   r   )r   r&   r*   r&   )r   r%   r*   rF   )H
__future__r   r   rg   r`   collections.abcr   r   typingr   r   r   tomlkit._utilsr   tomlkit.containerr	   tomlkit.exceptionsr
   tomlkit.itemsr   r   r   r   r   r   r   r   r   r   r   r   rv   r   r   r   r   r[   r   r   r   r    r!   tomlkit.parserr"   tomlkit.toml_documentr$   r%   r&   r0   r>   rB   rH   r,   rJ   rP   rT   rW   r(   ra   rf   ri   rl   rn   ro   rr   rd   r   r   r   r   r   r   r.   r.   r.   r/   <module>   s    
	







	
		








