o
    wvXj×  ã                   @   s  d Z ddlmZmZ ddlZddlZddlZddlZddl	m
Z
mZmZmZ zddlmZ W n ey?   G dd„ deƒZY nw zddlZddlmZ d	d
iZW n eyg   ddlZi ZG dd„ deƒZY nw eejƒZdZG dd„ deƒZeZejddfdd„Zeje
fdd„ZdS )zJSON Serialization Utilities.é    )Úabsolute_importÚunicode_literalsN)ÚPY3Úbuffer_tÚtext_tÚbytes_t)ÚPromisec                   @   s   e Zd ZdZdS )ÚDjangoPromisezDummy object.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úM/var/www/html/myproject/venv/lib/python3.10/site-packages/kombu/utils/json.pyr	      s    r	   )ÚJSONDecodeErrorÚuse_decimalFc                   @   s   e Zd ZdS )Ú_DecodeErrorN)r
   r   r   r   r   r   r   r      s    r   c                       sF   e Zd ZdZejejfejfeje	j
efeejef‡ fdd„	Z‡  ZS )ÚJSONEncoderzKombu custom json encoder.c           
         s¢   t |dd ƒ}|d ur|ƒ S |||ƒr7|||ƒs$||j|j|jddddƒ}| ¡ }	|	 d¡r5|	d d… d }	|	S |||ƒr@| ¡ S |||ƒrI||ƒS tt| ƒ |¡S )NÚ__json__r   z+00:00iúÿÿÿÚZ)	ÚgetattrÚyearÚmonthÚdayÚ	isoformatÚendswithÚsuperr   Údefault)
ÚselfÚoÚdatesÚtimesÚtextualÚ
isinstanceÚdatetimer   ÚreducerÚr©Ú	__class__r   r   r   %   s   




zJSONEncoder.default)r
   r   r   r   r$   ÚdateÚtimeÚdecimalÚDecimalÚuuidÚUUIDr	   r#   r   r   Ú__classcell__r   r   r'   r   r   "   s    
úr   c                 K   s,   |st }|| fd|ptit|fi |¤Ž¤ŽS )z Serialize object to json string.Úcls)Ú_json_extra_kwargsÚ_default_encoderÚdict)ÚsÚ_dumpsr0   Údefault_kwargsÚkwargsr   r   r   ÚdumpsA   s
   ÿr8   c                 C   s„   t | tƒr|  ¡  d¡} n!t | tƒr|  d¡} n|r%t | tƒr%|  d¡} n	t | tƒr.t| ƒ} z|| ƒW S  tyA   t	 
| ¡ Y S w )zDeserialize json from string.zutf-8)r#   Ú
memoryviewÚtobytesÚdecodeÚ	bytearrayr   r   r   r   ÚstdjsonÚloads)r4   Ú_loadsÚdecode_bytesr   r   r   r>   I   s   



þr>   )r   Ú
__future__r   r   r$   r+   Újsonr=   r-   Ú
kombu.fiver   r   r   r   Údjango.utils.functionalr   r	   ÚImportErrorÚobjectÚ
simplejsonÚsimplejson.decoderr   r   r1   Ú	ExceptionÚtyper2   Ú_encoder_clsr   r8   r>   r   r   r   r   Ú<module>   s6   ÿü
