o
    ;h                     @  s   d dl mZ d dlZd dlmZmZmZmZ ddl	m
ZmZmZ er6d dlmZmZmZmZmZ d dlmZ dZd	d
 Zdd Zdd Zdddd,ddZedZedddd-d#d$Zed%ddd&d.d)d$Zed%ddd&d/d*d$Zeddd&d+d$ZdS )0    )annotationsN)TYPE_CHECKINGoverloadTypeVarAny   )DecodeErrorconvertto_builtins)CallableOptionalTypeUnionLiteral)Buffer)encodedecodec                   C  s   t S N)__all__ r   r   ?/var/www/html/venv/lib/python3.10/site-packages/msgspec/toml.py__dir__   s   r   c                  C  sJ   zdd l } | W S  ty   Y nw zdd l}|W S  ty$   tdd w )Nr   z`msgspec.toml.decode` requires `tomli` be installed.

Please either `pip` or `conda` install it as follows:

  $ python -m pip install tomli   # using pip
  $ conda install tomli           # or using conda)tomllibImportErrortomli)r   r   r   r   r   _import_tomllib   s    r   c                  C  s(   zdd l } | W S  ty   tdd w )Nr   z`msgspec.toml.encode` requires `tomli_w` be installed.

Please either `pip` or `conda` install it as follows:

  $ python -m pip install tomli_w   # using pip
  $ conda install tomli_w           # or using conda)tomli_wr   )r   r   r   r   _import_tomli_w-   s   r   )enc_hookorderobjr   r   Optional[Callable[[Any], Any]]r   (Literal[None, 'deterministic', 'sorted']returnbytesc                C  s4   t  }t| tjtjtjfd||d}||dS )a  Serialize an object as TOML.

    Parameters
    ----------
    obj : Any
        The object to serialize.
    enc_hook : callable, optional
        A callable to call for objects that aren't supported msgspec types.
        Takes the unsupported object and should return a supported object, or
        raise a ``NotImplementedError`` if unsupported.
    order : {None, 'deterministic', 'sorted'}, optional
        The ordering to use when encoding unordered compound types.

        - ``None``: All objects are encoded in the most efficient manner
          matching their in-memory representations. The default.
        - `'deterministic'`: Unordered collections (sets, dicts) are sorted to
          ensure a consistent output between runs. Useful when
          comparison/hashing of the encoded binary output is necessary.
        - `'sorted'`: Like `'deterministic'`, but *all* object-like types
          (structs, dataclasses, ...) are also sorted by field name before
          encoding. This is slower than `'deterministic'`, but may produce more
          human-readable output.

    Returns
    -------
    data : bytes
        The serialized object.

    See Also
    --------
    decode
    T)builtin_typesstr_keysr   r   utf-8)r   _to_builtins	_datetimedatetimedatetimedumpsr   )r    r   r   tomlmsgr   r   r   r   ;   s   &r   TT)strictdec_hookbufUnion[Buffer, str]r1   boolr2   $Optional[Callable[[type, Any], Any]]c                C     d S r   r   )r3   r1   r2   r   r   r   r   o   s   r   .)typer1   r2   r8   Type[T]c                C  r7   r   r   r3   r8   r1   r2   r   r   r   r   y      c                C  r7   r   r   r:   r   r   r   r      r;   c             
   C  s   t  }t| tr| }nt| ttfr| d}n	tt| d}z||}W n |jy< } zt	t|dd}~ww |t
u rC|S t||tjtjtjfd||dS )a  Deserialize an object from TOML.

    Parameters
    ----------
    buf : bytes-like or str
        The message to decode.
    type : type, optional
        A Python type (in type annotation form) to decode the object as. If
        provided, the message will be type checked and decoded as the specified
        type. Defaults to `Any`, in which case the message will be decoded
        using the default TOML types.
    strict : bool, optional
        Whether type coercion rules should be strict. Setting to False enables
        a wider set of coercion rules from string to non-string types for all
        values. Default is True.
    dec_hook : callable, optional
        An optional callback for handling decoding custom types. Should have
        the signature ``dec_hook(type: Type, obj: Any) -> Any``, where ``type``
        is the expected message type, and ``obj`` is the decoded representation
        composed of only basic TOML types. This hook should transform ``obj``
        into type ``type``, or raise a ``NotImplementedError`` if unsupported.

    Returns
    -------
    obj : Any
        The deserialized object.

    See Also
    --------
    encode
    r'   NT)r%   r&   r1   r2   )r   
isinstancestrr$   	bytearrayr   
memoryviewloadsTOMLDecodeError_DecodeErrorr   _convertr)   r*   r+   r,   )r3   r8   r1   r2   r.   Zstr_bufr    excr   r   r   r      s,    
)r    r   r   r!   r   r"   r#   r$   )r3   r4   r1   r5   r2   r6   r#   r   )
r3   r4   r8   r9   r1   r5   r2   r6   r#   r0   )
r3   r4   r8   r   r1   r5   r2   r6   r#   r   )
__future__r   r*   r)   typingr   r   r   r    r   rB   r	   rC   r
   r(   r   r   r   r   r   typing_extensionsr   r   r   r   r   r   r0   r   r   r   r   r   <module>   s<    1	

