
    Mh                        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mZ ddl	m	Z	 ddl
mZ dZ ej        d          Z e	j        d	d
           dZdZdZdZdZdZdZddZddZdS )z%Utilities to manipulate JSON objects.    )annotationsN)
b2a_base64)datetime)Anyz%Y-%m-%dT%H:%M:%S.%fzJ^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(\.\d{1,6})?Z?([\+\-]\d{2}:?\d{2})?$z
2000-01-01z%Y-%m-%ds   PNG

s	   iVBORw0KGs   s   /9s   R0lGODdhs   R0lGODlhs   JVBERformat_dictdict[str, str]returnc                    | S )a  b64-encodes images in a displaypub format dict

    Perhaps this should be handled in json_clean itself?

    Parameters
    ----------

    format_dict : dict
        A dictionary of display data keyed by mime-type

    Returns
    -------

    format_dict : dict
        A copy of the same dictionary,
        but binary image data ('image/png', 'image/jpeg' or 'application/pdf')
        is base64-encoded.

     )r   s    Q/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbclient/jsonutil.pyencode_imagesr   2   s
    (     objr   c                   t           t          d          f}t          t          t          j        f}t          | t                    r| S t          | t          j	                  rt          |           S t          | t          j                  rFt          j        |           st          j        |           rt          |           S t!          |           S t          | |          r| S t          | t"                    r"t%          |                               d          S t          | |          s t)          | d          rt)          | d          rt+          |           } t          | t*                    rd | D             S t          | t,                    rt/          |           }t/          t          t1          t           |                               }||k    rt3          d          i }t5          |                                           D ]$\  }}t9          |          |t          |          <   %|S t          | t:                    r|                     t>                    S t3          d| z            )a  Clean an object to ensure it's safe to encode in JSON.

    Atomic, immutable objects are returned unmodified.  Sets and tuples are
    converted to lists, lists are copied and dicts are also copied.

    Note: dicts whose keys could cause collisions upon encoding (such as a dict
    with both the number 1 and the string '1' as keys) will cause a ValueError
    to be raised.

    Parameters
    ----------
    obj : any python object

    Returns
    -------
    out : object

      A version of the input which will not cause an encoding error when
      encoded as JSON.  Note that this function does not *encode* its inputs,
      it simply sanitizes it so that there will be no encoding errors later.

    Nascii__iter____next__c                ,    g | ]}t          |          S r   )
json_clean).0xs     r   
<listcomp>zjson_clean.<locals>.<listcomp>   s    +++!
1+++r   zSdict cannot be safely converted to JSON: key collision would lead to dropped valueszCan't clean for JSON: %r) strtypetuplesettypesGeneratorType
isinstanceboolnumbersIntegralintRealmathisnanisinfreprfloatbytesr   decodehasattrlistdictlenmap
ValueErroriteritemsr   r   strftimeISO8601)r   	atomic_okcontainer_to_listnkeysnkeys_collapsedoutkvs           r   r   r   I   s5   0 d4jj!I U%89
 #t 
#w'(( 3xx#w|$$ :c?? 	djoo 	99Szz#y!! 
#u /#%%g...#()) Z  %,S*%=%= 3ii#t ,++s++++#t  Cc#c3--0011O##=  
 %% 	( 	(DAq$Q--CAKK
#x   %||G$$$ /#5
6
66r   )r   r   r	   r   )r   r   r	   r   )__doc__
__future__r   r%   r!   rer   binasciir   r   typingr   r5   compileISO8601_PATstrptimePNGPNG64JPEGJPEG64GIF_64GIF89_64PDF64r   r   r   r   r   <module>rL      s
   + + # " " " " "   				                    !bjQ   ,
 + + + 		   .O7 O7 O7 O7 O7 O7r   