
    Nwgb$                       d dl mZ d dlZd dlmZmZmZmZmZm	Z	  ed      Z
erd dlmZmZmZ d dlmZmZmZ d dlmZ ee
ef   Zee
eef   Zeeed   f   Zeee
   ee
   ee
   f   Zeeed	   f   Zeeee   ee   ef   Zeee
   eeed
   f   f   Zeeee
   eedf   f      Zeeee
   eedf   f      Z G d dee
         Zy)    )annotationsN)TYPE_CHECKINGAnyGenericTypeVarcastoverloadT)IterableIteratorSequence)ListTupleUnion)StrOrPromise
_Choice[T]
_ChoiceStrz_DoubleRead[T]_DoubleCollector[T]_TripleCollector[T]c                     e Zd ZdZedd       Zedd       ZddZ	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 ddZddZdd	Z	dd
Z
d dZd!dZed"d       Zed#d       Zd$dZed%d       Zed&d       Zd'dZd(dZd)dZd*dZd+dZd,dZy)-Choicesa  
    A class to encapsulate handy functionality for lists of choices
    for a Django model field.

    Each argument to ``Choices`` is a choice, represented as either a
    string, a two-tuple, or a three-tuple.

    If a single string is provided, that string is used as the
    database representation of the choice as well as the
    human-readable presentation.

    If a two-tuple is provided, the first item is used as the database
    representation and the second the human-readable presentation.

    If a triple is provided, the first item is the database
    representation, the second a valid Python identifier that can be
    used as a readable label in code, and the third the human-readable
    presentation. This is most useful when the database representation
    must sacrifice readability for some reason: to achieve a specific
    ordering, to use an integer rather than a character field, etc.

    Regardless of what representation of each choice is originally
    given, when iterated over or indexed into, a ``Choices`` object
    behaves as the standard Django choices list of two-tuples.

    If the triple form is used, the Python identifier names can be
    accessed as attributes on the ``Choices`` object, returning the
    database representation. (If the single or two-tuple forms are
    used and the database representation happens to be a valid Python
    identifier, the database representation itself is available as an
    attribute on the ``Choices`` object, returning itself.)

    Option groups can also be used with ``Choices``; in that case each
    argument is a tuple consisting of the option group name and a list
    of options, where each option in the list is either a string, a
    two-tuple, or a triple as outlined above.

    c                     y N selfchoicess     J/var/www/horilla/myenv/lib/python3.12/site-packages/model_utils/choices.py__init__zChoices.__init__L           c                     y r   r   r   s     r   r   zChoices.__init__P   r    r!   c                |    g | _         g | _        i | _        i | _        t	               | _        | j                  |       y r   )_triples_doubles_display_map_identifier_mapset
_db_values_processr   s     r   r   zChoices.__init__T   s5    -/-/FH-/"%%gr!   c                    |d   | j                   |d   <   |d   | j                  |d   <   | j                  j                  |d          |j	                  |       |j	                  |d   |d   f       y )Nr         )r'   r&   r)   addappend)r   tripletriple_collectordouble_collectors       r   _storezChoices._storeb   ss     +1)VAY''-ay&)$F1I&'F1I 67r!   Nc           
     6     j                    j                  d fd}|D ]  }t        |t        t        f      rt        |      dk(  r	 ||       0t        |      dk(  rt        |d   t        t        f      rH|d   }|d   }g }j                  ||f       g }	j                  ||	f        j                  |||	        ||d   t        t        |d         t        d|d         f       t        dt        |      z         ||||f        y )	Nc                ,    j                  |        y r   )r3   )cr2   r   r1   s    r   storezChoices._process.<locals>.storey   s    KK+-=>r!      r-   r,   r   r   z3Choices can't take a list of length %s, only 2 or 3)r6   ztuple[Any, str, StrOrPromise]returnNone)r$   r%   
isinstancelisttuplelenr/   r*   r   str
ValueError)
r   r   r1   r2   r7   choice
group_name
subchoicestcdcs
   ` ``      r   r*   zChoices._processn   s'    ##}}##}}	?  	0F &4-0v;!#&M[A%!&)dE];%+AY
%+AY
24(//R0@A24(//R0@Aj"b9vay$sF1I*>^U[\]U^@_`a$Mf+& 
 vvv./7	0r!   c                ,    t        | j                        S r   )r>   r%   r   s    r   __len__zChoices.__len__   s    4==!!r!   c                ,    t        | j                        S r   )iterr%   rG   s    r   __iter__zChoices.__iter__   s    DMM""r!   c                ,    t        | j                        S r   )reversedr%   rG   s    r   __reversed__zChoices.__reversed__   s    &&r!   c                R    	 | j                   |   S # t        $ r t        |      w xY wr   )r'   KeyErrorAttributeError)r   attnames     r   __getattr__zChoices.__getattr__   s2    	*''00 	* ))	*s    &c                     | j                   |   S r   )r&   )r   keys     r   __getitem__zChoices.__getitem__   s      %%r!   c                     y r   r   r   others     r   __add__zChoices.__add__   r    r!   c                     y r   r   rX   s     r   rZ   zChoices.__add__   r    r!   c                    t        || j                        r|j                  }nt        |      }t	        | j                  |z    S r   )r;   	__class__r$   r<   r   r   rY   
other_argss      r   rZ   zChoices.__add__   s6    eT^^,JeJ355r!   c                     y r   r   rX   s     r   __radd__zChoices.__radd__   r    r!   c                     y r   r   rX   s     r   ra   zChoices.__radd__   r    r!   c                B    t        |      }t        || j                  z    S r   )r<   r   r$   r^   s      r   ra   zChoices.__radd__   s!    %[
 dmm355r!   c                b    t        || j                        r| j                  |j                  k(  S y)NF)r;   r]   r$   rX   s     r   __eq__zChoices.__eq__   s&    eT^^,==ENN22r!   c                    dj                  | j                  j                  dj                  d | j                  D                    S )Nz{}({})z, c              3  8   K   | ]  }d t        |      z    yw)z%sN)repr).0is     r   	<genexpr>z#Choices.__repr__.<locals>.<genexpr>   s     <dT!Wn<s   )formatr]   __name__joinr$   rG   s    r   __repr__zChoices.__repr__   s6    NN##II<dmm<<
 	
r!   c                    || j                   v S r   )r)   )r   items     r   __contains__zChoices.__contains__   s    t&&r!   c                `    t        j                  | j                  |      } | j                  | S r   )copydeepcopyr$   r]   )r   memoargss      r   __deepcopy__zChoices.__deepcopy__   s'    --t<t~~t$$r!   c                   t        | j                  j                               }|j                  |      st	        d|j                  |      z        | j                  D cg c]  }|d   |v r| }} | j                  | S c c}w )Nz-The following identifiers are not present: %sr,   )r(   r'   keys
issupersetr@   symmetric_differencer$   r]   )r   new_identifiersidentifiersrA   rw   s        r   subsetzChoices.subset   s    $..3356%%o6?00AB  "&
ayO+ 
 
 t~~t$$	
s    B)r   Choices[str]r   r   )r   r   )r   z_ChoiceStr | _Choice[T])r0   ztuple[T, str, StrOrPromise]r1   r   r2   r   r9   r:   )NN)r   z!Iterable[_ChoiceStr | _Choice[T]]r1   z_TripleCollector[T] | Noner2   z_DoubleCollector[T] | Noner9   r:   )r9   int)r9   zIterator[_DoubleRead[T]])rR   r?   r9   r
   )rU   r
   r9   z#StrOrPromise | Sequence[_Triple[T]])r   r   rY   z#Choices[str] | Iterable[_ChoiceStr]r9   r   )rY   z!Choices[T] | Iterable[_Choice[T]]r9   
Choices[T])rY   z2Choices[Any] | Iterable[_ChoiceStr | _Choice[Any]]r9   Choices[Any])r   r   rY   zIterable[_ChoiceStr]r9   r   )rY   zIterable[_Choice[T]]r9   r   )rY   z+Iterable[_ChoiceStr] | Iterable[_Choice[T]]r9   r   )rY   objectr9   bool)r9   r?   )rq   r
   r9   r   )rv   zdict[int, Any] | Noner9   r   )r}   r?   r9   r   )rm   
__module____qualname____doc__r	   r   r3   r*   rH   rK   rN   rS   rV   rZ   ra   re   ro   rr   rx   r   r   r!   r   r   r   $   s    %N    
8+
8 .
8 .	
8
 

8 8<7;	)02)0 5)0 5	)0
 
)0V"#'*&    6    6

'%%r!   r   )
__future__r   rt   typingr   r   r   r   r   r	   r
   collections.abcr   r   r   r   r   r   django_stubs_extr   _Doubler?   _Triple_Group_Choice	_GroupStrr   _DoubleRead_DoubleCollector_TripleCollectorr   r   r!   r   <module>r      s.   "  G GCL<< *)- A|O$GAsL()G<,!778FGAJ
F1I56GlH\$::;IsGCL'#,	ABJ 
E,AQ8R*R$SSTKE'!*eLBW4W.X"XYZE'!*eLBW4W.X"XYZE%gaj E%r!   