
    ?wgF2              
       &   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j4                  d
edefdZdej(                  dedefdZy)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y	)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 | _        | j                          | j                          y )N )originaloperatorsafe	variablesvariable_namesdefaultsparse
post_parse)selfr   s     K/var/www/horilla/myenv/lib/python3.12/site-packages/uritemplate/variable.py__init__zURIVariable.__init__6   sG     	  	 ,.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                  | _        |j                  d      }|D ]  }d}|}d|v rt        |j                  dd            \  }}d}|j                  d      rd	}|dd
 }d}d|v r)t        |j                  dd            \  }}t        |      }|r|| j                  |<   | j                  j                  |||df        | j                  D 	
cg c]  \  }	}
|		 c}
}	| _        yc c}
}	w )zParse the variable.

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

        r      N   ,=F*T:)explodeprefix)r   r   	operatorsr   reservedr   splittupleendswithintr   r   appendr   )r   var_list_strvar_listr   default_valnamer.   r/   
prefix_strvarname_s              r   r   zURIVariable.parseO   sU    }}=={444 MM!,DM==,L==K11"155#,,DI%%c* 	CKDcz$)#))C*;$<!kG}}S!CRy&*Fd{#(C);#< jZ&1d#NN!!7f=>'	. <@>>J<GQwJJs   
E c                 F   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
                  | _         y	y	)
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   r1   r!   s    r   r   zURIVariable.post_parse|   s     	%)]]2
T]==CDJ==N*DM==CDJ==CDJDM==J&#,,DI 'r   r:   valuer.   r/   c                    |yt        |      \  }}| j                  t        |      rx|sv|syt        j                  t        j
                  t           |      }|r%| j                  j                  fd|D              S dj                  fd|D              } d| S t        |      s|r|syt        j                  t        j                  t        t        f   |      }|xs t        |j                               }|r$| j                  j                  fd|D              S dj                  fd|D              } d| S |r>t        j                  t        j                  |      }|r|d| n|} dt        |       S dz   S )z/Expansion method for the '?' and '&' operators.Nc              3   @   K   | ]  } d t        |         ywr*   Nquote.0vr:   r   s     r   	<genexpr>z/URIVariable._query_expansion.<locals>.<genexpr>   s(      *34tfAeAtn-.*s   r)   c              3   6   K   | ]  }t        |        y wr$   rE   rH   rI   r   s     r   rJ   z/URIVariable._query_expansion.<locals>.<genexpr>         ?Aq$ ?   r*   c              3   Z   K   | ]"  \  }}t        |       d t        |        $ ywrD   rE   rH   krI   r   s      r   rJ   z/URIVariable._query_expansion.<locals>.<genexpr>   s3      *=AQuQ~&aa'78*   (+c              3   Z   K   | ]"  \  }}t        |       d t        |        $ yw)r)   NrE   rP   s      r   rJ   z/URIVariable._query_expansion.<locals>.<genexpr>   s3      !=AQuQ~&aa'78!rR   )is_list_of_tuplesr   	list_testtcastSequenceScalarVariableValuer@   join	dict_testMappingstrsorteditemsTextrF   )r   r:   rA   r.   r/   tuplesr_   r   s    `     @r   _query_expansionzURIVariable._query_expansion   s    =)%0yyUFFF1::&9:EBE}})) *8=*    ? ??q((UvFF199S*=%=>FE2VEKKM2E}})) *EJ*    !EJ!  q((FF1665)E&,E'6N%EV1U5$/011czr   c                    | j                   }| j                  |.t        |t        t        t
        t        f      st        |      dk(  ryt        |      \  }}t        |      rb|s`|sd}t        j                  t        j                  t           |      }|D cg c]  }|t        |       }	}|	r|j                  |	      S dS t!        |      s|rwt        j                  t        j"                  t        t        f   |      }|xs t%        |j'                               }d|sdd}|j                  fd|D              }
|
r|
S dS t        j                  t        j(                  |      }|r|d| n|}t        |      S c c}w )zSLabel and path expansion method.

        Expands for operators: '/', '.'

        Nr   r)   %s=%s%s,%sc              3   ^   K   | ]$  \  }}|t        |      t        |      fz   & y wr$   rE   )rH   rQ   rI   
format_strr   s      r   rJ   z4URIVariable._label_path_expansion.<locals>.<genexpr>   s8      %Aq= eAtneAtn==%   *-)r@   r   
isinstancer]   r5   floatcomplexlenrT   rU   rV   rW   rX   rY   rF   rZ   r[   r\   r^   r_   r`   )r   r:   rA   r.   r/   r@   ra   r_   rI   	fragmentsexpandedrg   r   s              @@r   _label_path_expansionz!URIVariable._label_path_expansion   sZ    ==yy=53UG"<=E
a)%0UFFF1::&9:EBE16HA!-q$HIH/88==+BdBUvFF199S*=%=>FE2VEKKM2E J$
}} %!% H
  (81T1qvvu%"(gveUD!!) Is   F"Fc                 &  	 | j                   }| j                  	|y| j                  dk(  rd}t        |      \  }}t	        |      rq|sot        j                  t
        j                  t           |      }|r!|j                  	fd|D              }|r|S dS dj                  	fd|D              } d| S t        |      s|rt        j                  t
        j                  t        t        f   |      }|xs t        |j                               }|r|j                  	fd|D              S dj                  	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        |         y wNr*   rE   rG   s     r   rJ   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s,      )34tfAeAtn-.)s   !!r)   c              3   6   K   | ]  }t        |        y wr$   rE   rL   s     r   rJ   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  rM   rN   r*   c              3   ^   K   | ]$  \  }}|t        |       dt        |        & y wrr   rE   rP   s      r   rJ   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s;      %1} Q~&aa'78%rh   c              3   ^   K   | ]$  \  }}|t        |       dt        |        & y w)Nr)   rE   rP   s      r   rJ   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s;      $1} Q~&aa'78$rh   )r@   r   r   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rF   )
r   r:   rA   r.   r/   r@   ra   r_   rn   r   s
    `       @r   _semi_path_expansionz URIVariable._semi_path_expansion   s    ==yy===CH)%0UFFF1::&9:EBE#== )8=)  $,x55 ? ??q((UvFF199S*=%=>FE2VEKKM2E}} % %%   88 $ %$ 
 q
++qvvu%"(gveV1U5$/011r   c                 J    |y t        |      \  }}t        |      rG|sEt        j                  t        j                  t
           |      }dj                   fd|D              S t        |      s|rot        j                  t        j                  t        t
        f   |      }|xs t        |j                               }|rdnddj                   fd|D              S t        j                  t        j                  |      }|r|d | n|}t        | j                        S )Nr)   c              3   J   K   | ]  }t        |j                          y wr$   rF   r   )rH   rI   r   s     r   rJ   z0URIVariable._string_expansion.<locals>.<genexpr>7  s     ?AE!TYY/?s    #rd   re   c              3      K   | ]6  \  }}t        |j                        t        |j                        fz   8 y wr$   ry   )rH   rQ   rI   rg   r   s      r   rJ   z0URIVariable._string_expansion.<locals>.<genexpr>>  s=      Aq eAtyy15DII3FGGs   <?)rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   rF   r   )r   r:   rA   r.   r/   ra   r_   rg   s   `      @r   _string_expansionzURIVariable._string_expansion)  s     =)%0UFFF1::&9:EBE88????UvFF199S*=%=>FE2VEKKM2E$+J88 !  
 qvvu%"(gveUDII&&r   var_dictc                 R   g }|| j                   | j                   iS | j                  D ]  \  }}|j                  |d      }|s"|dk7  r|| j                  v r| j                  |   }|?d}| j                  dv r| j
                  }nC| j                  dv r| j                  }n(| j                  dk(  r| j                  }n| j                  } ||||d   |d         }||j                  |        d}|r(| j                  | 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{   r6   r?   r@   rZ   )r   r|   return_valuesr:   optsrA   rn   	expansions           r   expandzURIVariable.expandG  s*   : MM4==11.. 	/JD$LLt,EUb[TT]]-Bd+}H}}
* 66	*, 11	#% 55	 22	 ud9otH~NH#$$X.+	/. JJ!3!3M!BBEu%%r   )r   Nr$   )__name__
__module____qualname____doc__r0   r1   r]   r   r"   r%   r   r   VariableValueboolrV   Optionalr5   rb   ro   rv   r{   VariableValueDictr\   r   r    r   r   r   r      s   $ CI#HC &(# ( +KZ-*-- - 	-
 

3- 
C-^0"0" 0" 	0"
 

30" 
C0"d55 5 	5
 

35 
C5n'' ' 	'
 

3' 
C'> 9=;&

#45;&	
38	;&r   r   rA   r   c                 `    | r(t        | t        t        f      rt        d | D              syd| fS )Nc              3   \   K   | ]$  }t        |t              xr t        |      d k(   & yw)r(   N)ri   r3   rl   )rH   rV   s     r   rJ   z$is_list_of_tuples.<locals>.<genexpr>  s'     GA:a'7CFaK7Gs   *,)FNT)ri   listr3   allrA   s    r   rT   rT     s0     %$/GGG;r   c                 .    t        | t        t        f      S r$   )ri   r   r3   r   s    r   rU   rU     s    edE]++r   c                 V    t        | t        t        j                  j                  f      S r$   )ri   dictcollectionsabcMutableMappingr   s    r   r[   r[     s    edKOO$B$BCDDr   encodingc                 H    t        | t              r| j                  |      S | S r$   )ri   r]   encode)rA   r   s     r   _encoder     s     %||H%%Lr   r   c                     t        | t        t        f      st        |       } t        j                  j                  t        |       |      S r$   )ri   r]   bytesurllibr   rF   r   )rA   r   s     r   rF   rF     s4    ec5\*E
<<gend33r   )zutf-8)r   collections.abcr   typingrV   urllib.parser   Unionr5   rj   rk   r]   rY   rX   r\   Tupler   Dictr   r   Anyr   r   rT   rU   r[   AnyStrr   r   rF   r    r   r   <module>r      sL      ggc5'367 JJ"#IIc&&'GGC$$% FF3-. c& c&L
55
WWT1::ajj6I1I)JKLLM
,QUU ,t ,EQUU Et E188 s  4 4c 4c 4r   