
    fk                     (    d dl Z  G d d          ZdS )    Nc                   n    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd ZdS )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                     g | _         g | _        i | _        i | _        t	                      | _        |                     |           d S N)_triples_doubles_display_map_identifier_mapset
_db_values_process)selfchoicess     I/var/www/equiseq/venv/lib/python3.11/site-packages/model_utils/choices.py__init__zChoices.__init__,   sC    !%%g    c                    |d         | j         |d         <   |d         | j        |d         <   | j                            |d                    |                    |           |                    |d         |d         f           d S )Nr         )r
   r	   r   addappend)r   tripletriple_collectordouble_collectors       r   _storezChoices._store:   s    *0)VAY''-ay&)$F1I&&&'''F1I 677777r   Nc                 |     j          j         fd}|D ]}t          |t          t          f          rt          |          dk    r ||           >t          |          dk    rt          |d         t          t          f          rZ|d         }|d         }g }                    ||f           g }	                    ||	f                                |||	            ||d         |d         |d         f           t          dt          |          z             ||||f           d S )Nc                 2                         |           S r   )r   )cr   r   r   s    r   <lambda>z"Choices._process.<locals>.<lambda>G   s    $++a)9;KLL r      r   r   r   z3Choices can't take a list of length %s, only 2 or 3)	r   r   
isinstancelisttuplelenr   r   
ValueError)
r   r   r   r   storechoice
group_name
subchoicestcdcs
   ` ``      r   r   zChoices._processA   s|   ##}##}LLLLLL 	0 	0F&4-00 0v;;!##E&MMMM[[A%%!&)dE];; 
A%+AY
%+AY
(//R0@AAA(//R0@AAAj"b9999vay&)VAY?@@@@$Mf++&  
 vvv.////-	0 	0r   c                 *    t          | j                  S r   )r$   r   r   s    r   __len__zChoices.__len__a   s    4=!!!r   c                 *    t          | j                  S r   )iterr   r-   s    r   __iter__zChoices.__iter__d   s    DM"""r   c                 *    t          | j                  S r   )reversedr   r-   s    r   __reversed__zChoices.__reversed__g   s    &&&r   c                 X    	 | j         |         S # t          $ r t          |          w xY wr   )r
   KeyErrorAttributeError)r   attnames     r   __getattr__zChoices.__getattr__j   s>    	*'00 	* 	* 	* )))	*s    )c                     | j         |         S r   )r	   )r   keys     r   __getitem__zChoices.__getitem__p   s     %%r   c                 |    t          || j                  r|j        }nt          |          }t	          | j        |z    S r   )r!   	__class__r   r"   r   r   others     r   __add__zChoices.__add__s   s<    eT^,, 	 NEEKKE.00r   c                 B    t          |          }t          || j        z    S r   )r"   r   r   r?   s     r   __radd__zChoices.__radd__z   s    U.00r   c                 P    t          || j                  r| j        |j        k    S dS )NF)r!   r>   r   r?   s     r   __eq__zChoices.__eq__   s*    eT^,, 	3=EN22ur   c                     d                     | j        j        d                    d | j        D                                 S )Nz{}({})z, c              3   :   K   | ]}d t          |          z  V  dS )z%sN)repr).0is     r   	<genexpr>z#Choices.__repr__.<locals>.<genexpr>   s,      <<dT!WWn<<<<<<r   )formatr>   __name__joinr   r-   s    r   __repr__zChoices.__repr__   s@    N#II<<dm<<<<<
 
 	
r   c                     || j         v S r   )r   )r   items     r   __contains__zChoices.__contains__   s    t&&r   c                 F     | j         t          j        | j        |           S r   )r>   copydeepcopyr   )r   memos     r   __deepcopy__zChoices.__deepcopy__   s    t~t}T]DAABBr   c                     t          | j                                                  }|                              s%t	          d|                              z             | j        fd| j        D              S )Nz-The following identifiers are not present: %sc                 (    g | ]}|d          v |S )r    )rI   r'   new_identifierss     r   
<listcomp>z"Choices.subset.<locals>.<listcomp>   s2      
  
  
ayO++ +++r   )r   r
   keys
issupersetr%   symmetric_differencer>   r   )r   r[   identifierss    ` r   subsetzChoices.subset   s    $.335566%%o66 	?00AAB  
 t~  
  
  
  
!% 
  
  
  	r   )NN)rM   
__module____qualname____doc__r   r   r   r.   r1   r4   r9   r<   rA   rC   rE   rO   rR   rW   ra   rZ   r   r   r   r      s	       % %N  8 8 80 0 0 0@" " "# # #' ' '* * *& & &1 1 11 1 1
  

 
 
' ' 'C C C    r   r   )rT   r   rZ   r   r   <module>re      sJ    X X X X X X X X X Xr   