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/html/premium_crap/venv/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 )z©Parse 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 |r¬t 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|r‰t 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`    üÿÿ ô  \ÿ"
þ