o
    i                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZ G dd deZ	G dd de
ZG d	d
 d
ZG dd deZG dd deZG dd deZdS )    N)MappingMutableMapping)	force_str)jsonc                       sH   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	  Z
S )
ReturnDictz
    Return object from `serializer.data` for the `Serializer` class.
    Includes a backlink to the serializer instance for renderers
    to use if they need richer field information.
    c                    "   | d| _t j|i | d S N
serializerpopr	   super__init__selfargskwargs	__class__ /var/www/snowflake_co_dev_github/snow_flake_back_end_deploy/env/lib/python3.10/site-packages/rest_framework/utils/serializer_helpers.pyr         zReturnDict.__init__c                 C   s   t | | jdS N)r	   )r   r	   r   r   r   r   copy   s   zReturnDict.copyc                 C   
   t | S N)dict__repr__r   r   r   r   r         
zReturnDict.__repr__c                 C      t t | ffS r   )r   r   r   r   r   
__reduce__      zReturnDict.__reduce__c                 C   s,   t |tstS | j| | jd}|| |S r   
isinstancer   NotImplementedr   r	   updater   othernewr   r   r   __or__    
   

zReturnDict.__or__c                 C   s,   t |tstS | j|| jd}||  |S r   r"   r&   r   r   r   __ror__'   r*   zReturnDict.__ror__)__name__
__module____qualname____doc__r   r   r   r    r)   r+   __classcell__r   r   r   r   r   	   s    r   c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )
ReturnListz
    Return object from `serializer.data` for the `SerializerList` class.
    Includes a backlink to the serializer instance for renderers
    to use if they need richer field information.
    c                    r   r   r
   r   r   r   r   r   6   r   zReturnList.__init__c                 C   r   r   )listr   r   r   r   r   r   :   r   zReturnList.__repr__c                 C   r   r   )r2   r   r   r   r   r    =   r!   zReturnList.__reduce__)r,   r-   r.   r/   r   r   r    r0   r   r   r   r   r1   /   s
    r1   c                   @   s>   e Zd ZdZdddZdd Zedd Zd	d
 Zdd Z	dS )
BoundFieldz
    A field object that also includes `.value` and `.error` properties.
    Returned when iterating over a serializer instance,
    providing an API similar to Django forms and form fields.
     c                 C   s(   || _ || _|| _|| _|| j | _d S r   )_field_prefixvalueerrors
field_namenamer   fieldr7   r8   prefixr   r   r   r   J   s
   zBoundField.__init__c                 C   s   t | j|S r   )getattrr5   )r   	attr_namer   r   r   __getattr__Q      zBoundField.__getattr__c                 C   s   | j jS r   )r5   r   r   r   r   r   _proxy_classT   s   zBoundField._proxy_classc                 C   s   d| j j| j| jf S )Nz<%s value=%s errors=%s>)r   r,   r7   r8   r   r   r   r   r   X   s   zBoundField.__repr__c                 C   s4   | j d u s
| j du rdn| j }| | j|| j| jS NFr4   )r7   r   r5   r8   r6   r   r7   r   r   r   as_form_field]   s   zBoundField.as_form_fieldNr4   )
r,   r-   r.   r/   r   r@   propertyrB   r   rE   r   r   r   r   r3   C   s    

r3   c                   @   s   e Zd Zdd ZdS )JSONBoundFieldc                 C   sh   | j }t|dds)ttt tj| j dddd}W d    n1 s$w   Y  | | j	|| j
| jS )Nis_json_stringFT   ),z: )	sort_keysindent
separators)r7   r>   
contextlibsuppress	TypeError
ValueErrorr   dumpsr   r5   r8   r6   rD   r   r   r   rE   c   s   zJSONBoundField.as_form_fieldN)r,   r-   r.   rE   r   r   r   r   rH   b   s    rH   c                       s:   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Z  ZS )NestedBoundFieldz
    This `BoundField` additionally implements __iter__ and __getitem__
    in order to support nested bound fields. This class is the type of
    `BoundField` that is used for serializer fields.
    r4   c                    s4   |d u s|dkst |tsi }t |||| d S )Nr4   )r#   r   r   r   r;   r   r   r   r   y   s   zNestedBoundField.__init__c                 c   s"    | j  D ]}| |j V  qd S r   )fieldsvaluesr9   )r   r<   r   r   r   __iter__~   s   zNestedBoundField.__iter__c                 C   s   | j | }| jr| j|nd }t| jtr| j|nd }t|dr.t|||| jd dS t	|ddr?t
|||| jd dS t|||| jd dS )NrU   .)r=   _is_jsonfieldF)rU   r7   getr#   r8   r   hasattrrT   r:   r>   rH   r3   )r   keyr<   r7   errorr   r   r   __getitem__   s   

zNestedBoundField.__getitem__c                 C   sf   i }| j  D ] \}}t|ttfr|||< q|d u s|du r!dnt|||< q| | j|| j| j	S rC   )
r7   itemsr#   r2   r   r   r   r5   r8   r6   )r   rV   r\   r7   r   r   r   rE      s   
"zNestedBoundField.as_form_fieldrF   )	r,   r-   r.   r/   r   rW   r^   rE   r0   r   r   r   r   rT   r   s    
rT   c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )BindingDictz
    This dict-like object is used to store fields on a serializer.

    This ensures that whenever fields are added to the serializer we call
    `field.bind()` so that the `field_name` and `parent` attributes
    can be set correctly.
    c                 C   s   || _ i | _d S r   )r	   rU   )r   r	   r   r   r   r      s   
zBindingDict.__init__c                 C   s   || j |< |j|| jd d S )N)r9   parent)rU   bindr	   )r   r\   r<   r   r   r   __setitem__   s   
zBindingDict.__setitem__c                 C   s
   | j | S r   rU   r   r\   r   r   r   r^      r   zBindingDict.__getitem__c                 C   s   | j |= d S r   rd   re   r   r   r   __delitem__   rA   zBindingDict.__delitem__c                 C   
   t | jS r   )iterrU   r   r   r   r   rW      r   zBindingDict.__iter__c                 C   rg   r   )lenrU   r   r   r   r   __len__   r   zBindingDict.__len__c                 C   s   t | jS r   )r   r   rU   r   r   r   r   r      rA   zBindingDict.__repr__N)r,   r-   r.   r/   r   rc   r^   rf   rW   rj   r   r   r   r   r   r`      s    r`   )rO   collections.abcr   r   django.utils.encodingr   rest_framework.utilsr   r   r   r2   r1   r3   rH   rT   r`   r   r   r   r   <module>   s    &$