
    fh.                    X   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          Z  e             Z!dUdZ"dUdZ#dUdZ$dUdZ%dUdZ&dVdZdWdZ'dXdZ(dYdZ) e	j*        d           Z+ e	j*        d!          Z, e	j*        d"          Z-dZd&Z.d' Z/d( Z0d) Z1d[d,Z2d[d-Z3d\d/Z4d\d0Z5dYd1Z6d]d4Z7d^d7Z8d_d:Z9d`d>Z:e!fdad@Z;dA Z<dB Z=dbdEZ>dF Z?dcdJZ@dcdKZAdddOZBdedRZCdfdTZDdS )gz 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dS )_Missingc                    dS )NF selfs    N/var/www/FlaskApp/flask-venv/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,   4   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_stringr1   9   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.)r1   
isinstancer   r*   s    r   is_collectionr4   >   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	TypeErrorr3   )valclass_s     r   is_instance_or_subclassr:   C   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)r3   tupler0   r*   s    r   is_keyed_tupler>   K   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
   r3   collectionsOrderedDictprintjsondumps	py_pprint)r+   argskwargss      r   r   r   R   s     M[$   
 #{.// (dj.t...v../////#'''''''''r   datetimedt.datetimec                L    | j         d uo| j                             |           d uS r   )tzinfo	utcoffsetrM   s    r   is_awarerS   f   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   )rT   s    r   from_rfcrW   l   s    
 !,,,r   c                     t          |           S )ziReturn the RFC822-formatted representation of a datetime object.

    :param datetime: The datetime.
    )r   rR   s    r   	rfcformatrY   t   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float | dt.timedeltadt.timezonec                   t          | t          j                  r|                                 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)r3   dt	timedeltatotal_secondsformatdivmodabstimezone)rZ   signhhmmnames       r   get_fixed_timezonerl      s    &",'' .%%''2-1**33#D > &Vb"9"9: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   0rP   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poprb   rh   utclenrw   rl   itemsrM   )valuer   kwrP   offset_minsrZ   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 stringrn   ro   rp   c                8    i | ]\  }}||t          |          S r   rv   rx   s      r   r|   z!from_iso_time.<locals>.<dictcomp>   r}   r   r   )_iso8601_time_rer   r   r   r   r   rb   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   rv   rx   s      r   r|   z!from_iso_date.<locals>.<dictcomp>   s$    	:	:	:1!SVV	:	:	:r   r   )_iso8601_date_rer   r   r   r   rb   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rP   zTimestamp is too largez"Error converting value to datetime)
r   floatrb   rM   fromtimestamprh   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   )rS   r   rb   rh   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 )zjReturn the ISO8601-formatted representation of a datetime object.

    :param datetime: The datetime.
    )	isoformatrR   s    r   r   r      s    
 r   r   dt.timec                @    t           j                            |           S r   )rb   r   r   )r   s    r   to_iso_timer          7T"""r   r   dt.datec                @    t           j                            |           S r   )rb   r   r   )r   s    r   to_iso_dater      r   r   r8   str | bytesc                t    t          | t                    r|                     d          } t          |           S )Nzutf-8)r3   bytesdecoderU   )r8   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   )ry   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.
    .)r3   rw   _get_value_for_keyssplit_get_value_for_keyr+   r   defaults      r   	get_valuer     sM     c3 AC3JJ"3		#@@@c3000r   c                    t          |          dk    rt          | |d         |          S t          t          | |d         |          |dd          |          S )Nrt   r   )r   r   r   )r+   keysr   s      r   r   r     sX    
4yyA~~!#tAw8883Q1148W  r   c                    t          | d          st          | ||          S 	 | |         S # t          t          t          t
          f$ r t          | ||          cY S w xY w)N__getitem__)r0   getattrKeyError
IndexErrorr7   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   rt   zCannot set z in z due to existing value: N)r   
setdefaultr3   dictr   	set_value)r   r   r   headresttargets         r   r   r   0  s     czzYYsA&&
db))&$'' 	McMMtMMVMM   	&$&&&&&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.)callabler7   r*   s    r   callable_or_raiser   G  s/    C== <:#:::;;;Jr   functyping.Callable	list[str]c                r    t          t          j        |           j                                                  S r   )listr'   	signature
parametersr   r   s    r   
_signaturer   N  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   r3   	functoolspartialr   r   s    r   get_func_argsr   R  sj     $  7#3D#9#9  $$	)** %$)$$$dr   cls_or_instancetype[Field] | Fieldr   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.
    )r3   typer6   r   r	   )r   s    r   resolve_field_instancer   a  sZ    
 /4(( !/844 	/..   ox00 +**r   dt.timedeltarw   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   o  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   w  s4    
/!!NcNNN
 
 	
 Jr   )r$   r%   )r$   r?   )rM   rN   r$   r%   )rT   rU   r$   rN   )rM   rN   r$   rU   )rZ   r[   r$   r\   )r   r   r$   rN   )r   rN   r$   r   )r   r   r$   rU   )r   r   r$   rU   )r8   r   r$   rU   )r   r   r   rU   )r   r   )r   r   r   rU   r   r   )r   r   r$   r   )r   r   r$   r   )r   r   r$   rw   )r+   r   r$   rU   )E__doc__
__future__r   rE   rM   rb   r   r'   rH   retypingrC   collections.abcr   email.utilsr   r   r   rJ   marshmallow.baser   marshmallow.exceptionsr	   marshmallow.warningsr
   TYPE_CHECKINGmarshmallow.fieldsr   EXCLUDEINCLUDERAISEr   r   missingr,   r1   r4   r:   r>   rS   rW   rY   compiler~   r   r   rl   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 1 1 1 1 1   * * *   .  ; ; ; ;      U U U U     r   