a
    ¡˜ëj§.  ã                   @  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r®d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   úP/mnt/bigstor/www/usecases/.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 )zþPretty-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 )zÂParse 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r°t	|ƒ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 )z¼Parse 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 )zÅExtracts 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 )zôSet 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 )zÐGiven 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 )z¯Compute the total microseconds of a timedelta

    https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Lib/datetime.py#L665-L667  # noqa: B950
    i€Q 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|   

ÿ
ÿ
		
