
    
hsG                        U d Z ddlZddlZddlZddlZddlZej	        e
eeedf         Zej	        ej        e         ej        e         ej        eef         ej        eef         ef         Zej        eef         Zej         ej         dZej        e         ed<   dZej        e         ed<   dZej        e         ed<   e e Zej        e         ed	<    G d
 dej                  Zej         ej!        ej"        ej#        ej$        ej%        ej&        ej'        ej(        ej)        ej*        ej+        dZ,ej        ej        eef                  ed<    G d d          Z-dej.        dej        e/ej0        ej        ej        eef                           f         fdZ1dej.        de/fdZ2dej.        de/fdZ3ddej4        dede5fdZ6dej.        dedefdZ7d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?
>

    Nz~-_._UNRESERVED_CHARACTERSz:/?#[]@_GEN_DELIMSz!$&'()*+,;=_SUB_DELIMS_RESERVED_CHARACTERSc                       e 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ZdZdefdZdefdZdefdZdedefdZdedefdZdej        defdZededd fd            ZdS )Operator +#./;?&=,!@|returnc                 h    | t           j        k    r
t          dz   S | t           j        k    rt          S dS )N%r	   )r   reservedr   fragmentselfs    k/home/visionen/pythonvenv/lib/python3.11/site-packages/uritemplate-4.2.0-py3.11.egg/uritemplate/variable.pyreserved_characterszOperator.reserved_charactersG   s6     8$$$'#--8$$$''r    c                     | t           j        k    rdS | t           j        k    rdS | t           j        k    rdS | t           j        k    s| t           j        k    rdS dS )aC  Identify the separator used during expansion.

        Per `Section 3.2.1. Variable Expansion`_:

        ======  ===========    =========
        Type    Separator
        ======  ===========    =========
                ``","``        (default)
        ``+``   ``","``
        ``#``   ``","``
        ``.``   ``"."``
        ``/``   ``"/"``
        ``;``   ``";"``
        ``?``   ``"&"``
        ``&``   ``"&"``
        ======  ===========    =========

        .. _`Section 3.2.1. Variable Expansion`:
            https://www.rfc-editor.org/rfc/rfc6570#section-3.2.1
        r   r   r   r   r   )r   label_with_dot_prefixpath_segmentpath_style_parameterform_style_queryform_style_query_continuationr   s    r   expansion_separatorzOperator.expansion_separatorW   se    * 811138(((380003H---x===3 sr   c                 d    | t           j        k    rdS t          j        t          | j                  S Nr	   )r   r   tcaststrvaluer   s    r   variable_prefixzOperator.variable_prefix   s)    8$$$2vc4:&&&r   r,   c                 "    t          |d          S r(   quoter   r,   s     r   _always_quotezOperator._always_quote   s    UBr   c                 v    t           j                            |          |k    rt          |t                    S |S N)urllibparseunquoter0   r   r1   s     r   _only_quote_unquoted_charactersz(Operator._only_quote_unquoted_characters   s3    <&&%// 4555r   c                 >   t          |t          t          f          st          |          }t          |t                    r|                                }| t          j        k    s| t          j        k    r|                     |          S |                     |          S r4   )	
isinstancer+   bytesdecoder   r   r   r8   r2   r1   s     r   r0   zOperator.quote   s    %#u.. 	JJEeU## 	#LLNNE8$$$0A(A(A77>>>!!%(((r   sc                 L    t                               | t          j                  S r4   )
_operatorsgetr   default)r=   s    r   from_stringzOperator.from_string   s    ~~a!1222r   N)__name__
__module____qualname__rA   r   r   r!   r"   r#   r$   r%   reserved_eqreserved_commareserved_bangreserved_atreserved_piper+   r   r&   r-   r2   r8   r)   Anyr0   staticmethodrB    r   r   r   r   +   sI        GHH  L  $'!KNMKMS     "S " " " "h' ' ' ' ' 3  3        S S    
)15 )S ) ) ) ) 3s 3z 3 3 3 \3 3 3r   r   )r
   r   r   r   r   r   r   r   r   r   r   r   r?   c                      e Zd ZdZdefdZdefdZdef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.

    varc                     || _         t          j        | _        g | _        g | _        i | _        |                                  d S r4   )originalr   rA   operator	variablesvariable_namesdefaultsr6   )r   rP   s     r   __init__zURIVariable.__init__   sA     "*"2  	 ,.DF

r   r   c                     d| z  S )NzURIVariable(%s)rM   r   s    r   __repr__zURIVariable.__repr__   s     4''r   c                     | j         S r4   )rR   r   s    r   __str__zURIVariable.__str__   s
    }r   Nc                 z   | j         }| j         d         x}t          v r.t                              |          | _        | j         dd         }|                    d          }|D ]}d}|}d|v r&t          |                    dd                    \  }}|                    d          }|                    d          }d}d|v r6t          |                    dd                    \  }}	t          |	d          }|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      Nr   r   *:
   )explodeprefixc                     g | ]\  }}|S rM   rM   ).0varname_s      r   
<listcomp>z%URIVariable.parse.<locals>.<listcomp>  s    JJJ<GQwJJJr   )rR   r?   r   rB   rS   splittupleendswithrstripintrV   rT   appendrU   )
r   var_list_stroperator_strvar_listrP   default_valnamera   rb   
prefix_strs
             r   r6   zURIVariable.parse   sa    } M!,,L;;$00>>DM=,L%%c** 	 	CKD czz$)#))C*;*;$<$<!kmmC((G;;s##D&*Fd{{#(C););#<#< jZ,, 2&1d#N!!7f==>    KJ4>JJJr   rr   r,   ra   rb   c                    |dS t          |          \  }}| j                                        | j        j        t	          |          r|s|sdS t          j        t
          j        t                   |          }|r9| 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          |                                          }|r9| j        	                                
                    fd|D                       S d
                    fd|D                       } d| S |r=t          j        t
          j        |          }|r
|d|         n|} d |           S dz   S )z/Expansion method for the '?' and '&' operators.Nc              3   8   K   | ]} d  |           V  dS r   NrM   )rd   v_quoterr   s     r   	<genexpr>z/URIVariable._query_expansion.<locals>.<genexpr>#  sR       @ @./t))ffQii))@ @ @ @ @ @r   r   c              3   .   K   | ]} |          V  d S r4   rM   )rd   rw   rx   s     r   ry   z/URIVariable._query_expansion.<locals>.<genexpr>'  s+       : :q : : : : : :r   r   c              3   Z   K   | ]%\  }}t          |           d  |           V  &dS rv   r/   rd   krw   rx   safes      r   ry   z/URIVariable._query_expansion.<locals>.<genexpr>0  s^       @ @8<1uQ~~33q		33@ @ @ @ @ @r   c              3   Z   K   | ]%\  }}t          |           d  |           V  &dS )r   Nr/   r|   s      r   ry   z/URIVariable._query_expansion.<locals>.<genexpr>4  sV       ! !8<1uQ~~33q		33! ! ! ! ! !r   )is_list_of_tuplesrS   r   r0   	list_testr)   r*   SequenceScalarVariableValuer&   join	dict_testMappingr+   sorteditemsText)	r   rr   r,   ra   rb   tuplesr   rx   r~   s	    `     @@r   _query_expansionzURIVariable._query_expansion  s    =4)%00}0022$U 
	)F 
	) tF1:&9:EBBE )}88::?? @ @ @ @ @38@ @ @     : : : :E : : :::(((((U 	)v 	) tF19S*=%=>FFE2VEKKMM22E )}88::?? @ @ @ @ @@E@ @ @     ! ! ! ! !@E! ! !   ((((( 	-F165))E&,7E'6'NN%E,,VVE]],,,czr   c                    
  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|} j                             |          S )zSLabel and path expansion method.

        Expands for operators: '/', '.'

        Nr   r   c                 H    g | ]}|j                             |          S r4   rS   r0   rd   rw   r   s     r   rg   z5URIVariable._label_path_expansion.<locals>.<listcomp>[  s1       +,##A&&r   %s=%s%s,%sc              3   |   K   | ]6\  }}|t          |          j                             |          fz  V  7d S r4   r0   rS   )rd   r}   rw   
format_strr~   r   s      r   ry   z4URIVariable._label_path_expansion.<locals>.<genexpr>h  sW       % %Aq= eAtnndm.A.A!.D.DEE ===% %r   )rS   r&   r   r:   r+   rl   floatcomplexlenr   r   r)   r*   r   r   r   r   r   r   r   r   r0   )r   rr   r,   ra   rb   join_strr   r   	fragmentsexpandedr   r~   s   `         @@r   _label_path_expansionz!URIVariable._label_path_expansion?  s    =4466}0022=53UG"<== E

a4)%00U 	CF 	C F1:&9:EBBE   05  I 09B8==+++dBU 	2v 	2F19S*=%=>FFE2VEKKMM22E J $
}} % % % % % %!% % %  H
  (188T1qvu%%"(3gvge}""5)))r   c                    	  j                                         } j                                         	|dS 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 j                             |           S S )z"Expansion method for ';' operator.Nc              3   F   K   | ]}| dt          |           V  d S Nr   r/   )rd   rw   rr   r~   s     r   ry   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  sB       ) )34t..eAtnn..) )r   r   c              3   8   K   | ]}t          |          V  d S r4   r/   )rd   rw   r~   s     r   ry   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s+       ? ?Aq$ ? ? ? ? ? ?r   r   c              3   |   K   | ]6\  }}|t          |           dj                             |           V  7d S r   r   rd   r}   rw   r~   r   s      r   ry   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s[       % %1} Q~~@@(;(;A(>(>@@$}}}% %r   c              3   |   K   | ]6\  }}|t          |           dj                             |           V  7d S )Nr   r   r   s      r   ry   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s[       $ $1} Q~~@@(;(;A(>(>@@$}}}$ $r   )rS   r&   r   r   r   r)   r*   r   r   r   r   r   r+   r   r   r   r0   )
r   rr   r,   ra   rb   r   r   r   r   r~   s
   ``       @r   _semi_path_expansionz URIVariable._semi_path_expansions  sQ    =4466}0022=4)%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 	:99T]0077999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|} j                            |          S )Nr   c              3   L   K   | ]}j                             |          V  d S r4   r   r   s     r   ry   z0URIVariable._string_expansion.<locals>.<genexpr>  s3      BBqDM//22BBBBBBr   r   r   c              3      K   | ]>\  }}j                             |          j                             |          fz  V  ?d S r4   r   )rd   r}   rw   r   r   s      r   ry   z0URIVariable._string_expansion.<locals>.<genexpr>  se        Aq dm11!44dm6I6I!6L6LMM     r   )r   r   r)   r*   r   r   r   r   r   r+   r   r   r   rS   r0   )r   rr   r,   ra   rb   r   r   r   s   `      @r   _string_expansionzURIVariable._string_expansion  sY    =4)%00U 	CF 	CF1:&9:EBBE88BBBBEBBBBBBU 	v 	F19S*=%=>FFE2VEKKMM22E$+8J88     !     
 qvu%%"(3gvge}""5)))r   var_dictc                    g }|| j         | j         iS | j        D ]\  }}|                    |d          }|s|dk    r|| j        v r| j        |         }|<d}| j        t
          j        k    s| j        t
          j        k    r| j        }nV| j        t
          j	        k    s| j        t
          j
        k    r| j        }n$| j        t
          j        k    r| j        }n| j        } ||||d         |d                   }||                    |           d}|rF| 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	   ra   rb   )rR   rT   r@   rV   rS   r   r"   r!   r   r$   r%   r   r#   r   r   rm   r-   r&   r   )r   r   return_valuesrr   optsr,   r   	expansions           r   expandzURIVariable.expand  s   : M4=11. %	/ %	/JD$LLt,,E ,Ub[[TT]-B-Bd+}H!666=H$BBB 6		!:::=H$JJJ 1		("??? 5		 2	 !yud9otH~NNH#$$X... 	--//-3355::=IIJ  u%%r   )r   Nr4   )rC   rD   rE   __doc__r+   rW   rY   r[   r6   VariableValueboolr)   Optionalrl   r   r   r   r   VariableValueDictr   r   rM   r   r   rO   rO      s        $C     (# ( ( ( (    (K (K (K (KT.. . 	.
 
3. 
C. . . .`2*2* 2* 	2*
 
32* 
C2* 2* 2* 2*h22 2 	2
 
32 
C2 2 2 2h** * 	*
 
3* 
C* * * *> 9=N& N&
#45N&	
38	N& N& N& N& N& N&r   rO   r,   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 )   N)r:   ri   r   )rd   r)   s     r   ry   z$is_list_of_tuples.<locals>.<genexpr>  s;      GGA:a''7CFFaKGGGGGGr   )FNT)r:   listri   allr,   s    r   r   r     sT     %$// GGGGGGG
 {;r   c                 :    t          | t          t          f          S r4   )r:   r   ri   r   s    r   r   r   #  s    edE]+++r   c                 N    t          | t          t          j        j        f          S r4   )r:   dictcollectionsabcMutableMappingr   s    r   r   r   '  s    edKO$BCDDDr   utf-8encodingc                 Z    t          | t                    r|                     |          S | S r4   )r:   r+   encode)r,   r   s     r   _encoder   +  s+    % &||H%%%Lr   r~   c                     t          | t          t          f          st          |           } t          j                            t          |           |          S r4   )r:   r+   r;   r5   r6   r0   r   )r,   r~   s     r   r0   r0   1  sA    ec5\** E

<gennd333r   )r   )8r   collections.abcr   enumstringtypingr)   urllib.parser5   Unionrl   r   r   r+   r   r   Listr   Tupler   Dictr   ascii_lettersdigitsr   Final__annotations__r   r   r   Enumr   r   r   r!   r"   r#   r$   r%   rH   rJ   rI   rF   rG   r?   rO   rK   r   r   r   r   r   AnyStrr;   r   r0   rM   r   r   <module>r      s%    "              gc5'3<= J"#FIc&&'GC$$%	 F3-.  0V]000     &QWS\ % % %)QWS\ ) ) )(3%B[%B%B agcl B B B~3 ~3 ~3 ~3 ~3ty ~3 ~3 ~3D 
					'				&		"		/										 . .
AGAF3=)*    W& W& W& W& W& W& W& W&t

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   