o
    DDi[                     @  s   d Z ddlmZ ddlZddlZddlZddlmZm	Z	 zddlm
Z
 W n ey3   ddlm
Z
 Y nw ddlmZ d>d	d
Zd?ddZd@ddZd?ddZdAddZdBddZdBddZdCdd ZdCd!d"ZdDd&d'ZdEd+d,ZefdFd.d/Zd0d1 Zd2d3 ZdGd6d7Zd8d9 ZdHd<d=ZdS )Iz Utility methods for marshmallow.    )annotationsN)MappingSequence)	TypeGuard)missingreturnTypeGuard[typing.Generator]c                 C  s   t | p	t | S )z%Return True if ``obj`` is a generator)inspectisgeneratorfunctionisgeneratorobj r   J/var/www/Datamplify/venv/lib/python3.10/site-packages/marshmallow/utils.pyis_generator      r   TypeGuard[typing.Iterable]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_string   s   r   TypeGuard[Sequence]c                 C  s   t | tot | ttf S )z9Return True if ``obj`` is a sequence that isn't a string.)
isinstancer   strbytesr   r   r   r   is_sequence_but_not_string   s   r   c                 C  s   t | o	t| t S )zGReturn True if ``obj`` is a collection type, e.g list, tuple, queryset.)r   r   r   r   r   r   r   is_collection#   r   r   datetimedt.datetimeboolc                 C  s   | j d uo| j | d uS )N)tzinfo	utcoffset)r   r   r   r   is_aware)   s   r"   value
typing.Anyc              
   C  s   | du s| du rt dt| } | dk rt dztjj| tjjdjd dW S  ty8 } zt d|d }~w t	yH } zt d|d }~ww )	NTFzNot a valid POSIX timestampr   )tzr    zTimestamp is too largez"Error converting value to datetime)

ValueErrorfloatdtr   fromtimestamptimezoneutcreplaceOverflowErrorOSError)r#   excr   r   r   from_timestamp/   s   

r1   c                 C  s   t | } t| d S Ni  )r(   r1   r#   r   r   r   from_timestamp_ms@   s   r4   r(   c                 C  s    t | s| jtjjd} |  S )Nr&   )r"   r-   r)   r+   r,   	timestampr3   r   r   r   r5   E   s   r5   c                 C  s   t | d S r2   )r5   r3   r   r   r   timestamp_msN   s   r6   valstr | bytesr   c                 C  s   t | tr
| d} t| S )Nzutf-8)r   r   decoder   )r7   r   r   r   ensure_text_typeR   s   

r:   dictlistlist[dict[str, typing.Any]]keyc                   s    fd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                   s   g | ]}|  qS r   r   ).0dr=   r   r   
<listcomp>`   s    zpluck.<locals>.<listcomp>r   )r;   r=   r   r@   r   pluckX   s   rB   	int | strc                 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   int_get_value_for_keyssplit_get_value_for_keyr   r=   defaultr   r   r   	get_valuef   s   rK   c                 C  s<   t |dkrt| |d |S tt| |d ||dd  |S )N   r   )lenrH   rF   )r   keysrJ   r   r   r   rF   v   s
   rF   c                 C  sH   t | dst| ||S z| | W S  ttttfy#   t| || Y S w )N__getitem__)r   getattrKeyError
IndexError	TypeErrorAttributeErrorrI   r   r   r   rH   ~   s   

rH   dctdict[str, typing.Any]c                 C  sd   d|v r,| 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}}
    rD   rL   zCannot set z in z due to existing value: N)rG   
setdefaultr   dictr'   	set_value)rU   r=   r#   headresttargetr   r   r   rY      s   
rY   c                 C  s   t | std| d| S )z@Check that an object is callable, else raise a :exc:`TypeError`.zObject z is not callable.)callablerS   r   r   r   r   callable_or_raise   s   r^   dt.timedeltarE   c                 C  s   | j d | j d | j S )zCompute the total microseconds of a timedelta.

    https://github.com/python/cpython/blob/v3.13.1/Lib/_pydatetime.py#L805-L807
    iQ i@B )dayssecondsmicrosecondsr3   r   r   r   timedelta_to_microseconds   s   rc   )r   r   )r   r   )r   r   )r   r   r   r   )r#   r$   r   r   )r#   r   r   r(   )r7   r8   r   r   )r;   r<   r=   r   )r=   rC   )rU   rV   r=   r   r#   r$   )r#   r_   r   rE   ) __doc__
__future__r   r   r)   r	   typingcollections.abcr   r   r   ImportErrortyping_extensionsmarshmallow.constantsr   r   r   r   r   r"   r1   r4   r5   r6   r:   rB   rK   rF   rH   rY   r^   rc   r   r   r   r   <module>   s:    








	



