o
    >hsG                     @   s  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 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 dZ-dej.deje/ej0ejejeef   f fddZ1dej.de/fddZ2dej.de/fddZ3ddej4dede5fddZ6dej.dedefd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                   @   s   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dZdefddZdefddZdedefddZdedefddZdejdefddZededd fddZdS ) Operator +#./;?&=,!@|returnc                 C   s$   | t jkr	td S | t jkrtS dS )N%r   )r   reservedr   fragmentself r   t/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/uritemplate/variable.pyreserved_charactersG   s
   


zOperator.reserved_charactersc                 C   sF   | 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   r   r   r   expansion_separatorW   s   




zOperator.expansion_separatorc                 C   s   | t jkrdS tt| jS Nr   )r   r   tcaststrvaluer   r   r   r   variable_prefix   s   
zOperator.variable_prefixr'   c                 C   s
   t |dS r#   quoter   r'   r   r   r   _always_quote   s   
zOperator._always_quotec                 C   s   t j||krt|tS |S N)urllibparseunquoter*   r   r+   r   r   r   _only_quote_unquoted_characters   s   
z(Operator._only_quote_unquoted_charactersc                 C   sP   t |ttfst|}t |tr| }| tjks| tjkr#| |S | |S r-   )	
isinstancer&   bytesdecoder   r   r   r1   r,   r+   r   r   r   r*      s   


zOperator.quotesc                 C   s   t | tjS r-   )
_operatorsgetr   default)r5   r   r   r   from_string   s   zOperator.from_stringN)__name__
__module____qualname__r8   r   r   r   r   r   r    r!   reserved_eqreserved_commareserved_bangreserved_atreserved_piper&   r   r"   r(   r,   r1   r$   Anyr*   staticmethodr9   r   r   r   r   r   +   s.    4

r   )r   r	   r
   r   r   r   r   r   r   r   r   r   r6   c                   @   s  e Zd ZdZdefddZdefddZdefdd	ZdddZdede	de
deje deje f
ddZdede	de
deje deje f
ddZdede	de
deje deje f
ddZdede	de
deje deje f
ddZ	
ddeje dejeef fd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                 C   s,   || _ tj| _g | _g | _i | _|   d S r-   )originalr   r8   operator	variablesvariable_namesdefaultsr/   )r   rE   r   r   r   __init__   s   zURIVariable.__init__r   c                 C   s   d|  S )NzURIVariable(%s)r   r   r   r   r   __repr__   s   zURIVariable.__repr__c                 C   s   | j S r-   )rF   r   r   r   r   __str__   s   zURIVariable.__str__Nc           
      C   s   | j }| j d  }tv rt|| _| j dd }|d}|D ]E}d}|}d|v r4t|dd\}}|d}|d}d}d|v rSt|dd\}}	t	|	d}|rZ|| j
|< | j|||d	f q d
d | jD | _dS )zParse the variable.

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

        r      Nr   r   *:
   )explodeprefixc                 S   s   g | ]\}}|qS r   r   ).0varname_r   r   r   
<listcomp>  s    z%URIVariable.parse.<locals>.<listcomp>)rF   r6   r   r9   rG   splittupleendswithrstripintrJ   rH   appendrI   )
r   var_list_stroperator_strvar_listrE   default_valnamerR   rS   
prefix_strr   r   r   r/      s,   





zURIVariable.parserb   r'   rR   rS   c                    s`  |du rdS t |\}}| j | jj t|rM|sM|sdS ttjt |}|r:| j	 
 fdd|D S d
 fdd|D } d| S t|sS|r|sWdS ttjttf |}|pit| }|r|| j	 
 fdd|D S d
 fdd|D } d| S |rttj|}|r|d| n|} d | S d S )	z/Expansion method for the '?' and '&' operators.Nc                 3   s"    | ]} d  | V  qdS r   Nr   rT   v)_quoterb   r   r   	<genexpr>#  s    
z/URIVariable._query_expansion.<locals>.<genexpr>r   c                 3   s    | ]} |V  qd S r-   r   re   )rg   r   r   rh   '  s    r   c                 3   ,    | ]\}}t | d  | V  qdS rd   r)   rT   krf   rg   safer   r   rh   0      
c                 3   ri   )r   Nr)   rj   rl   r   r   rh   4  rn   )is_list_of_tuplesrG   r   r*   	list_testr$   r%   SequenceScalarVariableValuer"   join	dict_testMappingr&   sorteditemsTextr   rb   r'   rR   rS   tuplesrw   r   )rg   rb   rm   r   _query_expansion  sB   
zURIVariable._query_expansionc           
         s,  j  }j  |du st|ttttfst|dkrdS t	|\}}t
|rJ|sJ|s/d}ttjt |}fdd|D }|rH||S dS t|sP|rttjttf |}|pbt| }d |skd d}| fdd	|D }	|	r}|	S dS ttj|}|r|d| n|}j |S )
zSLabel and path expansion method.

        Expands for operators: '/', '.'

        Nr   r   c                    s    g | ]}|d ur j |qS r-   rG   r*   re   r   r   r   rW   [  s    z5URIVariable._label_path_expansion.<locals>.<listcomp>%s=%s%s,%sc                 3   s6    | ]\}}|d ur t |j |f V  qd S r-   r*   rG   rj   
format_strrm   r   r   r   rh   h  s    z4URIVariable._label_path_expansion.<locals>.<genexpr>)rG   r"   r   r2   r&   r\   floatcomplexlenro   rp   r$   r%   rq   rr   rs   rt   ru   rv   rw   rx   r*   )
r   rb   r'   rR   rS   join_strrz   rw   	fragmentsexpandedr   r   r   _label_path_expansion?  s<   


z!URIVariable._label_path_expansionc           	         sR  j  }j  |du rdS t|\}}t|rM|sMttjt |}|r:|	 fdd|D }|r8|S dS d	fdd|D }  d| S t
|sS|rttjttf |}|pet| }|ru|	fdd|D S d	fdd|D }  d| S ttj|}|r|d| n|}|r  dj | S  S )	z"Expansion method for ';' operator.Nc                 3   s,    | ]}|d ur  dt | V  qd S Nr   r)   re   )rb   rm   r   r   rh     s    "z3URIVariable._semi_path_expansion.<locals>.<genexpr>r   c                 3   s    | ]}t | V  qd S r-   r)   re   )rm   r   r   rh     s    r   c                 3   8    | ]\}}|d urt |  dj | V  qd S r   r   rj   rm   r   r   r   rh         c                 3   r   )Nr   r   rj   r   r   r   rh     r   )rG   r"   r   ro   rp   r$   r%   rq   rr   rs   rt   ru   r&   rv   rw   rx   r*   )	r   rb   r'   rR   rS   r   rz   rw   r   r   )rb   rm   r   r   _semi_path_expansions  s<   

z URIVariable._semi_path_expansionc                    s   |d u rd S t |\}}t|r'|s'ttjt |}dfdd|D S t|s-|rSttjt	tf |}|p?t
| }|rDdnd d fdd|D S ttj|}|rb|d | n|}j|S )Nr   c                 3   s    | ]	} j |V  qd S r-   r|   re   r   r   r   rh     s    z0URIVariable._string_expansion.<locals>.<genexpr>r}   r~   c                 3   s0    | ]\}} j |j |f V  qd S r-   r|   rj   r   r   r   r   rh     s
    
)ro   rp   r$   r%   rq   rr   rs   rt   ru   r&   rv   rw   rx   rG   r*   ry   r   r   r   _string_expansion  s    zURIVariable._string_expansionvar_dictc                 C   s  g }|du r| j | j iS | jD ]b\}}||d}|s)|dkr)|| jv r)| j| }|du r.qd}| jtjks<| jtjkr@| j}n| jtj	ksL| jtj
krP| j}n| jtjkrZ| j}n| j}||||d |d }|durq|| qd}|r| j | j | }| 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   rR   rS   )rF   rH   r7   rJ   rG   r   r   r   r   r    r!   r{   r   r   r   r]   r(   r"   rs   )r   r   return_valuesrb   optsr'   r   	expansionr   r   r   expand  s<   


zURIVariable.expand)r   Nr-   )r:   r;   r<   __doc__r&   rK   rL   rM   r/   VariableValueboolr$   Optionalr\   r{   r   r   r   VariableValueDictru   r   r   r   r   r   rD      sp    
*
0
4
4
rD   r'   r   c                 C   s0   | rt | ttfrtdd | D sdS d| fS )Nc                 s   s&    | ]}t |tot|d kV  qdS )   N)r2   rY   r   )rT   r$   r   r   r   rh     s   $ z$is_list_of_tuples.<locals>.<genexpr>)FNT)r2   listrY   allr'   r   r   r   ro     s   ro   c                 C   s   t | ttfS r-   )r2   r   rY   r   r   r   r   rp   #  s   rp   c                 C   s   t | ttjjfS r-   )r2   dictcollectionsabcMutableMappingr   r   r   r   rt   '  s   rt   utf-8encodingc                 C   s   t | tr
| |S | S r-   )r2   r&   encode)r'   r   r   r   r   _encode+  s   

r   rm   c                 C   s(   t | ttfst| } tjt| |S r-   )r2   r&   r3   r.   r/   r*   r   )r'   rm   r   r   r   r*   1  s   r*   )r   )8r   collections.abcr   enumstringtypingr$   urllib.parser.   Unionr\   r   r   r&   rr   rq   Listru   Tupler   Dictr   ascii_lettersdigitsr   Final__annotations__r   r   r   Enumr   r   r   r   r   r   r    r!   r?   rA   r@   r=   r>   r6   rD   rB   r   r   ro   rp   rt   AnyStrr3   r   r*   r   r   r   r   <module>   s`       \"
