o
    wvXj£  ã                   @   s’   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
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 )é    )ÚOrderedDict)ÚMutableMapping)Ú	force_str)Újsonc                       s8   e Zd ZdZ‡ f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__© úd/var/www/html/myproject/venv/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__)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__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   '   r   zReturnList.__init__c                 C   r   r   )Úlistr   r   r   r   r   r   +   r   zReturnList.__repr__c                 C   r   r   )r'   r   r   r   r   r   .   r    zReturnList.__reduce__)r!   r"   r#   r$   r   r   r   r%   r   r   r   r   r&       s
    r&   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   Úfieldr,   r-   Úprefixr   r   r   r   ;   s
   zBoundField.__init__c                 C   s   t | j|ƒS r   )Úgetattrr*   )r   Ú	attr_namer   r   r   Ú__getattr__B   ó   zBoundField.__getattr__c                 C   s   | j jS r   )r*   r   r   r   r   r   Ú_proxy_classE   s   zBoundField._proxy_classc                 C   s   d| j j| j| jf S )Nz<%s value=%s errors=%s>)r   r!   r,   r-   r   r   r   r   r   I   s   ÿzBoundField.__repr__c                 C   s4   | j d u s
| j du rdn| j }|  | j|| j| j¡S ©NFr)   )r,   r   r*   r-   r+   ©r   r,   r   r   r   Úas_form_fieldN   s   zBoundField.as_form_fieldN©r)   )
r!   r"   r#   r$   r   r5   Úpropertyr7   r   r:   r   r   r   r   r(   4   s    

r(   c                   @   s   e Zd Zdd„ ZdS )ÚJSONBoundFieldc              	   C   sV   | j }t|ddƒs ztj| j ddd�}W n ttfy   Y nw |  | j|| j| j	¡S )NÚis_json_stringFTé   )Ú	sort_keysÚindent)
r,   r3   r   ÚdumpsÚ	TypeErrorÚ
ValueErrorr   r*   r-   r+   r9   r   r   r   r:   T   s   ÿzJSONBoundField.as_form_fieldN)r!   r"   r#   r:   r   r   r   r   r=   S   s    r=   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.
    r)   c                    s*   |d u s|dkr
i }t ƒ  ||||¡ d S )Nr)   )r   r   r0   r   r   r   r   g   s   zNestedBoundField.__init__c                 c   s"   � | j  ¡ D ]}| |j V  qd S r   )ÚfieldsÚvaluesr.   )r   r1   r   r   r   Ú__iter__l   s   €ÿzNestedBoundField.__iter__c                 C   sr   | j | }| jr| j |¡nd }t| jtƒr| j |¡nd }t|dƒr.t|||| jd d�S t	|||| jd d�S )NrF   Ú.)r2   )
rF   r,   ÚgetÚ
isinstancer-   r   ÚhasattrrE   r/   r(   )r   Úkeyr1   r,   Úerrorr   r   r   Ú__getitem__p   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 r8   )
r,   ÚitemsrK   r'   r   r   r   r*   r-   r+   )r   rG   rM   r,   r   r   r   r:   x   s   
"zNestedBoundField.as_form_fieldr;   )	r!   r"   r#   r$   r   rH   rO   r:   r%   r   r   r   r   rE   `   s    rE   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   || _ tƒ | _d S r   )r	   r   rF   )r   r	   r   r   r   r   ‹   s   zBindingDict.__init__c                 C   s   || j |< |j|| jd� d S )N)r.   Úparent)rF   Úbindr	   )r   rM   r1   r   r   r   Ú__setitem__�   s   
zBindingDict.__setitem__c                 C   s
   | j | S r   ©rF   ©r   rM   r   r   r   rO   “   r   zBindingDict.__getitem__c                 C   s   | j |= d S r   rU   rV   r   r   r   Ú__delitem__–   r6   zBindingDict.__delitem__c                 C   ó
   t | jƒS r   )ÚiterrF   r   r   r   r   rH   ™   r   zBindingDict.__iter__c                 C   rX   r   )ÚlenrF   r   r   r   r   Ú__len__œ   r   zBindingDict.__len__c                 C   s   t  | j¡S r   )r   r   rF   r   r   r   r   r   Ÿ   r6   zBindingDict.__repr__N)r!   r"   r#   r$   r   rT   rO   rW   rH   r[   r   r   r   r   r   rQ   ‚   s    rQ   N)Úcollectionsr   Úcollections.abcr   Údjango.utils.encodingr   Úrest_framework.utilsr   r   r'   r&   r(   r=   rE   rQ   r   r   r   r   Ú<module>   s    "