a
    ]g.                     @  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 e
jrdd
lmZ dZdZdZeeehZG dd dZ e  Z!ddddZ"ddddZ#ddddZ$ddddZ%ddddZ&ddddZddd d!d"Z'd#dd$d%d&Z(dd#d d'd(Z)e	*d)Z+e	*d*Z,e	*d+Z-d,d-d.d/d0Z.d1d2 Z/d3d4 Z0d5d6 Z1d7dd8d9d:Z2d7dd8d;d<Z3dd=d8d>d?Z4dd=d8d@dAZ5dd#d dBdCZ6dDd#dEdFdGZ7dHd#dIdJdKZ8dLd#dMdNdOZ9dPd#dQdRdSZ:e!fdTdUdVdWZ;dXdY Z<dZd[ Z=d\d#d7d]d^d_Z>d`da Z?dbdcdddedfZ@dbdcdddgdhZAdidjdkdldmZBdndod8dpdqZCd7d#drdsdtZDdS )uz Utility methods for marshmallow.    )annotationsN)Mapping)format_datetimeparsedate_to_datetime)pprint)FieldABC)FieldInstanceResolutionError)RemovedInMarshmallow4Warning)Fieldexcludeincluderaisec                   @  s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
_Missingc                 C  s   dS )NF selfr   r   _/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/marshmallow/utils.py__bool__!   s    z_Missing.__bool__c                 C  s   | S Nr   r   r   r   r   __copy__$   s    z_Missing.__copy__c                 C  s   | S r   r   )r   _r   r   r   __deepcopy__'   s    z_Missing.__deepcopy__c                 C  s   dS )Nz<marshmallow.missing>r   r   r   r   r   __repr__*   s    z_Missing.__repr__N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r       s   r   bool)returnc                 C  s   t | pt | S )z%Return True if ``obj`` is a generator)inspectisgeneratorfunctionisgeneratorobjr   r   r   is_generator4   s    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_string9   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_collection>   s    r)   c                 C  s.   zt | |W S  ty(   t| | Y S 0 dS )zFReturn True if ``val`` is either a subclass or instance of ``class_``.N)
issubclass	TypeErrorr(   )valclass_r   r   r   is_instance_or_subclassC   s    r.   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_tupleK   s    r1   Nonec                 O  sT   t jdtdd t| tjr:ttj| g|R i | n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   R   s    r   zdt.datetime)datetimer   c                 C  s   | j d uo| j | d uS r   )tzinfo	utcoffsetr?   r   r   r   is_awaref   s    rC   str)
datestringr   c                 C  s   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   )rE   r   r   r   from_rfcl   s    rF   c                 C  s   t | S )ziReturn the RFC822-formatted representation of a datetime object.

    :param datetime: The datetime.
    )r   rB   r   r   r   	rfcformatt   s    rG   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})?)?zfloat | dt.timedeltazdt.timezone)offsetr   c                 C  sX   t | tjr|  d } | dk r$dnd}dj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formatdivmodabstimezone)rH   signZhhmmnamer   r   r   get_fixed_timezone   s    rV   c                 C  s   t | }|std| }|d o4|d dd|d< |d}|dkrVtjj}nZ|durt	|dkrzt
|d	d nd
}dt
|dd  | }|d
 dkr| }t|}dd | D }||d< tjf 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   0r@   ZN   r   rI      rJ   c                 S  s"   i | ]\}}|d ur|t |qS r   int.0kvr   r   r   
<dictcomp>       z%from_iso_datetime.<locals>.<dictcomp>)_iso8601_datetime_rematch
ValueError	groupdictljustpoprM   rS   utclenr_   rV   itemsr?   )valuerg   kwr@   Zoffset_minsrH   r   r   r   from_iso_datetime   s"    


 rq   c                 C  s\   t | }|std| }|d o4|d dd|d< dd | D }tjf 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 stringrW   rX   rY   c                 S  s"   i | ]\}}|d ur|t |qS r   r^   r`   r   r   r   rd      re   z!from_iso_time.<locals>.<dictcomp>)_iso8601_time_rerg   rh   ri   rj   rn   rM   timero   rg   rp   r   r   r   from_iso_time   s    
ru   c                 C  s<   t | }|stddd |  D }tjf 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   r^   r`   r   r   r   rd      re   z!from_iso_date.<locals>.<dictcomp>)_iso8601_date_rerg   rh   ri   rn   rM   datert   r   r   r   from_iso_date   s
    
rx   z
typing.Any)ro   r   c              
   C  s   | du s| du rt dt| } | dk r0t dztjj| tjjdjd dW S  ty| } zt d|W Y d }~n6d }~0  t	y } zt d|W Y d }~n
d }~0 0 d S )	NTFzNot a valid POSIX timestampr   )tzr@   zTimestamp is too largez"Error converting value to datetime)
rh   floatrM   r?   fromtimestamprS   rl   replaceOverflowErrorOSError)ro   excr   r   r   from_timestamp   s    r   c                 C  s   t | } t| d S Ni  )r{   r   ro   r   r   r   from_timestamp_ms   s    r   r{   c                 C  s    t | s| jtjjd} |  S )Nrz   )rC   r}   rM   rS   rl   	timestampr   r   r   r   r      s    r   c                 C  s   t | d S r   )r   r   r   r   r   timestamp_ms   s    r   c                 C  s   |   S )zjReturn the ISO8601-formatted representation of a datetime object.

    :param datetime: The datetime.
    )	isoformatrB   r   r   r   r      s    r   zdt.time)rs   r   c                 C  s   t j| S r   )rM   rs   r   )rs   r   r   r   to_iso_time   s    r   zdt.date)rw   r   c                 C  s   t j| S r   )rM   rw   r   )rw   r   r   r   to_iso_date   s    r   zstr | bytes)r,   r   c                 C  s   t | tr| d} t| S )Nzutf-8)r(   bytesdecoderD   )r,   r   r   r   ensure_text_type   s    

r   zlist[dict[str, typing.Any]]Zdictlist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   )ra   dr   r   r   
<listcomp>  re   zpluck.<locals>.<listcomp>r   r   r   r   r   pluck   s    r   z	int | strr   c                 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(   r_   _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 )Nr]   r   )rm   r   r   )r"   keysr   r   r   r   r     s
    r   c                 C  sL   t | dst| ||S z
| | W S  ttttfyF   t| || Y S 0 d S )N__getitem__)r&   getattrKeyError
IndexErrorr+   AttributeErrorr   r   r   r   r   &  s    

r   zdict[str, typing.Any])dctr   ro   c                 C  sb   d|v rV| dd\}}| |i }t|tsHtd| d| d| t||| n|| |< 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   r]   zCannot set z in z due to existing value: N)r   
setdefaultr(   dictrh   	set_value)r   r   ro   headresttargetr   r   r   r   0  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_raiseG  s    r   ztyping.Callablez	list[str])funcr   c                 C  s   t t| j S r   )listr   	signature
parametersr   r   r   r   r   
_signatureN  s    r   c                 C  s:   t | st | rt| S t| tjr2t| 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_argsR  s
    
r   ztype[Field] | Fieldr
   )cls_or_instancer   c                 C  s0   t | trt| tst|  S t | ts,t| S )zrReturn a field instance from a field class or instance.

    :param cls_or_instance: Field class or instance.
    )r(   typer*   r   r   )r   r   r   r   resolve_field_instancea  s    


r   zdt.timedeltar_   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_microsecondso  s    r   )r"   r   c                 C  s   | t vrtd| d| S )Nr   z1 is not a valid value for the 'unknown' parameter)_UNKNOWN_VALUESrh   r!   r   r   r    validate_unknown_parameter_valuew  s
    
r   )E__doc__
__future__r   r7   r?   rM   r   r   r:   retypingr5   collections.abcr   email.utilsr   r   r   r<   Zmarshmallow.baser   Zmarshmallow.exceptionsr   Zmarshmallow.warningsr	   TYPE_CHECKINGZmarshmallow.fieldsr
   ZEXCLUDEZINCLUDEZRAISEr   r   missingr#   r'   r)   r.   r1   rC   rF   rG   compilerf   rv   rr   rV   rq   ru   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s|   



		
