o
    "7h                     @   s`   d 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
 G dd de
Z	G d	d
 d
eZdS )z#
Serialize data to/from JSON Lines
    N)DeserializationError)DjangoJSONEncoder)Deserializer)
Serializerc                       s<   e Zd ZdZdZdd Zdd Zdd Z fd	d
Z  Z	S )r   z!Convert a queryset to JSON Lines.Fc                 C   sf   d | _ | j | _| jdd  | jdd  | jdd  d| jd< | jdt | jdd d S )	Nstreamfieldsindent),z: 
separatorsclsensure_asciiF)_currentoptionscopyjson_kwargspop
setdefaultr   self r   r/var/www/epreuve.sigeris.cm/public_html/epreuve/venv/lib/python3.10/site-packages/django/core/serializers/jsonl.py_init_options   s   
zSerializer._init_optionsc                 C   s   |    d S N)r   r   r   r   r   start_serialization   s   zSerializer.start_serializationc                 C   s4   t j| || jfi | j | jd d | _d S )N
)jsondumpget_dump_objectr   r   writer   )r   objr   r   r   
end_object   s   
zSerializer.end_objectc                    s   t t|  S r   )superPythonSerializergetvaluer   	__class__r   r   r#   %   s   zSerializer.getvalue)
__name__
__module____qualname____doc__internal_use_onlyr   r   r    r#   __classcell__r   r   r$   r   r      s    
r   c                       s8   e Zd ZdZ fddZ fddZedd Z  ZS )r   z,Deserialize a stream or string of JSON data.c                    sB   t |tr	| }t |tr| }t jt|fi | d S r   )	
isinstancebytesdecodestr
splitlinesr!   __init__r   
_get_lines)r   stream_or_stringr   r$   r   r   r1   -   s
   

zDeserializer.__init__c              
   #   sV    zt  |E d H  W d S  ttfy     ty* } ztd| |d }~ww )NzError deserializing object: )r!   _handle_objectGeneratorExitr   	Exception)r   r   excr$   r   r   r4   4   s   zDeserializer._handle_objectc                 c   sJ    | D ]}|  s
qzt|V  W q ty" } zt |d }~ww d S r   )stripr   loadsr6   r   )r   liner7   r   r   r   r2   <   s   zDeserializer._get_lines)	r&   r'   r(   r)   r1   r4   staticmethodr2   r+   r   r   r$   r   r   *   s    r   )r)   r   django.core.serializers.baser   django.core.serializers.jsonr   django.core.serializers.pythonr   PythonDeserializerr   r"   r   r   r   r   <module>   s    