a
    ze>                  
   @   s2  d dl Z zd dlmZ W n ey.   dZY n0 zd dlmZ W n eyV   dZY n0 zd dlmZ W n ey~   dZY n0 e 	dZ
e 	dZe 	dZdd	d
dddddZedD ]Zeeede qedZdd ZepeZdd ZepeZG dd deZeeeeeeeee ej!f
ddZ"dS )    N)encode_basestring_ascii)encode_basestring)make_encoderz[\x00-\x1f\\"\b\f\n\r\t]z([\\"]|[^\ -~])s   [-]z\\z\"z\bz\fz\nz\rz\t)\"
	    	\u{0:04x}infc                 C   s   dd }dt ||  d S )Nc                 S   s   t | d S )Nr   )
ESCAPE_DCTgroup)match r   "/usr/lib/python3.9/json/encoder.pyreplace(   s    z%py_encode_basestring.<locals>.replacer   )ESCAPEsubsr   r   r   r   py_encode_basestring$   s    r   c                 C   s   dd }dt ||  d S )Nc                 S   s~   |  d}z
t| W S  tyx   t|}|dk r@d| Y S |d8 }d|d? d@ B }d|d@ B }d|| Y S Y n0 d S )	Nr   i   r   i   
   i  i   z\u{0:04x}\u{1:04x})r   r   KeyErrorordformat)r   r   ns1s2r   r   r   r   4   s    

z+py_encode_basestring_ascii.<locals>.replacer   )ESCAPE_ASCIIr   r   r   r   r   py_encode_basestring_ascii0   s    r"   c                	   @   sJ   e Zd ZdZdZdddddddddddZd	d
 Zdd ZdddZdS )JSONEncoderz, z: FTN)skipkeysensure_asciicheck_circular	allow_nan	sort_keysindent
separatorsdefaultc          	      C   sZ   || _ || _|| _|| _|| _|| _|d ur:|\| _| _n|d urHd| _|d urV|| _d S )N,)	r$   r%   r&   r'   r(   r)   item_separatorkey_separatorr+   )	selfr$   r%   r&   r'   r(   r)   r*   r+   r   r   r   __init__h   s    +zJSONEncoder.__init__c                 C   s   t d|jj dd S )NzObject of type z is not JSON serializable)	TypeError	__class____name__)r/   or   r   r   r+      s    zJSONEncoder.defaultc                 C   sN   t |tr | jrt|S t|S | j|dd}t |ttfsDt|}d|S )NT)	_one_shot )	
isinstancestrr%   r   r   
iterencodelisttuplejoin)r/   r4   chunksr   r   r   encode   s    	
zJSONEncoder.encodec                 C   s   | j ri }nd }| jrt}nt}| jtjtt fdd}|rvtd urv| j	d u rvt|| j
|| j	| j| j| j| j| j	}n&t|| j
|| j	|| j| j| j| j|
}||dS )Nc                 S   sJ   | | krd}n$| |krd}n| |kr*d}n|| S |sFt dt|  |S )NZNaNZInfinityz	-Infinityz2Out of range float values are not JSON compliant: )
ValueErrorrepr)r4   r'   Z_reprZ_infZ_neginftextr   r   r   floatstr   s    z(JSONEncoder.iterencode.<locals>.floatstrr   )r&   r%   r   r   r'   float__repr__INFINITYc_make_encoderr)   r+   r.   r-   r(   r$   _make_iterencode)r/   r4   r5   markers_encoderrB   _iterencoder   r   r   r9      s.    


zJSONEncoder.iterencode)F)	r3   
__module____qualname__r-   r.   r0   r+   r>   r9   r   r   r   r   r#   I   s   8r#   c                    s   d ursd  	fdd	 	
fdd 	fddS )N c           	      3   s  | sdV  d S d ur6| }|v r. d| |< d}d urh|d7 }d|  }| }||7 }nd }}d}| D ]}|rd}n|}|r|| V  qx|d u r|d V  qx|du r|d	 V  qx|du r|d
 V  qx|r|| V  qx|
r|| V  qx|V  |fr8||}n"|	rP||}n
||}|E d H  qx|d ur|d8 }d|  V  dV  d ur|= d S )Nz[]Circular reference detected[   r	   TFnulltruefalse]r   )	Zlst_current_indent_levelmarkeridbufnewline_indent	separatorfirstvaluer=   )r?   rI   	_floatstr_indent_intstr_item_separatorrJ   _iterencode_dict_iterencode_listdictrC   idintr7   r:   rH   r8   r;   r   r   ra     s\    





z*_make_iterencode.<locals>._iterencode_listc           
      3   s:  | sdV  d S d ur6| }|v r. d| |< dV  d urh|d7 }d|  }| }|V  nd }}d}rt |  }n|  }|D ]j\}}|rnn|r|}nZ|du rd}nL|du rd	}n>|d u rd
}n0|r|}n
rqntd|jj |r"d}n|V  |V  	V  |rP|V  q|d u rbd
V  q|du rtdV  q|du rd	V  q|r|V  q|r|V  q|fr҈||}	n"|r||}	n
||}	|	E d H  q|d ur |d8 }d|  V  dV  d ur6|= d S )Nz{}rN   {rP   r	   TrR   FrS   rQ   z0keys must be str, int, float, bool or None, not })sorteditemsr1   r2   r3   )
ZdctrU   rV   rX   r-   rZ   rh   keyr[   r=   )r?   rI   r\   r]   r^   r_   rJ   r`   ra   _key_separator	_skipkeys
_sort_keysrb   rC   rc   rd   r7   r:   rH   r8   r;   r   r   r`   M  s    











z*_make_iterencode.<locals>._iterencode_dictc                 3   s   | r| V  n| d u r&dV  n| du r6dV  n| du rFdV  n| r\| V  n| 	rr| V  n| fr| |E d H  nj| r| |E d H  nNd urֈ
| }|v rΈ d| |< | } | |E d H  d ur|= d S )NrQ   TrR   FrS   rN   r   )r4   rU   rV   )r?   _defaultrI   r\   r^   rJ   r`   ra   rb   rC   rc   rd   r7   r:   rH   r8   r;   r   r   rJ     s2    



z%_make_iterencode.<locals>._iterencoder   )rH   rm   rI   r]   r\   rj   r_   rl   rk   r5   r?   rb   rC   rc   rd   r7   r:   r8   r;   r^   r   )r?   rm   rI   r\   r]   r^   r_   rJ   r`   ra   rj   rk   rl   rb   rC   rc   rd   r7   r:   rH   r8   r;   r   rG     s    .84P,rG   )#reZ_jsonr   Zc_encode_basestring_asciiImportErrorr   Zc_encode_basestringr   rF   compiler   r!   ZHAS_UTF8r   rangei
setdefaultchrr   rC   rE   r   r"   objectr#   r?   rb   rc   rd   r7   r:   r8   r;   rD   rG   r   r   r   r   <module>   sX   





		 >