o
    $ifn.                     @  s  d Z ddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZ ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ d
ZdZdZeeehZG dd dZe ZdqddZdqddZ dqddZ!dqddZ"dqddZ#drddZdsd d!Z$dtd$d%Z%dud&d'Z&e	'd(Z(e	'd)Z)e	'd*Z*dvd.d/Z+d0d1 Z,d2d3 Z-d4d5 Z.dwd8d9Z/dwd:d;Z0dxd=d>Z1dxd?d@Z2dudAdBZ3dydEdFZ4dzdIdJZ5d{dMdNZ6d|dRdSZ7efd}dUdVZ8dWdX Z9dYdZ Z:d~d]d^Z;d_d` Z<ddddeZ=ddfdgZ>dhdi Z?ddldmZ@ddodpZAdS )z Utility methods for marshmallow.    )annotationsN)Mapping)format_datetimeparsedate_to_datetime)pprint)FieldABC)FieldInstanceResolutionError)RemovedInMarshmallow4Warningexcludeincluderaisec                   @  s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_Missingc                 C     dS )NF selfr   r   J/var/www/html/corbot_env/lib/python3.10/site-packages/marshmallow/utils.py__bool__      z_Missing.__bool__c                 C     | S Nr   r   r   r   r   __copy__   r   z_Missing.__copy__c                 C  r   r   r   )r   _r   r   r   __deepcopy__"   r   z_Missing.__deepcopy__c                 C  r   )Nz<marshmallow.missing>r   r   r   r   r   __repr__%   r   z_Missing.__repr__N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r      s
    r   returnboolc                 C  s   t | p	t | S )z%Return True if ``obj`` is a generator)inspectisgeneratorfunctionisgeneratorobjr   r   r   is_generator/      r%   c                 C  s   t | drt | d pt| S )zAReturn True if ``obj`` is an iterable object that isn't a string.__iter__strip)hasattrr%   r#   r   r   r   is_iterable_but_not_string4   s   r*   c                 C  s   t | o	t| t S )zGReturn True if ``obj`` is a collection type, e.g list, tuple, queryset.)r*   
isinstancer   r#   r   r   r   is_collection9   r&   r,   c                 C  s*   zt | |W S  ty   t| | Y S w )zFReturn True if ``val`` is either a subclass or instance of ``class_``.)
issubclass	TypeErrorr+   )valclass_r   r   r   is_instance_or_subclass>   s
   r1   c                 C  s   t | to	t| dS )zjReturn True if ``obj`` has keyed tuple behavior, such as
    namedtuples or SQLAlchemy's KeyedTuples.
    _fields)r+   tupler)   r#   r   r   r   is_keyed_tupleF   s   r4   Nonec                 O  sV   t jdtdd t| tjrttj| g|R i | dS t	| g|R i | dS )zPretty-printing function that can pretty-print OrderedDicts
    like regular dictionaries. Useful for printing the output of
    :meth:`marshmallow.Schema.dump`.

    .. deprecated:: 3.7.0
        marshmallow.pprint will be removed in marshmallow 4.
    zQmarshmallow's pprint function is deprecated and will be removed in marshmallow 4.   )
stacklevelN)
warningswarnr	   r+   collectionsOrderedDictprintjsondumps	py_pprint)r$   argskwargsr   r   r   r   M   s    r   datetimedt.datetimec                 C  s   | j d uo| j | d uS r   )tzinfo	utcoffsetrB   r   r   r   is_awarea   s   rG   
datestringstrc                 C     t | S )zParse a RFC822-formatted datetime string and return a datetime object.

    https://stackoverflow.com/questions/885015/how-to-parse-a-rfc-2822-date-time-into-a-python-datetime  # noqa: B950
    )r   )rH   r   r   r   from_rfcg      rK   c                 C  rJ   )zrReturn the RFC822-formatted representation of a datetime object.

    :param datetime datetime: The datetime.
    )r   rF   r   r   r   	rfcformato   rL   rM   z(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?(?P<tzinfo>Z|[+-]\d{2}(?::?\d{2})?)?$z4(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$zd(?P<hour>\d{1,2}):(?P<minute>\d{1,2})(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?offsetint | float | dt.timedeltadt.timezonec                 C  sV   t | tjr|  d } | dk rdnd}dtt| d }|| }ttj| d|S )z6Return a tzinfo instance with a fixed offset from UTC.<   r   -+z%02d%02d)minutes)r+   dt	timedeltatotal_secondsdivmodabstimezone)rN   signhhmmnamer   r   r   get_fixed_timezone   s   r^   c                 C  s   t | }|std| }|d o|d dd|d< |d}|dkr+tjj}n-|durXt	|dkr=t
|d	d nd
}dt
|dd  | }|d
 dkrT| }t|}dd | D }||d< tjdi |S )zParse a string and return a datetime.datetime.

    This function supports time zone offsets. When the input contains one,
    the output uses a timezone with a fixed offset from UTC.
    z-Not a valid ISO8601-formatted datetime stringmicrosecond   0rD   ZN   r   rQ      rR   c                 S  "   i | ]\}}|d ur|t |qS r   int.0kvr   r   r   
<dictcomp>      " z%from_iso_datetime.<locals>.<dictcomp>r   )_iso8601_datetime_rematch
ValueError	groupdictljustpoprU   rZ   utclenrh   r^   itemsrB   )valuerp   kwrD   offset_minsrN   r   r   r   from_iso_datetime   s"   


 r{   c                 C  s\   t | }|std| }|d o|d dd|d< dd | D }tjdi |S )	zeParse a string and return a datetime.time.

    This function doesn't support time zone offsets.
    z)Not a valid ISO8601-formatted time stringr_   r`   ra   c                 S  rf   r   rg   ri   r   r   r   rm      rn   z!from_iso_time.<locals>.<dictcomp>Nr   )_iso8601_time_rerp   rq   rr   rs   rw   rU   timerx   rp   ry   r   r   r   from_iso_time   s   
r   c                 C  s<   t | }|stddd |  D }tjdi |S )z*Parse a string and return a datetime.date.z)Not a valid ISO8601-formatted date stringc                 S  s   i | ]	\}}|t |qS r   rg   ri   r   r   r   rm      s    z!from_iso_date.<locals>.<dictcomp>Nr   )_iso8601_date_rerp   rq   rr   rw   rU   dater~   r   r   r   from_iso_date   s
   
r   rx   
typing.Anyc              
   C  s   | du s| du rt dt| } | dk rt dztjj| tjjdjd dW S  ty8 } zt d|d }~w t	yH } zt d|d }~ww )	NTFzNot a valid POSIX timestampr   )tzrD   zTimestamp is too largez"Error converting value to datetime)
rq   floatrU   rB   fromtimestamprZ   ru   replaceOverflowErrorOSError)rx   excr   r   r   from_timestamp   s   

r   c                 C  s   t | } t| d S Ni  )r   r   rx   r   r   r   from_timestamp_ms   s   r   r   c                 C  s    t | s| jtjjd} |  S )Nr   )rG   r   rU   rZ   ru   	timestampr   r   r   r   r      s   r   c                 C  s   t | d S r   )r   r   r   r   r   timestamp_ms      r   c                 C  s   |   S )zsReturn the ISO8601-formatted representation of a datetime object.

    :param datetime datetime: The datetime.
    )	isoformatrF   r   r   r   r      rL   r   r}   dt.timec                 C     t j| S r   )rU   r}   r   )r}   r   r   r   to_iso_time   r   r   r   dt.datec                 C  r   r   )rU   r   r   )r   r   r   r   to_iso_date   r   r   r/   str | bytesc                 C  s   t | tr
| d} t| S )Nzutf-8)r+   bytesdecoderI   )r/   r   r   r   ensure_text_type   s   

r   dictlistlist[dict[str, typing.Any]]keyc                   s    fdd| D S )zExtracts a list of dictionary values from a list of dictionaries.
    ::

        >>> dlist = [{'id': 1, 'name': 'foo'}, {'id': 2, 'name': 'bar'}]
        >>> pluck(dlist, 'id')
        [1, 2]
    c                   s   g | ]}|  qS r   r   )rj   dr   r   r   
<listcomp>  s    zpluck.<locals>.<listcomp>r   )r   r   r   r   r   pluck   s   r   	int | strc                 C  s0   t |tsd|v rt| |d|S t| ||S )a  Helper for pulling a keyed value off various types of objects. Fields use
    this method by default to access attributes of the source object. For object `x`
    and attribute `i`, this method first tries to access `x[i]`, and then falls back to
    `x.i` if an exception is raised.

    .. warning::
        If an object `x` does not raise an exception when `x[i]` does not exist,
        `get_value` will never check the value `x.i`. Consider overriding
        `marshmallow.fields.Field.get_value` in this case.
    .)r+   rh   _get_value_for_keyssplit_get_value_for_keyr$   r   defaultr   r   r   	get_value	  s   r   c                 C  s<   t |dkrt| |d |S tt| |d ||dd  |S )Nre   r   )rv   r   r   )r$   keysr   r   r   r   r     s
   r   c                 C  sH   t | dst| ||S z| | W S  ttttfy#   t| || Y S w )N__getitem__)r)   getattrKeyError
IndexErrorr.   AttributeErrorr   r   r   r   r   #  s   

r   dctdict[str, typing.Any]c                 C  sd   d|v r,| dd\}}| |i }t|ts$td| d| d| t||| dS || |< dS )zSet a value in a dict. If `key` contains a '.', it is assumed
    be a path (i.e. dot-delimited string) to the value's location.

    ::

        >>> d = {}
        >>> set_value(d, 'foo.bar', 42)
        >>> d
        {'foo': {'bar': 42}}
    r   re   zCannot set z in z due to existing value: N)r   
setdefaultr+   dictrq   	set_value)r   r   rx   headresttargetr   r   r   r   -  s   
r   c                 C  s   t | std| d| S )z@Check that an object is callable, else raise a :exc:`TypeError`.Object z is not callable.)callabler.   r#   r   r   r   callable_or_raiseD  s   r   functyping.Callable	list[str]c                 C  s   t t| j S r   )listr    	signature
parametersr   r   r   r   r   
_signatureK  s   r   c                 C  s:   t | s
t | rt| S t| tjrt| jS t| S )zGiven a callable, return a list of argument names. Handles
    `functools.partial` objects and class-based callables.

    .. versionchanged:: 3.0.0a1
        Do not return bound arguments, eg. ``self``.
    )r    
isfunctionismethodr   r+   	functoolspartialr   r   r   r   r   get_func_argsO  s
   
r   c                 C  s0   t | trt| tst|  S t | tst| S )zReturn a Schema instance from a Schema class or instance.

    :param type|Schema cls_or_instance: Marshmallow Schema class or instance.
    )r+   typer-   r   r   )cls_or_instancer   r   r   resolve_field_instance^  s   


r   dt.timedeltarh   c                 C  s   | j d | j d | j S )zCompute the total microseconds of a timedelta

    https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/datetime.py#L665-L667  # noqa: B950
    iQ i@B )dayssecondsmicrosecondsr   r   r   r   timedelta_to_microsecondsm  s   r   r$   c                 C  s   | t vrtd| d| S )Nr   z1 is not a valid value for the 'unknown' parameter)_UNKNOWN_VALUESrq   r#   r   r   r    validate_unknown_parameter_valueu  s
   
r   )r   r   )r   r5   )rB   rC   r   r   )rH   rI   r   rC   )rB   rC   r   rI   )rN   rO   r   rP   )rx   r   r   rC   )rx   rC   r   r   )r}   r   r   rI   )r   r   r   rI   )r/   r   r   rI   )r   r   r   rI   )r   r   )r   r   r   rI   rx   r   )r   r   r   r   )rx   r   r   rh   )r$   r   r   rI   )B__doc__
__future__r   r:   rB   rU   r   r    r=   retypingr8   collections.abcr   email.utilsr   r   r   r?   marshmallow.baser   marshmallow.exceptionsr   marshmallow.warningsr	   EXCLUDEINCLUDERAISEr   r   missingr%   r*   r,   r1   r4   rG   rK   rM   compilero   r   r|   r^   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sz    














	


	




	




