o
    tf                     @   s,  d 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	 ddl
m
Z
 ddlmZmZmZ ddlmZ ddlmZ d	Zd
ZedZe
dd de
de
fddZdee deeee
f  fddZdedefddZdedefddZdedefddZdedefddZdedefddZ dS ) z%Utilities to manipulate JSON objects.    N)
b2a_base64)Iterable)datetime)AnyOptionalUnion)parse)tzlocal__next__z%Y-%m-%dT%H:%M:%S.%fzL^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(\.\d{1,6})?(Z|([\+\-]\d{2}:?\d{2}))?$1z%ddtreturnc                 C   s,   | j stjd|  tdd | jt d} | S )zREnsure a datetime object has tzinfo

    If no tzinfo is present, add tzlocal
    zPInterpreting naive datetime as local %s. Please add timezone info to timestamps.   
stacklevel)tzinfo)r   warningswarnDeprecationWarningreplacer	   )r    r   `/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/jupyter_client/jsonutil.py_ensure_tzinfo&   s   r   sc                 C   s.   | du r| S t | }|rt| }t|S | S )zparse an ISO8601 date string

    If it is None or not a valid ISO8601 timestamp,
    it will be returned unmodified.
    Otherwise, it will return a datetime object.
    N)ISO8601_PATmatch_dateutil_parser   )r   mr   r   r   r   
parse_date6   s   
r   objc                 C   sj   t | tri }|  D ]
\}}t|||< q|} | S t | ttfr*dd | D } | S t | tr3t| } | S )z(extract ISO8601 dates from unpacked JSONc                 S      g | ]}t |qS r   )extract_dates.0or   r   r   
<listcomp>N       z!extract_dates.<locals>.<listcomp>)
isinstancedictitemsr!   listtuplestrr   )r   Znew_objkvr   r   r   r!   F   s   

r!   c                 C   sj   t | trt| } |  D ]
\}}t|| |< q| S t | ttfr*dd | D } | S t | tr3|  } | S )z,squash datetime objects into ISO8601 stringsc                 S   r    r   )squash_datesr"   r   r   r   r%   [   r&   z squash_dates.<locals>.<listcomp>)r'   r(   r)   r/   r*   r+   r   	isoformat)r   r-   r.   r   r   r   r/   T   s   

r/   c                 C   s   t jddd t| S )z4DEPRECATED: Use jupyter_client.jsonutil.json_defaultz`date_default is deprecated since jupyter_client 7.0.0. Use jupyter_client.jsonutil.json_default.   r   )r   r   json_defaultr   r   r   r   date_defaulta   s
   r4   c                 C   s   t | trt| } |  ddS t | trt| dddS t | tr(t	| S t | t
jr2t| S t | t
jr<t| S td|  )z-default function for packing objects in JSON.z+00:00ZFnewlineasciiz%r is not JSON serializable)r'   r   r   r0   r   bytesr   decoder   r*   numbersIntegralintRealfloat	TypeErrorr3   r   r   r   r2   k   s   


r2   c           	      C   sT  t td f}tttjf}t| tr| S t| tj	rt
| S t| tjr5t| s-t| r1t| S t| S t| |r<| S t| trJt| dddS t| |sYt| dr]t| tr]t| } t| tridd | D S t| trt| }tttt | }||krd}t|i }|  D ]\}}t||t |< q|S t| tr| tS td|  )	NFr6   r8   __iter__c                 S   r    r   )
json_clean)r#   xr   r   r   r%      r&   zjson_clean.<locals>.<listcomp>zSdict cannot be safely converted to JSON: key collision would lead to dropped valueszCan't clean for JSON: %r) r,   typer+   settypesGeneratorTyper'   boolr;   r<   r=   r>   mathisnanisinfreprr?   r9   r   r:   hasattrnext_attr_namer*   r(   lenmap
ValueErrorr)   rB   r   strftimeISO8601)	r   Z	atomic_okZcontainer_to_listZnkeysZnkeys_collapsedmsgoutr-   r.   r   r   r   rB      sH   







rB   )!__doc__rI   r;   rerF   r   binasciir   collections.abcr   r   typingr   r   r   Zdateutil.parserr   r   Zdateutil.tzr	   rN   rS   compiler   strptimer   r,   r   r!   r/   r4   r2   rB   r   r   r   r   <module>   s2    "
