
    +hF2              
          d Z ddlZddlZddlZej        ee	e
ef         Zej        ej        e         ej        eef         ej        eef         ef         Zej        eef         Z G d d          Zdej        dej        eej        ej        ej        eef                           f         fdZdej        defdZdej        defd	Zddej        dedefdZdej        dedefdZdS )z

uritemplate.variable
====================

This module contains the URIVariable class which powers the URITemplate class.

What treasures await you:

- URIVariable class

You see a hammer in front of you.
What do you do?
>

    Nc                      e Zd ZdZdZdZdefdZdefdZdefdZ	dd
Z
ddZdedededej        e         dej        e         f
dZdedededej        e         dej        e         f
dZdedededej        e         dej        e         f
dZdedededej        e         dej        e         f
dZ	 ddej        e         dej        eef         fdZd	S )URIVariablea  This object validates everything inside the URITemplate object.

    It validates template expansions and will truncate length as decided by
    the template.

    Please note that just like the :class:`URITemplate <URITemplate>`, this
    object's ``__str__`` and ``__repr__`` methods do not return the same
    information. Calling ``str(var)`` will return the original variable.

    This object does the majority of the heavy lifting. The ``URITemplate``
    object finds the variables in the URI and then creates ``URIVariable``
    objects.  Expansions of the URI are handled by each ``URIVariable``
    object. ``URIVariable.expand()`` returns a dictionary of the original
    variable and the expanded value. Check that method's documentation for
    more information.

    )
+#./;?&|!@z:/?#[]@!$&'()*+,;=varc                     || _         d| _        d| _        g | _        g | _        i | _        |                                  |                                  d S )N )originaloperatorsafe	variablesvariable_namesdefaultsparse
post_parse)selfr   s     X/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/uritemplate/variable.py__init__zURIVariable.__init__6   sW     	  	 ,.DF

    returnc                     d| z  S )NzURIVariable(%s) r   s    r   __repr__zURIVariable.__repr__I   s     4''r   c                     | j         S N)r   r!   s    r   __str__zURIVariable.__str__L   s
    }r   Nc                    | j         }| j         d         t          j        v r!| j         d         | _        | j         dd         }| j        t          j        dd         v rt          j        | _        |                    d          }|D ]}d}|}d|v r&t          |                    dd                    \  }}d}|                    d          rd	}|dd
         }d}d|v r5t          |                    dd                    \  }}t          |          }|r
|| j
        |<   | j                            |||df           d | j        D             | _        dS )zParse the variable.

        This finds the:
            - operator,
            - set of safe characters,
            - variables, and
            - defaults.

        r      N   ,=F*T:)explodeprefixc                     g | ]\  }}|S r    r    ).0varname_s      r   
<listcomp>z%URIVariable.parse.<locals>.<listcomp>z   s    JJJ<GQwJJJr   )r   r   	operatorsr   reservedr   splittupleendswithintr   r   appendr   )	r   var_list_strvar_listr   default_valnamer.   r/   
prefix_strs	            r   r   zURIVariable.parseO   s~    }={444 M!,DM=,L=K1"1"555#,DI%%c** 	 	CKDczz$)#))C*;*;$<$<!kG}}S!! !CRCy&*Fd{{#(C););#<#< jZ 2&1d#N!!7f==>    KJ4>JJJr   c                    d| _         | j        x| _        | _        | j        dk    rd| _        | j        dv rd| _        | j        dk    rd| _        | j        dk    rd| _        d| _        | j        dv rt          j        | _         d	S d	S )
zSet ``start``, ``join_str`` and ``safe`` attributes.

        After parsing the variable, we need to set up these attributes and it
        only makes sense to do it in a more easily testable way.
        r   r   )r   r   r   r)   r   r
   r   )r   r   N)r   r   startjoin_strr   r6   r!   s    r   r   zURIVariable.post_parse|   s     	%)]2
T]=CDJ=N**DM=CDJ=CDJDM=J&&#,DIII '&r   r?   valuer.   r/   c                 d   |dS t          |          \  }}| j        t          |          r|s|sdS t          j        t          j        t                   |          }|r'| j                            fd|D                       S d                    fd|D                       } d| S t          |          s|r|sdS t          j        t          j
        t          t          f         |          }|p t          |                                          }|r&| j                            fd|D                       S d                    fd|D                       } d| S |rBt          j        t          j        |          }|r
|d|         n|} dt          |           S dz   S )z/Expansion method for the '?' and '&' operators.Nc              3   B   K   | ]} d t          |           V  dS r*   Nquoter1   vr?   r   s     r   	<genexpr>z/URIVariable._query_expansion.<locals>.<genexpr>   sJ       * *34t..eAtnn..* * * * * *r   r)   c              3   8   K   | ]}t          |          V  d S r$   rH   r1   rK   r   s     r   rL   z/URIVariable._query_expansion.<locals>.<genexpr>   +       ? ?Aq$ ? ? ? ? ? ?r   r*   c              3   d   K   | ]*\  }}t          |           d t          |           V  +dS rG   rH   r1   krK   r   s      r   rL   z/URIVariable._query_expansion.<locals>.<genexpr>   sV       * *=AQuQ~~88a88* * * * * *r   c              3   d   K   | ]*\  }}t          |           d t          |           V  +dS )r)   NrH   rQ   s      r   rL   z/URIVariable._query_expansion.<locals>.<genexpr>   sV       ! !=AQuQ~~88a88! ! ! ! ! !r   )is_list_of_tuplesr   	list_testtcastSequenceScalarVariableValuerC   join	dict_testMappingstrsorteditemsTextrI   )r   r?   rD   r.   r/   tuplesr_   r   s    `     @r   _query_expansionzURIVariable._query_expansion   s<    =4)%00yU 
	)F 
	) tF1:&9:EBBE )})) * * * * *8=* * *     ? ? ? ? ? ? ???(((((U 	)v 	) tF19S*=%=>FFE2VEKKMM22E )})) * * * *EJ* * *     ! ! ! !EJ! ! !   ((((( 	2F165))E&,7E'6'NN%E11U5$//111czr   c                 4  
 | j         }| j        |;t          |t          t          t
          t          f          st          |          dk    rdS t          |          \  }}t          |          rW|sU|sd}t          j        t          j        t                   |          }fd|D             }|r|                    |          ndS t          |          s|rt          j        t          j        t          t          f         |          }|p t#          |                                          }d
|sd
d}|                    
fd|D                       }	|	r|	ndS t          j        t          j        |          }|r
|d|         n|}t)          |          S )zSLabel and path expansion method.

        Expands for operators: '/', '.'

        Nr   r)   c                 4    g | ]}|t          |          S r$   rH   rN   s     r   r4   z5URIVariable._label_path_expansion.<locals>.<listcomp>   s"    HHHA!-q$---r   %s=%s%s,%sc              3   h   K   | ],\  }}|t          |          t          |          fz  V  -d S r$   rH   )r1   rR   rK   
format_strr   s      r   rL   z4URIVariable._label_path_expansion.<locals>.<genexpr>   sO       % %Aq= eAtnneAtnn== ===% %r   )rC   r   
isinstancer]   r:   floatcomplexlenrT   rU   rV   rW   rX   rY   rZ   r[   r\   r^   r_   r`   rI   )r   r?   rD   r.   r/   rC   ra   r_   	fragmentsexpandedrh   r   s             @@r   _label_path_expansionz!URIVariable._label_path_expansion   s    =y=53UG"<== E

a4)%00U 	CF 	C F1:&9:EBBEHHHHHHHI/8B8==+++dBU 	2v 	2F19S*=%=>FFE2VEKKMM22E J $
}} % % % % %!% % %  H
  (188T1qvu%%"(3gvgeUD!!!r   c                 n  	 | j         }| j        	|dS | j        dk    rd}t          |          \  }}t	          |          r~|s|t          j        t
          j        t                   |          }|r(|	                    	fd|D                       }|r|ndS d	                    	fd|D                       } d| S t          |          s|rt          j        t
          j        t          t          f         |          }|p t          |                                          }|r!|	                    	fd|D                       S d	                    	fd	|D                       } d| S t          j        t
          j        |          }|r
|d|         n|}|r dt!          |	           S S )
z"Expansion method for ';' operator.Nr
   r   c              3   F   K   | ]}| dt          |           V  d S Nr*   rH   rJ   s     r   rL   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  sB       ) )34t..eAtnn..) )r   r)   c              3   8   K   | ]}t          |          V  d S r$   rH   rN   s     r   rL   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  rO   r   r*   c              3   h   K   | ],\  }}|t          |           dt          |           V  -d S rr   rH   rQ   s      r   rL   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  sS       % %1} Q~~88a88$}}}% %r   c              3   h   K   | ],\  }}|t          |           dt          |           V  -d S )Nr)   rH   rQ   s      r   rL   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  sS       $ $1} Q~~88a88$}}}$ $r   )rC   r   r   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rI   )
r   r?   rD   r.   r/   rC   ra   r_   rn   r   s
    `       @r   _semi_path_expansionz URIVariable._semi_path_expansion   s:    =y=4=CH)%00U 		)F 		)F1:&9:EBBE )#== ) ) ) ) )8=) ) )   $,5xx5 ? ? ? ? ? ? ???(((((U 	,v 	,F19S*=%=>FFE2VEKKMM22E ,}} % % % % %% % %    88 $ $ $ $ %$ $ $  
 +++++qvu%%"(3gvge 	211U5$//111r   c                     |d S t          |          \  }}t          |          rM|sKt          j        t          j        t
                   |          }d                     fd|D                       S t          |          s|r|t          j        t          j        t          t
          f         |          }|p t          |                                          }|rdndd                     fd|D                       S t          j        t          j        |          }|r
|d |         n|}t          | j                  S )Nr)   c              3   B   K   | ]}t          |j                  V  d S r$   rI   r   )r1   rK   r   s     r   rL   z0URIVariable._string_expansion.<locals>.<genexpr>7  s/      ??AE!TY//??????r   re   rf   c              3   x   K   | ]4\  }}t          |j                  t          |j                  fz  V  5d S r$   ry   )r1   rR   rK   rh   r   s      r   rL   z0URIVariable._string_expansion.<locals>.<genexpr>>  s]        Aq eAty115DI3F3FGG     r   )rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rI   r   )r   r?   rD   r.   r/   ra   r_   rh   s   `      @r   _string_expansionzURIVariable._string_expansion)  sU    =4)%00U 	@F 	@F1:&9:EBBE88??????????U 	v 	F19S*=%=>FFE2VEKKMM22E$+8J88     !     
 qvu%%"(3gvgeUDI&&&r   var_dictc                    g }|| j         | j         iS | j        D ]\  }}|                    |d          }|s|dk    r|| j        v r| j        |         }|<d}| j        dv r| j        }n+| j        dv r| j        }n| j        dk    r| j        }n| j        } ||||d         |d                   }||	                    |           d}|r"| j
        | j                            |          z   }| j         |iS )a1  Expand the variable in question.

        Using ``var_dict`` and the previously parsed defaults, expand this
        variable and subvariables.

        :param dict var_dict: dictionary of key-value pairs to be used during
            expansion
        :returns: dict(variable=value)

        Examples::

            # (1)
            v = URIVariable('/var')
            expansion = v.expand({'var': 'value'})
            print(expansion)
            # => {'/var': '/value'}

            # (2)
            v = URIVariable('?var,hello,x,y')
            expansion = v.expand({'var': 'value', 'hello': 'Hello World!',
                                  'x': '1024', 'y': '768'})
            print(expansion)
            # => {'?var,hello,x,y':
            #     '?var=value&hello=Hello%20World%21&x=1024&y=768'}

        Nr   )r   r   )r
   r   r	   r.   r/   )r   r   getr   r   ro   rb   rv   r{   r;   rB   rC   rZ   )r   r|   return_valuesr?   optsrD   rn   	expansions           r   expandzURIVariable.expandG  s7   : M4=11. 	/ 	/JD$LLt,,E ,Ub[[TT]-B-Bd+}H}
** 6		*,, 1		#%% 5		 2	 yud9otH~NNH#$$X... 	CJ!3!3M!B!BBEu%%r   )r   Nr$   )__name__
__module____qualname____doc__r5   r6   r]   r   r"   r%   r   r   VariableValueboolrV   Optionalr:   rb   ro   rv   r{   VariableValueDictr\   r   r    r   r   r   r      s-        $ CI#HC    &(# ( ( ( (    +K +K +K +KZ- - - -*-- - 	-
 
3- 
C- - - -^0"0" 0" 	0"
 
30" 
C0" 0" 0" 0"d55 5 	5
 
35 
C5 5 5 5n'' ' 	'
 
3' 
C' ' ' '> 9=;& ;&
#45;&	
38	;& ;& ;& ;& ;& ;&r   r   rD   r   c                 |    | r5t          | t          t          f          rt          d | D                       sdS d| fS )Nc              3   f   K   | ],}t          |t                    ot          |          d k    V  -dS )r(   N)ri   r8   rl   )r1   rV   s     r   rL   z$is_list_of_tuples.<locals>.<genexpr>  s;      GGA:a''7CFFaKGGGGGGr   )FNT)ri   listr8   allrD   s    r   rT   rT     sT     %$// GGGGGGG
 {;r   c                 :    t          | t          t          f          S r$   )ri   r   r8   r   s    r   rU   rU     s    edE]+++r   c                 N    t          | t          t          j        j        f          S r$   )ri   dictcollectionsabcMutableMappingr   s    r   r[   r[     s    edKO$BCDDDr   utf-8encodingc                 Z    t          | t                    r|                     |          S | S r$   )ri   r]   encode)rD   r   s     r   _encoder     s+    % &||H%%%Lr   r   c                     t          | t          t          f          st          |           } t          j                            t          |           |          S r$   )ri   r]   bytesurllibr   rI   r   )rD   r   s     r   rI   rI     sA    ec5\** E

<gennd333r   )r   )r   collections.abcr   typingrV   urllib.parser   Unionr:   rj   rk   r]   rY   rX   r\   Tupler   Dictr   r   Anyr   r   rT   rU   r[   AnyStrr   r   rI   r    r   r   <module>r      s                gc5'367 J"#Ic&&'GC$$% F3-. c& c& c& c& c& c& c& c&L
5
WT1:aj6I1I)JKLLM
 
 
 
,QU ,t , , , ,EQU Et E E E E 18 s     4 4c 4c 4 4 4 4 4 4r   