
    rh                         d dl Z d dlmZmZ d dlmZ d dlmZ  G d de      Z	 G d de
      Z G d	 d
      Z G d de      Z G d de      Z G d de      Zy)    N)MappingMutableMapping)	force_str)jsonc                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 x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                 P    |j                  d      | _        t        |   |i | y N
serializerpopr   super__init__selfargskwargs	__class__s      z/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/rest_framework/utils/serializer_helpers.pyr   zReturnDict.__init__   %     **\2$)&)    c                 0    t        | | j                        S N)r   )r   r   r   s    r   copyzReturnDict.copy   s    $4??;;r   c                 ,    t         j                  |       S N)dict__repr__r   s    r   r   zReturnDict.__repr__       }}T""r   c                 &    t         t        |       ffS r   )r   r   s    r   
__reduce__zReturnDict.__reduce__        tDzm$$r   c                     t        |t              st        S | j                  | | j                        }|j                  |       |S r   
isinstancer   NotImplementedr   r   updater   othernews      r   __or__zReturnDict.__or__    s9    %&!!nnTdoon>

5
r   c                     t        |t              st        S | j                  || j                        }|j                  |        |S r   r%   r)   s      r   __ror__zReturnDict.__ror__'   s9    %&!!nnUtn?

4
r   )__name__
__module____qualname____doc__r   r   r   r"   r,   r.   __classcell__r   s   @r   r   r   	   s&    *<#%r   r   c                   .     e Zd ZdZ fdZd Zd Z x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                 P    |j                  d      | _        t        |   |i | y r
   r   r   s      r   r   zReturnList.__init__6   r   r   c                 ,    t         j                  |       S r   )listr   r   s    r   r   zReturnList.__repr__:   r    r   c                 &    t         t        |       ffS r   )r9   r   s    r   r"   zReturnList.__reduce__=   r#   r   )r/   r0   r1   r2   r   r   r"   r3   r4   s   @r   r6   r6   /   s    *#%r   r6   c                   :    e Zd ZdZddZd Zed        Zd Zd Z	y)	
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                 d    || _         || _        || _        || _        || j                  z   | _        y r   )_field_prefixvalueerrors
field_namename)r   fieldr@   rA   prefixs        r   r   zBoundField.__init__J   s.    
T__,	r   c                 .    t        | j                  |      S r   )getattrr>   )r   	attr_names     r   __getattr__zBoundField.__getattr__Q   s    t{{I..r   c                 .    | j                   j                  S r   )r>   r   r   s    r   _proxy_classzBoundField._proxy_classT   s    {{$$$r   c                 j    d| j                   j                  d| j                  d| j                  dS )N<z value=z errors=>)r   r/   r@   rA   r   s    r   r   zBoundField.__repr__X   s%    NN##TZZ
 	
r   c                     | j                   | j                   du rdn| j                   }| j                  | j                  || j                  | j                        S NF )r@   r   r>   rA   r?   r   r@   s     r   as_form_fieldzBoundField.as_form_field]   sB    zz)TZZ5-@tzz~~dkk5$++t||LLr   NrQ   )
r/   r0   r1   r2   r   rI   propertyrK   r   rS    r   r   r<   r<   C   s0    -/ % %

Mr   r<   c                       e Zd Zd Zy)JSONBoundFieldc                 D   | j                   }t        |dd      sJt        j                  t        t
              5  t        j                  | j                   ddd      }d d d        | j                  | j                  || j                  | j                        S # 1 sw Y   ;xY w)Nis_json_stringFT   ),z: )	sort_keysindent
separators)r@   rG   
contextlibsuppress	TypeError
ValueErrorr   dumpsr   r>   rA   r?   rR   s     r   rS   zJSONBoundField.as_form_fieldc   s    

 u.6$$Y
; 

JJ"*	 ~~dkk5$++t||LL s   $BBN)r/   r0   r1   rS   rV   r   r   rX   rX   b   s    Mr   rX   c                   6     e Zd ZdZd fd	Zd Zd Zd Z x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.
    c                 \    ||dk(  st        |t              si }t        |   ||||       y )NrQ   )r&   r   r   r   )r   rD   r@   rA   rE   r   s        r   r   zNestedBoundField.__init__y   s/    =ERKz%/IEvv6r   c              #   l   K   | j                   j                         D ]  }| |j                       y wr   )fieldsvaluesrB   )r   rD   s     r   __iter__zNestedBoundField.__iter__~   s3     [['') 	)Eu''((	)s   24c                    | j                   |   }| j                  r| j                  j                  |      nd }t        | j                  t
              r| j                  j                  |      nd }t        |d      rt        |||| j                  dz         S t        |dd      rt        |||| j                  dz         S t        |||| j                  dz         S )Nri   .)rE   _is_jsonfieldF)ri   r@   getr&   rA   r   hasattrrf   rC   rG   rX   r<   )r   keyrD   r@   errors        r   __getitem__zNestedBoundField.__getitem__   s    C '+zz

s#t(24;;(E$45(##E5%		CPPUOU3!%dii#oNN%dii#oFFr   c                    i }| j                   j                         D ]7  \  }}t        |t        t        f      r|||<   "||du rdn
t        |      ||<   9 | j                  | j                  || j                  | j                        S rP   )
r@   itemsr&   r9   r   r   r   r>   rA   r?   )r   rj   rq   r@   s       r   rS   zNestedBoundField.as_form_field   s~    ****, 	\JC%$.#s%*]eunb9UZK[s		\
 ~~dkk64;;MMr   rT   )	r/   r0   r1   r2   r   rk   rs   rS   r3   r4   s   @r   rf   rf   r   s    7
)GNr   rf   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
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                      || _         i | _        y r   )r   ri   )r   r   s     r   r   zBindingDict.__init__   s    $r   c                 \    || j                   |<   |j                  || j                         y )N)rB   parent)ri   bindr   )r   rq   rD   s      r   __setitem__zBindingDict.__setitem__   s$     C

c$//
:r   c                      | j                   |   S r   ri   r   rq   s     r   rs   zBindingDict.__getitem__   s    {{3r   c                     | j                   |= y r   r~   r   s     r   __delitem__zBindingDict.__delitem__   s    KKr   c                 ,    t        | j                        S r   )iterri   r   s    r   rk   zBindingDict.__iter__   s    DKK  r   c                 ,    t        | j                        S r   )lenri   r   s    r   __len__zBindingDict.__len__   s    4;;r   c                 @    t         j                  | j                        S r   )r   r   ri   r   s    r   r   zBindingDict.__repr__   s    }}T[[))r   N)r/   r0   r1   r2   r   r|   rs   r   rk   r   r   rV   r   r   rw   rw      s*    ; ! *r   rw   )r`   collections.abcr   r   django.utils.encodingr   rest_framework.utilsr   r   r   r9   r6   r<   rX   rf   rw   rV   r   r   <module>r      s_     3 + %# #L% %(M M>MZ M !Nz !NH*. *r   