
    ei                        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/dBd%Z0dCdDd'Z1dEd(Z2d&d)dFd*Z3dBd+Z4dGd,Z5dHd-Z6dId.Z7dJd/Z8d&d&d0d1	 	 	 	 	 	 	 	 	 dKd2Z9dLd3Z:dMd4Z;dNd5ZdOdPd6Z<dQdRd7Z=dSd8Z>dTd9Z?dUd:Z@dVd;ZAdWd<ZBdXd=ZCdYd>ZDdZd?ZEd[d@ZFd\dAZGy)]    )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)boundc                    t        |       S )zF
    Parses a string into a TOMLDocument.

    Alias for parse().
    )parsestrings    M/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/tomlkit/api.pyloadsr.   .   s     =    Fc                    t        | t        t        t        f      s&t        | t              rt        t        |       |      } 	 | j                         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)data	sort_keysexmsgs       r-   dumpsr<   7   sv     dUK;<gB DJ95% ~~ %>tDzl&Qn"$%s   A 	A<A77A<c                4    t        | j                               S )z5
    Load toml document from a file-like object.
    )r*   read)fps    r-   loadr@   I   s     r/   r9   c               <    |j                  t        | |             y)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)
    rA   N)writer<   )r8   r?   r9   s      r-   dumprD   P   s     HHU49-.r/   c                4    t        |       j                         S )z7
    Parses a string or bytes into a TOMLDocument.
    )r#   r*   r+   s    r-   r*   r*   _   s     &>!!r/   c                     t               S )z.
    Returns a new TOMLDocument instance.
    r$    r/   r-   documentrH   f   s     >r/   c                *    t        t        |             S )z/Create an integer item from a number or string.)r"   intraws    r-   integerrM   n   s    C>r/   c                *    t        t        |             S )z-Create an float item from a number or string.)r"   floatrK   s    r-   float_rP   s   s    c
r/   c                J    t        t        | t              r	| dk(        S |       S )z+Turn `true` or `false` into a boolean item.true)r"   r2   strrK   s    r-   booleanrT   x   s"    C!5v??3??r/   T)literal	multilineescapec               \    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)rL   rU   rV   rW   type_s        r-   r,   r,   }   s)    ( w	2E??3v..r/   c                x    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"   rL   values     r-   r_   r_      0    #EeY^^,<==;r/   c                x    t        |       }t        |t        j                        st	        d      t        |      S )zCreate a TOML time.z!time() only accepts time strings.)r	   r2   r^   timer`   r"   ra   s     r-   re   re      rc   r/   c                x    t        |       }t        |t        j                        st	        d      t        |      S )zCreate a TOML datetime.z)datetime() only accepts datetime strings.)r	   r2   r^   datetimer`   r"   ra   s     r-   rg   rg      s2    #EeY//0DEE;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]
    )rb   rK   s    r-   arrayri      s     :r/   c                >    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   )is_super_tables    r-   tablerl      s    " fh~>>r/   c                 >    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   rG   r/   r-   inline_tablero      s     y{FH$77r/   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   rG   r/   r-   aotrq      s     r7Nr/   c                    t        | t              rt        |       S t        | D cg c]  }t	        |       c}      S c c}w )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
    )r2   rS   r   r   key)k_ks     r-   rs   rs      s5     !S|*"c"g*++*s   >c                    t        |       }|j                         }|j                         s!|j                  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)rL   parservs      r-   rb   rb     sD     C[FA::<  !46?? KKHr/   c                4    t        |       j                         S )zkParse a key-value pair from a string.

    :Example:

    >>> key_value("foo = 1")
    (Key('foo'), 1)
    )r#   _parse_key_valuesrcs    r-   	key_valuer     s     #;''))r/   c                    t        | d      S )z"Create a whitespace from a string.T)fixedr    r   s    r-   wsr      s    c&&r/   c                     t        d      S )zCreate a newline item.
)r   rG   r/   r-   nlr   %  s    d8Or/   c                4    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BBr/   c                0    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encoders    r-   register_encoderr   /  s    " 7#Nr/   c                    t        j                  t              5  t        j                  |        ddd       y# 1 sw Y   yxY w)zUnregister a custom encoder.N)
contextlibsuppressr`   r   remover   s    r-   unregister_encoderr   D  s3    			Z	( (w'( ( (s	   9A)r,   zstr | bytesreturnr%   )F)r8   r   r9   boolr   rS   )r?   zIO[str] | IO[bytes]r   r%   )r8   r   r?   zIO[str]r9   r   r   None)r   r%   )rL   z	str | intr   r   )rL   zstr | floatr   r   )rL   z
str | boolr   r   )
rL   rS   rU   r   rV   r   rW   r   r   r   )rL   rS   r   r   )rL   rS   r   r   )rL   rS   r   r   )z[])rL   rS   r   r   )N)rk   zbool | Noner   r   )r   r   )r   r   )rt   zstr | Iterable[str]r   r   )rL   rS   r   _Item)r   rS   r   ztuple[Key, _Item])r   rS   r   r!   )r   r!   )r,   rS   r   r   )r   r'   r   r'   )r   r&   r   r   )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   r   r   r   r   r   rY   r   r   r   r!   r"   tomlkit.parserr#   tomlkit.toml_documentr%   r&   r'   r.   r<   r@   rD   r*   rH   rM   rP   rT   r,   r_   re   ri   rl   ro   rq   rs   rb   r   r   r   r   r   r   rG   r/   r-   <module>r      s?   "   $ #     ( ' 2 )    !  " #  % ! '  #   3     $  ! . %7#A%$ ;@ /"

@ /	/ / 	/
 / /0?(
8 ,$&*'

C
*(r/   