
    6|h.                    h   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
j2                  rdd
lmZ dZdZdZeeehZ G d d      Z  e        Z!d3dZ"d3dZ#d3dZ$d3dZ%d3dZ&d4dZd5dZ'd6dZ(d7dZ) e	jT                  d      Z+ e	jT                  d      Z, e	jT                  d      Z-d8dZ.d Z/d Z0d Z1d9d Z2d9d!Z3	 	 	 	 d:d"Z4d:d#Z5d7d$Z6d;d%Z7d<d&Z8d=d'Z9d>d(Z:e!fd?d)Z;d* Z<d+ Z=d@d,Z>d- Z?dAd.Z@dAd/ZAdBd0ZBdCd1ZCdDd2ZDy)Ez Utility methods for marshmallow.    )annotationsN)Mapping)format_datetimeparsedate_to_datetime)pprint)FieldABC)FieldInstanceResolutionError)RemovedInMarshmallow4Warning)Fieldexcludeincluderaisec                  $    e Zd Zd Zd Zd Zd Zy)_Missingc                     y)NF selfs    P/var/www/html/test/engine/venv/lib/python3.12/site-packages/marshmallow/utils.py__bool__z_Missing.__bool__    s        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                     y)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      s    'r   r   c                Z    t        j                  |       xs t        j                  |       S )z%Return True if ``obj`` is a generator)inspectisgeneratorfunctionisgeneratorobjs    r   is_generatorr*   3   s#    &&s+Gw/B/B3/GGr   c                R    t        | d      xr t        | d       xs 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_stringr/   8   s)    C$BWS'-B)BX|TWGXXr   c                >    t        |       xr t        | t               S )zGReturn True if ``obj`` is a collection type, e.g list, tuple, queryset.)r/   
isinstancer   r(   s    r   is_collectionr2   =   s    %c*K:c73K/KKr   c                R    	 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	TypeErrorr1   )valclass_s     r   is_instance_or_subclassr8   B   s0    '#v&& '#v&&'s    &&c                >    t        | t              xr t        | d      S )zjReturn True if ``obj`` has keyed tuple behavior, such as
    namedtuples or SQLAlchemy's KeyedTuples.
    _fields)r1   tupler.   r(   s    r   is_keyed_tupler<   J   s     c5!=gc9&==r   c                    t        j                  dt        d       t        | t        j
                        r#t        t        j                  | g|i |       yt        | g|i | y)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
   r1   collectionsOrderedDictprintjsondumps	py_pprint)r)   argskwargss      r   r   r   Q   sX     MM[$
 #{../djj.t.v./#'''r   c                \    | j                   d uxr | j                   j                  |       d uS r   )tzinfo	utcoffsetdatetimes    r   is_awarerO   e   s-    t#W(A(A((KSW(Wr   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   )
datestrings    r   from_rfcrR   k   s    
 !,,r   c                    t        |       S )ziReturn the RFC822-formatted representation of a datetime object.

    :param datetime: The datetime.
    )r   rM   s    r   	rfcformatrT   s   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})?)?c                   t        | t        j                        r| j                         dz  } | dk  rdnd} dj                  t        t        |       d       }||z   }t        j                  t        j                  |       |      S )z6Return a tzinfo instance with a fixed offset from UTC.<   r   -+z{:02d}{:02d})minutes)r1   dt	timedeltatotal_secondsformatdivmodabstimezone)offsetsignhhmmnames       r   get_fixed_timezonere      sp    &",,'%%'2-1*3#D >  &Vb"9:D$;D;;r||F3T::r   c                8   t         j                  |       }|st        d      |j                         }|d   xr |d   j	                  dd      |d<   |j                  d      }|dk(  rt        j                  j                  }nJ|Ht        |      dkD  rt        |d	d       nd
}dt        |dd       z  |z   }|d
   dk(  r| }t        |      }|j                         D ci c]  \  }}|	|t        |       }}}||d<   t        j                  di |S c c}}w )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   0rK   ZN   r   rV      rW   r   )_iso8601_datetime_rematch
ValueError	groupdictljustpoprZ   r`   utclenintre   itemsrN   )valuero   kwrK   offset_minsra   kvs           r   from_iso_datetimer}      s    !&&u-EHII		B=)Mb.?.E.Ea.MB}VVHF}		*-f+/c&+&qc&1+&&4!9WF#F+ "
	<1am!SV)	<B	<BxL;; 
=s    
D+Dc                8   t         j                  |       }|st        d      |j                         }|d   xr |d   j	                  dd      |d<   |j                         D ci c]  \  }}|	|t        |       }}}t        j                  di |S c c}}w )zeParse a string and return a datetime.time.

    This function doesn't support time zone offsets.
    z)Not a valid ISO8601-formatted time stringrg   rh   ri   r   )	_iso8601_time_rero   rp   rq   rr   rw   rv   rZ   time)rx   ro   ry   r{   r|   s        r   from_iso_timer      s    
 ""5)EDEE		B=)Mb.?.E.Ea.MB} "
	<1am!SV)	<B	<77=R= 
=s   %
B0Bc                    t         j                  |       }|st        d      |j                         j	                         D ci c]  \  }}|t        |       }}}t        j                  di |S c c}}w )z*Parse a string and return a datetime.date.z)Not a valid ISO8601-formatted date stringr   )_iso8601_date_rero   rp   rq   rw   rv   rZ   date)rx   ro   r{   r|   ry   s        r   from_iso_dater      se    ""5)EDEE % 1 7 7 9	:1!SV)	:B	:77=R= 
;s   A2c                \   | du s| du rt        d      t        |       } | dk  rt        d      	 t        j                  j	                  | t        j
                  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rK   zTimestamp is too largez"Error converting value to datetime)
rp   floatrZ   rN   fromtimestampr`   rt   replaceOverflowErrorOSError)rx   excs     r   from_timestampr      s    }677%LEqy677H{{((2;;??(CKKSWKXX <12; H=>CGHs$   AA9 9	B+BB+B&&B+c                4    t        |       } t        | dz        S Ni  )r   r   rx   s    r   from_timestamp_msr      s    %LE%$,''r   c                    t        |       s*| j                  t        j                  j                        } | j                         S )Nr   )rO   r   rZ   r`   rt   	timestampr   s    r   r   r      s0     E?R[[__5??r   c                    t        |       dz  S r   )r   r   s    r   timestamp_msr      s    Ud""r   c                "    | j                         S )zjReturn the ISO8601-formatted representation of a datetime object.

    :param datetime: The datetime.
    )	isoformatrM   s    r   r   r      s    
 r   c                @    t         j                  j                  |       S r   )rZ   r   r   )r   s    r   to_iso_timer          77T""r   c                @    t         j                  j                  |       S r   )rZ   r   r   )r   s    r   to_iso_dater      r   r   c                Z    t        | t              r| j                  d      } t        |       S )Nzutf-8)r1   bytesdecodestr)r6   s    r   ensure_text_typer      s#    #ujj!s8Or   c                2    | D cg c]  }||   	 c}S c c}w )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]
    r   )dictlistkeyds      r   pluckr      s     %%qAcF%%%s   c                |    t        |t              s d|v rt        | |j                  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.
    .)r1   rv   _get_value_for_keyssplit_get_value_for_keyr)   r   defaults      r   	get_valuer     s:     c3C3J"3		#@@!#sG44r   c                z    t        |      dk(  rt        | |d   |      S t        t        | |d   |      |dd  |      S )Nrm   r   )ru   r   r   )r)   keysr   s      r   r   r     sG    
4yA~!#tAw88"sDGW5tABx
 	
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
IndexErrorr5   AttributeErrorr   s      r   r   r   '  sP    3&sC))*3xj)^< *sC))*s     &A	A	c                    d|v rY|j                  dd      \  }}| j                  |i       }t        |t              st	        d| d| d|       t        |||       y|| |<   y)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   rm   zCannot set z in z due to existing value: N)r   
setdefaultr1   dictrp   	set_value)dctr   rx   headresttargets         r   r   r   1  st     czYYsA&
db)&$'cU$tf,HQ  	&$&Cr   c                :    t        |       st        d| d      | S )z@Check that an object is callable, else raise a :exc:`TypeError`.Object z is not callable.)callabler5   r(   s    r   callable_or_raiser   H  s#    C='#(9:;;Jr   c                n    t        t        j                  |       j                  j	                               S r   )listr%   	signature
parametersr   funcs    r   
_signaturer   O  s'    !!$'2277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   r1   	functoolspartialr   r   s    r   get_func_argsr   S  sT     $7#3#3D#9$$	))*$))$$dr   c                    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.
    )r1   typer4   r   r	   )cls_or_instances    r   resolve_field_instancer   b  s=    
 /4(/84..  /84..r   c                Z    | 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   q  s,    
 JJ)$u}}4?%BTBTTTr   c                4    | t         vrt        d| d      | S )Nr   z1 is not a valid value for the 'unknown' parameter)_UNKNOWN_VALUESrp   r(   s    r    validate_unknown_parameter_valuer   y  s+    
/!cWMN
 	
 Jr   )returnbool)r   None)rN   dt.datetimer   r   )rQ   r   r   r   )rN   r   r   r   )ra   zint | float | dt.timedeltar   zdt.timezone)rx   
typing.Anyr   r   )rx   r   r   r   )r   zdt.timer   r   )r   zdt.dater   r   )r6   zstr | bytesr   r   )r   zlist[dict[str, typing.Any]]r   r   )r   z	int | str)r   zdict[str, typing.Any]r   r   rx   r   )r   ztyping.Callabler   z	list[str])r   ztype[Field] | Fieldr   r   )rx   zdt.timedeltar   rv   )r)   r   r   r   )E__doc__
__future__r   rB   rN   rZ   r   r%   rE   retypingr@   collections.abcr   email.utilsr   r   r   rG   marshmallow.baser   marshmallow.exceptionsr	   marshmallow.warningsr
   TYPE_CHECKINGmarshmallow.fieldsr   EXCLUDEINCLUDERAISEr   r   missingr*   r/   r2   r8   r<   rO   rR   rT   compilern   r   r   re   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      sn   & "      	   # > & % ? =	( 
GU+' '" *H
Y
L
'>((-% "rzz-  2::UV 2::G ;2H"(

# ##& ,3 5"
*.;Ur   