
    WIgn.                    B   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d2dZd2dZ d2dZ!d2dZ"d2dZ#d3dZd4dZ$d5dZ%d6dZ& e	jN                  d      Z( e	jN                  d      Z) e	jN                  d      Z*d7dZ+d Z,d Z-d Z.d8dZ/d8d Z0	 	 	 	 d9d!Z1d9d"Z2d6d#Z3d:d$Z4d;d%Z5d<d&Z6d=d'Z7efd>d(Z8d) Z9d* Z:d?d+Z;d, Z<d@d-Z=d@d.Z>d/ Z?dAd0Z@dBd1ZAy)Cz 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y)_Missingc                     y)NF selfs    N/var/www/html/answerous/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)   /   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.   4   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_collectionr1   9   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	TypeErrorr0   )valclass_s     r   is_instance_or_subclassr7   >   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)r0   tupler-   r'   s    r   is_keyed_tupler;   F   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
   r0   collectionsOrderedDictprintjsondumps	py_pprint)r(   argskwargss      r   r   r   M   sX     MM[$
 #{../djj.t.v./#'''r   c                \    | j                   d uxr | j                   j                  |       d uS r   )tzinfo	utcoffsetdatetimes    r   is_awarerN   a   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_rfcrQ   g   s    
 !,,r   c                    t        |       S )zrReturn the RFC822-formatted representation of a datetime object.

    :param datetime datetime: The datetime.
    )r   rL   s    r   	rfcformatrS   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})?)?c                    t        | t        j                        r| j                         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)r0   dt	timedeltatotal_secondsdivmodabstimezone)offsetsignhhmmnames       r   get_fixed_timezonerc      sh    &",,'%%'2-1*3#Ds6{B//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   0rJ   ZN   r   rU      rV   r   )_iso8601_datetime_rematch
ValueError	groupdictljustpoprY   r^   utclenintrc   itemsrM   )valuerm   kwrJ   offset_minsr_   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 stringre   rf   rg   r   )	_iso8601_time_rerm   rn   ro   rp   ru   rt   rY   time)rv   rm   rw   ry   rz   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_rerm   rn   ro   ru   rt   rY   date)rv   rm   ry   rz   rw   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rJ   zTimestamp is too largez"Error converting value to datetime)
rn   floatrY   rM   fromtimestampr^   rr   replaceOverflowErrorOSError)rv   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   rv   s    r   from_timestamp_msr      s    %LE%$,''r   c                    t        |       s*| j                  t        j                  j                        } | j                         S )Nr   )rN   r   rY   r^   rr   	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 )zsReturn the ISO8601-formatted representation of a datetime object.

    :param datetime datetime: The datetime.
    )	isoformatrL   s    r   r   r      s    
 r   c                @    t         j                  j                  |       S r   )rY   r~   r   )r~   s    r   to_iso_timer          77T""r   c                @    t         j                  j                  |       S r   )rY   r   r   )r   s    r   to_iso_dater      r   r   c                Z    t        | t              r| j                  d      } t        |       S )Nzutf-8)r0   bytesdecodestr)r5   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.
    .)r0   rt   _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 )Nrk   r   )rs   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
IndexErrorr4   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   rk   zCannot set z in z due to existing value: N)r   
setdefaultr0   dictrn   	set_value)dctr   rv   headresttargets         r   r   r   -  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.)callabler4   r'   s    r   callable_or_raiser   D  s#    C='#(9:;;Jr   c                n    t        t        j                  |       j                  j	                               S r   )listr$   	signature
parametersr   funcs    r   
_signaturer   K  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   r0   	functoolspartialr   r   s    r   get_func_argsr   O  sT     $7#3#3D#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.
    )r0   typer3   r   r	   )cls_or_instances    r   resolve_field_instancer   ^  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   m  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_VALUESrn   r'   s    r    validate_unknown_parameter_valuer   u  s+    
/!cWMN
 	
 Jr   )returnbool)r   None)rM   dt.datetimer   r   )rP   r   r   r   )rM   r   r   r   )r_   zint | float | dt.timedeltar   zdt.timezone)rv   
typing.Anyr   r   )rv   r   r   r   )r~   zdt.timer   r   )r   zdt.dater   r   )r5   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   rv   r   )r   ztyping.Callabler   z	list[str])rv   zdt.timedeltar   rt   )r(   r   r   r   )B__doc__
__future__r   rA   rM   rY   r   r$   rD   retypingr?   collections.abcr   email.utilsr   r   r   rF   marshmallow.baser   marshmallow.exceptionsr	   marshmallow.warningsr
   EXCLUDEINCLUDERAISEr   r   missingr)   r.   r1   r7   r;   rN   rQ   rS   compilerl   r   r}   rc   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
Y
L
'>((-% "rzz-  2::UV 2::G ;2H"(

# ##& ,3 5"
*.;Ur   