
    Ngn.                    <   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          Z e            ZdQdZdQdZ dQdZ!dQdZ"dQdZ#dRdZdSdZ$dTdZ%dUdZ& e	j'        d          Z( e	j'        d           Z) e	j'        d!          Z*dVd%Z+d& Z,d' Z-d( Z.dWd+Z/dWd,Z0dXd.Z1dXd/Z2dUd0Z3dYd3Z4dZd6Z5d[d9Z6d\d=Z7efd]d?Z8d@ Z9dA Z:d^dDZ;dE Z<d_dIZ=d_dJZ>dK Z?d`dNZ@dadPZAdS )bz Utility methods for marshmallow.    )annotationsN)Mapping)format_datetimeparsedate_to_datetime)pprint)FieldABC)FieldInstanceResolutionError)RemovedInMarshmallow4Warningexcludeincluderaisec                  &    e Zd Zd Zd Zd Zd ZdS )_Missingc                    dS )NF selfs    M/var/www/html/ai-engine/env/lib/python3.11/site-packages/marshmallow/utils.py__bool__z_Missing.__bool__   s    u    c                    | S Nr   r   s    r   __copy__z_Missing.__copy__       r   c                    | S r   r   )r   _s     r   __deepcopy__z_Missing.__deepcopy__"   r   r   c                    dS )Nz<marshmallow.missing>r   r   s    r   __repr__z_Missing.__repr__%   s    &&r   N)__name__
__module____qualname__r   r   r   r   r   r   r   r   r      sP              ' ' ' ' 'r   r   returnboolc                R    t          j        |           pt          j        |           S )z%Return True if ``obj`` is a generator)inspectisgeneratorfunctionisgeneratorobjs    r   is_generatorr+   /   s#    &s++Gw/B3/G/GGr   c                b    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)   s    r   is_iterable_but_not_stringr0   4   s2    C$$BWS'-B-B)BX|TWGXGXXr   c                L    t          |           ot          | t                     S )zGReturn True if ``obj`` is a collection type, e.g list, tuple, queryset.)r0   
isinstancer   r)   s    r   is_collectionr3   9   s"    %c**K:c73K3K/KKr   c                d    	 t          | |          S # t          $ r t          | |          cY S w xY w)zFReturn True if ``val`` is either a subclass or instance of ``class_``.)
issubclass	TypeErrorr2   )valclass_s     r   is_instance_or_subclassr9   >   sH    '#v&&& ' ' '#v&&&&&'s    //c                L    t          | t                    ot          | d          S )zjReturn True if ``obj`` has keyed tuple behavior, such as
    namedtuples or SQLAlchemy's KeyedTuples.
    _fields)r2   tupler/   r)   s    r   is_keyed_tupler=   F   s#     c5!!=gc9&=&==r   Nonec                    t          j        dt          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
   r2   collectionsOrderedDictprintjsondumps	py_pprint)r*   argskwargss      r   r   r   M   s     M[$   
 #{.// (dj.t...v../////#'''''''''r   datetimedt.datetimec                L    | j         d uo| j                             |           d uS r   )tzinfo	utcoffsetrL   s    r   is_awarerR   a   s,    t#W(A(A((K(KSW(Wr   
datestringstrc                     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   )rS   s    r   from_rfcrV   g   s    
 !,,,r   c                     t          |           S )zrReturn the RFC822-formatted representation of a datetime object.

    :param datetime datetime: The datetime.
    )r   rQ   s    r   	rfcformatrX   o   s    
 8$$$r   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                   t          | t          j                  r|                                 dz  } | dk     rdnd}dt	          t          |           d          z  }||z   }t          j        t          j        |           |          S )z6Return a tzinfo instance with a fixed offset from UTC.<   r   -+z%02d%02d)minutes)r2   dt	timedeltatotal_secondsdivmodabstimezone)rY   signhhmmnames       r   get_fixed_timezonerj      s    &",'' .%%''2-1**33#Ds6{{B///D$;D;r|F333T:::r   c                b   t                               |           }|st          d          |                                }|d         o|d                             dd          |d<   |                    d          }|dk    rt          j        j        }ni|gt          |          dk    rt          |d	d                   nd
}dt          |dd                   z  |z   }|d
         dk    r| }t          |          }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   0rO   ZN   r   r]      r^   c                8    i | ]\  }}||t          |          S r   int.0kvs      r   
<dictcomp>z%from_iso_datetime.<locals>.<dictcomp>   %    	<	<	<1am!SVVmmmr   r   )_iso8601_datetime_rematch
ValueError	groupdictljustpopra   rf   utclenru   rj   itemsrL   )valuer}   kwrO   offset_minsrY   s         r   from_iso_datetimer      s6    !&&u--E JHIII			B=)Mb.?.E.Ea.M.MB}VVHF}}		*-f++//c&+&&&qc&1+&&&4!9WF#F++	<	<

	<	<	<BBxL;r   c                ,   t                               |           }|st          d          |                                }|d         o|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 stringrl   rm   rn   c                8    i | ]\  }}||t          |          S r   rt   rv   s      r   rz   z!from_iso_time.<locals>.<dictcomp>   r{   r   r   )_iso8601_time_rer}   r~   r   r   r   ra   timer   r}   r   s      r   from_iso_timer      s    
 ""5))E FDEEE			B=)Mb.?.E.Ea.M.MB}	<	<

	<	<	<B7==R==r   c                    t                               |           }|st          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                4    i | ]\  }}|t          |          S r   rt   rv   s      r   rz   z!from_iso_date.<locals>.<dictcomp>   s$    	:	:	:1!SVV	:	:	:r   r   )_iso8601_date_rer}   r~   r   r   ra   dater   s      r   from_iso_dater      sh    ""5))E FDEEE	:	: 1 1 7 7 9 9	:	:	:B7==R==r   r   
typing.Anyc                   | du s| du rt          d          t          |           } | dk     rt          d          	 t          j                            | t          j        j                                      d           S # t          $ r}t          d          |d }~wt          $ r}t          d          |d }~ww xY w)	NTFzNot a valid POSIX timestampr   )tzrO   zTimestamp is too largez"Error converting value to datetime)
r~   floatra   rL   fromtimestamprf   r   replaceOverflowErrorOSError)r   excs     r   from_timestampr      s    }}6777%LLEqyy6777H{((2;?(CCKKSWKXXX < < <122; H H H=>>CGHs$   AB 
B=BB=(B88B=c                D    t          |           } t          | dz            S Ni  )r   r   r   s    r   from_timestamp_msr      s    %LLE%$,'''r   r   c                    t          |           s%|                     t          j        j                  } |                                 S )Nr   )rR   r   ra   rf   r   	timestampr   s    r   r   r      s9     E?? 6R[_55??r   c                &    t          |           dz  S r   )r   r   s    r   timestamp_msr      s    Ud""r   c                *    |                                  S )zsReturn the ISO8601-formatted representation of a datetime object.

    :param datetime datetime: The datetime.
    )	isoformatrQ   s    r   r   r      s    
 r   r   dt.timec                @    t           j                            |           S r   )ra   r   r   )r   s    r   to_iso_timer          7T"""r   r   dt.datec                @    t           j                            |           S r   )ra   r   r   )r   s    r   to_iso_dater      r   r   r7   str | bytesc                t    t          | t                    r|                     d          } t          |           S )Nzutf-8)r2   bytesdecoderT   )r7   s    r   ensure_text_typer      s0    #u "jj!!s88Or   dictlistlist[dict[str, typing.Any]]keyc                     f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                     g | ]
}|         S r   r   )rw   dr   s     r   
<listcomp>zpluck.<locals>.<listcomp>  s    %%%qAcF%%%r   r   )r   r   s    `r   pluckr      s     &%%%H%%%%r   	int | strc                    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.
    .)r2   ru   _get_value_for_keyssplit_get_value_for_keyr*   r   defaults      r   	get_valuer   	  sL     c3 5C3JJ"3		#@@@!#sG444r   c                    t          |          dk    rt          | |d         |          S t          t          | |d         |          |dd          |          S )Nrr   r   )r   r   r   )r*   keysr   s      r   r   r     sX    
4yyA~~!#tAw888"sDGW55tABBx
 
 	
r   c                    t          | d          st          | ||          S 	 | |         S # t          t          t          t
          f$ r t          | ||          cY S w xY w)N__getitem__)r/   getattrKeyError
IndexErrorr6   AttributeErrorr   s      r   r   r   #  sp    3&& *sC)))*3xj)^< * * *sC)))))*s   + .AAdctdict[str, typing.Any]c                    d|v ro|                     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   rr   zCannot set z in z due to existing value: N)r   
setdefaultr2   dictr~   	set_value)r   r   r   headresttargets         r   r   r   -  s     czzYYsA&&
db))&$'' 	QcQQtQQQQ   	&$&&&&&Cr   c                J    t          |           st          d| d          | S )z@Check that an object is callable, else raise a :exc:`TypeError`.Object z is not callable.)callabler6   r)   s    r   callable_or_raiser   D  s/    C== <:#:::;;;Jr   functyping.Callable	list[str]c                r    t          t          j        |           j                                                  S r   )listr&   	signature
parametersr   r   s    r   
_signaturer   K  s*    !$''27799:::r   c                    t          j        |           st          j        |           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   r2   	functoolspartialr   r   s    r   get_func_argsr   O  sj     $  7#3D#9#9  $$	)** %$)$$$dr   c                    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.
    )r2   typer5   r   r	   )cls_or_instances    r   resolve_field_instancer   ^  sZ    
 /4(( /844 	/..   /844 	/..r   dt.timedeltaru   c                <    | j         dz  | j        z   dz  | j        z   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   s    r   timedelta_to_microsecondsr   m  s%    
 J)$u}4?%BTTTr   r*   c                >    | t           vrt          d| d          | S )Nr   z1 is not a valid value for the 'unknown' parameter)_UNKNOWN_VALUESr~   r)   s    r    validate_unknown_parameter_valuer   u  s4    
/!!NcNNN
 
 	
 Jr   )r#   r$   )r#   r>   )rL   rM   r#   r$   )rS   rT   r#   rM   )rL   rM   r#   rT   )rY   rZ   r#   r[   )r   r   r#   rM   )r   rM   r#   r   )r   r   r#   rT   )r   r   r#   rT   )r7   r   r#   rT   )r   r   r   rT   )r   r   )r   r   r   rT   r   r   )r   r   r#   r   )r   r   r#   ru   )r*   r   r#   rT   )B__doc__
__future__r   rD   rL   ra   r   r&   rG   retypingrB   collections.abcr   email.utilsr   r   r   rI   marshmallow.baser   marshmallow.exceptionsr	   marshmallow.warningsr
   EXCLUDEINCLUDERAISEr   r   missingr+   r0   r3   r9   r=   rR   rV   rX   compiler|   r   r   rj   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>r     s   & & " " " " " "               				   # # # # # # > > > > > > > > & & & & & & % % % % % % ? ? ? ? ? ? = = = = = =

GU+' ' ' ' ' ' ' '" (**H H H H
Y Y Y Y
L L L L
' ' ' '> > > >( ( ( ((   - - - -% % % % "rz-   2:UVV 2:G  ; ; ; ;  2    H H H H"( ( ( (
   # # # #       # # # ## # # #   & & & & ,3 5 5 5 5 5"
 
 
* * *   .  ; ; ; ;     U U U U     r   