
    tni                        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
rd d"lm.Z.  ed#e.$          Z/dnd)Z0dodpd0Z1dqd3Z2d*d4drd7Z3dnd8Z4dsd9Z5dtd=Z6dud@Z7dvdCZ8d*d*dDdEdwdJZ9dxdLZ:dydNZ;dzdPZd{d|dSZ<d}d~dWZ=ddYZ>dd[Z?dd_Z@ddaZAdddZBddfZCddgZDddiZEddkZFddm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                     t          |           S )zF
    Parses a string into a TOMLDocument.

    Alias for parse().
    )parser)   s    H/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/tomlkit/api.pyloadsr0   .   s     ==    Fdatar   	sort_keysboolstrc                @   t          | t          t          t          f          s3t          | t                    rt          t          |           |          } 	 |                                 S # t          $ r(}dt          |            d}t          |          |d}~ww xY 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)r2   r3   exmsgs       r/   dumpsr@   7   s     dUK;<< 6gB B 6 DJJ9555% ~~ % % %QtDzzQQQnn"$%s   A+ +
B5#BBfpIO[str] | IO[bytes]c                D    t          |                                           S )z5
    Load toml document from a file-like object.
    )r-   read)rA   s    r/   loadrE   I   s     r1   r3   IO[str]Nonec               N    |                     t          | |                     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)
    rF   N)writer@   )r2   rA   r3   s      r/   dumprK   P   s)     HHU49---.....r1   c                D    t          |                                           S )z7
    Parses a string or bytes into a TOMLDocument.
    )r#   r-   r.   s    r/   r-   r-   _   s     &>>!!!r1   c                     t                      S )z.
    Returns a new TOMLDocument instance.
    r$    r1   r/   documentrO   f   s     >>r1   raw	str | intr   c                :    t          t          |                     S )z/Create an integer item from a number or string.)r"   intrP   s    r/   integerrU   n   s    C>>r1   str | floatr   c                :    t          t          |                     S )z-Create an float item from a number or string.)r"   floatrT   s    r/   float_rY   s   s    c

r1   
str | boolr   c                V    t          t          | t                    r| dk    n|           S )z+Turn `true` or `false` into a boolean item.true)r"   r8   r5   rT   s    r/   booleanr]   x   s'    C!5!5>v3???r1   T)literal	multilineescaper^   r_   r`   r   c               X    t          j        ||          }t          j        | ||          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)rP   r^   r_   r`   type_s        r/   r)   r)   }   s*    ( w	22E?3v...r1   r   c                    t          |           }t          |t          j                  st	          d          t          |          S )zCreate a TOML date.z!date() only accepts date strings.)r	   r8   	_datetimedate
ValueErrorr"   rP   values     r/   rh   rh      >    #EeY^,, ><===;;r1   r   c                    t          |           }t          |t          j                  st	          d          t          |          S )zCreate a TOML time.z!time() only accepts time strings.)r	   r8   rg   timeri   r"   rj   s     r/   rn   rn      rl   r1   r   c                    t          |           }t          |t          j                  st	          d          t          |          S )zCreate a TOML datetime.z)datetime() only accepts datetime strings.)r	   r8   rg   datetimeri   r"   rj   s     r/   rp   rp      s@    #EeY/00 FDEEE;;r1   []r   c                     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]
    )rk   rT   s    r/   arrayrs      s     ::r1   is_super_tablebool | Noner   c                V    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   )rt   s    r/   tablerw      s     " fhh~>>>r1   r   c                 V    t          t                      t                      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   rN   r1   r/   inline_tablerz      s!     y{{FHH$7777r1   r   c                      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   rN   r1   r/   aotr|      s     r77Nr1   kstr | Iterable[str]r   c                |    t          | t                    rt          |           S t          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                ,    g | ]}t          |          S rN   )key).0_ks     r/   
<listcomp>zkey.<locals>.<listcomp>   s    ***"c"gg***r1   )r8   r5   r   r   )r}   s    r/   r   r      s?     !S ||*****+++r1   _Itemc                    t          |           }|                                }|                                s!|                    t          |j                  |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)rP   parservs      r/   rk   rk     sR     C[[FA::<< L  !46? KKKHr1   srctuple[Key, _Item]c                D    t          |                                           S )zkParse a key-value pair from a string.

    :Example:

    >>> key_value("foo = 1")
    (Key('foo'), 1)
    )r#   _parse_key_valuer   s    r/   	key_valuer     s     #;;'')))r1   r!   c                $    t          | d          S )z"Create a whitespace from a string.T)fixedr    r   s    r/   wsr      s    c&&&&r1   c                      t          d          S )zCreate a newline item.
)r   rN   r1   r/   nlr   %  s    d88Or1   r   c                D    t          t          dd| z                       S )zCreate a comment item.z  z# )
comment_wscomment)r   r   r.   s    r/   r   r   *  s!    6T4&=AAABBBr1   encoderc                .    t          j        |            | 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   s    r/   register_encoderr   /  s    " 7###Nr1   r&   c                    t          j        t                    5  t          j        |            ddd           dS # 1 swxY w Y   dS )zUnregister a custom encoder.N)
contextlibsuppressri   r   remover   s    r/   unregister_encoderr   D  s    		Z	(	( ( (w'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   <A A )r)   r*   r+   r%   )F)r2   r   r3   r4   r+   r5   )rA   rB   r+   r%   )r2   r   rA   rG   r3   r4   r+   rH   )r+   r%   )rP   rQ   r+   r   )rP   rV   r+   r   )rP   rZ   r+   r   )
rP   r5   r^   r4   r_   r4   r`   r4   r+   r   )rP   r5   r+   r   )rP   r5   r+   r   )rP   r5   r+   r   )rq   )rP   r5   r+   r   )N)rt   ru   r+   r   )r+   r   )r+   r   )r}   r~   r+   r   )rP   r5   r+   r   )r   r5   r+   r   )r   r5   r+   r!   )r+   r!   )r)   r5   r+   r   )r   r'   r+   r'   )r   r&   r+   rH   )H
__future__r   r   rp   rg   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   r   r   r   r   r   rb   r   r   r   r!   r"   tomlkit.parserr#   tomlkit.toml_documentr%   r&   r'   r0   r@   rE   rK   r-   rO   rU   rY   r]   r)   rh   rn   rs   rw   rz   r|   r   rk   r   r   r   r   r   r   rN   r1   r/   <module>r      s   " " " " " "         $ $ $ $ $ $ # # # # # #                         ( ( ( ( ( ( ' ' ' ' ' ' 2 2 2 2 2 2 ) ) ) ) ) )                   ! ! ! ! ! !       " " " " " " # # # # # #       % % % % % % ! ! ! ! ! ! ' ' ' ' ' '       # # # # # #             3 3 3 3 3 3                         $ $ $ $ $ $       ! ! ! ! ! ! . . . . . .  $%%%%%%7###A   % % % % %$    ;@ / / / / / /" " " "      
   
@ @ @ @ / / / / / /0             ? ? ? ? ?(
8 
8 
8 
8    , , , ,$   &* * * *' ' ' '
   
C C C C
   *( ( ( ( ( (r1   