
    ZrhsG                        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j2                  e   ed<   dZej2                  e   ed<   dZej2                  e   ed<   e e Zej2                  e   ed	<    G d
 dej<                        Zej@                  ejB                  ejD                  ejF                  ejH                  ejJ                  ejL                  ejN                  ejP                  ejR                  ejT                  ejV                  dZ,ej2                  ej(                  eef      ed<    G d d      Z-dej\                  dej$                  e/ej`                  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jh                  dede5fdZ6dej\                  dedefdZ7y)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y)Operator +#./;?&=,!@|returnc                 n    | t         j                  k(  r	t        dz   S | t         j                  k(  rt        S y)N%r	   )r   reservedr   fragmentselfs    g/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/uritemplate/variable.pyreserved_characterszOperator.reserved_charactersG   s4     8$$$'#--8$$$''    c                     | t         j                  k(  ry| t         j                  k(  ry| t         j                  k(  ry| t         j                  k(  s| t         j
                  k(  ryy)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   s[    * 81118(((8000H---x=== r   c                 r    | t         j                  k(  ryt        j                  t        | j
                        S Nr	   )r   r   tcaststrvaluer   s    r   variable_prefixzOperator.variable_prefix   s(    8$$$vvc4::&&r   r,   c                     t        |d      S r(   quoter   r,   s     r   _always_quotezOperator._always_quote   s    UBr   c                 j    t         j                  j                  |      |k(  rt        |t              S |S N)urllibparseunquoter0   r   r1   s     r   _only_quote_unquoted_charactersz(Operator._only_quote_unquoted_characters   s,    <<&%/ 455r   c                    t        |t        t        f      st        |      }t        |t              r|j                         }| t        j
                  k(  s| t        j                  k(  r| j                  |      S | j                  |      S r4   )	
isinstancer+   bytesdecoder   r   r   r8   r2   r1   s     r   r0   zOperator.quote   sk    %#u.JEeU#LLNE8$$$0A0A(A77>>!!%((r   sc                 J    t         j                  | t        j                        S r4   )
_operatorsgetr   default)r=   s    r   from_stringzOperator.from_string   s    ~~a!1!1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   +   s     GHH  L  $'!KNMKMS  "S "h' ' 3  3  S S 
)155 )S ) 3s 3z 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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.

    varc                     || _         t        j                  | _        g | _        g | _        i | _        | j                          y r4   )originalr   rA   operator	variablesvariable_namesdefaultsr6   )r   rP   s     r   __init__zURIVariable.__init__   s<     "*"2"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                 r   | j                   }| j                   d   x}t        v r)t        j                  |      | _        | j                   dd }|j                  d      }|D ]  }d}|}d|v rt        |j                  dd            \  }}|j                  d      }|j                  d      }d}d|v r*t        |j                  dd            \  }}	t        |	d      }|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      Nr   r   *:
   )explodeprefix)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_strvarname_s               r   r6   zURIVariable.parse   s0    }} MM!,,L;$00>DM==,L%%c* 	CKD cz$)#))C*;$<!kmmC(G;;s#D&*Fd{#(C);#< jZ,&1d#NN!!7f=>'	. <@>>J<GQwJJs   D3rm   r,   ra   rb   c                    |yt        |      \  }}| j                  j                         | j                  j                  t	        |      r|s|syt        j                  t
        j                  t           |      }|r3| j                  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                               }|r3| j                  j                         j                  fd|D              S dj                  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  |         ywr   NrM   ).0v_quoterm   s     r   	<genexpr>z/URIVariable._query_expansion.<locals>.<genexpr>#  s'      @./tfAfQi[)@s   r   c              3   .   K   | ]  } |        y wr4   rM   )rt   ru   rv   s     r   rw   z/URIVariable._query_expansion.<locals>.<genexpr>'  s      :q :s   r   c              3   R   K   | ]  \  }}t        |       d  |          ywrs   r/   rt   kru   rv   safes      r   rw   z/URIVariable._query_expansion.<locals>.<genexpr>0  s2      @8<1uQ~&aq	{3@   $'c              3   R   K   | ]  \  }}t        |       d  |          yw)r   Nr/   rz   s      r   rw   z/URIVariable._query_expansion.<locals>.<genexpr>4  s0      !8<1uQ~&aq	{3!r}   )is_list_of_tuplesrS   r   r0   	list_testr)   r*   SequenceScalarVariableValuer&   join	dict_testMappingr+   sorteditemsText)	r   rm   r,   ra   rb   tuplesr   rv   r|   s	    `     @@r   _query_expansionzURIVariable._query_expansion  s    =)%0}}002$$UFFF1::&9:EBE}}88:?? @38@    :E ::q((UvFF199S*=%=>FE2VEKKM2E}}88:?? @@E@    !@E!  q((FF1665)E&,E'6N%EV1VE]O,,czr   c                      j                   j                         } j                   j                         |.t        |t        t
        t        t        f      st        |      dk(  ryt        |      \  }}t        |      rq|so|sd}t        j                  t        j                  t           |      }|D cg c]   }| j                   j                  |      " }	}|	r|j!                  |	      S dS t#        |      s|rxt        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|} j                   j                  |      S c c}w )zSLabel and path expansion method.

        Expands for operators: '/', '.'

        Nr   r   %s=%s%s,%sc              3   |   K   | ]3  \  }}|,t        |      j                  j                  |      fz   5 y wr4   r0   rS   )rt   r{   ru   
format_strr|   r   s      r   rw   z4URIVariable._label_path_expansion.<locals>.<genexpr>h  sA      %Aq= eAtndmm.A.A!.DEE%   9<)rS   r&   r   r:   r+   rg   floatcomplexlenr   r   r)   r*   r   r   r0   r   r   r   r   r   r   )r   rm   r,   ra   rb   join_strr   r   ru   	fragmentsexpandedr   r|   s   `          @@r   _label_path_expansionz!URIVariable._label_path_expansion?  s    ==446}}002=53UG"<=E
a)%0UFFF1::&9:EBE05+,##A&I  098==+BdBUvFF199S*=%=>FE2VEKKM2E J$
}} %!% H
  (81T1qvvu%"(gve}}""5))-s   7G ?G c                 `   	  j                   j                         } j                   j                         	|y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 j                   j!                  |       S S )z"Expansion method for ';' operator.Nc              3   F   K   | ]  }| dt        |         y wNr   r/   )rt   ru   rm   r|   s     r   rw   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s,      )34tfAeAtn-.)s   !!r   c              3   6   K   | ]  }t        |        y wr4   r/   )rt   ru   r|   s     r   rw   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  s      ?Aq$ ?s   r   c              3   |   K   | ]3  \  }}|,t        |       dj                  j                  |        5 y wr   r   rt   r{   ru   r|   r   s      r   rw   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  sD      %1} Q~&a(;(;A(>'?@%r   c              3   |   K   | ]3  \  }}|,t        |       dj                  j                  |        5 y w)Nr   r   r   s      r   rw   z3URIVariable._semi_path_expansion.<locals>.<genexpr>  sD      $1} Q~&a(;(;A(>'?@$r   )rS   r&   r   r   r   r)   r*   r   r   r   r   r   r+   r   r   r   r0   )
r   rm   r,   ra   rb   r   r   r   r   r|   s
   ``       @r   _semi_path_expansionz URIVariable._semi_path_expansions  s    ==446}}002=)%0UFFF1::&9:EBE#== )8=)  $,x55 ? ??q((UvFF199S*=%=>FE2VEKKM2E}} % %%   88 $ %$ 
 q
++qvvu%"(gveV1T]]007899r   c                 T    |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|} j                  j                  |      S )Nr   c              3   T   K   | ]  }j                   j                  |       ! y wr4   rS   r0   )rt   ru   r   s     r   rw   z0URIVariable._string_expansion.<locals>.<genexpr>  s      BqDMM//2Bs   %(r   r   c              3      K   | ]@  \  }}j                   j                  |      j                   j                  |      fz   B y wr4   r   )rt   r{   ru   r   r   s      r   rw   z0URIVariable._string_expansion.<locals>.<genexpr>  sE      Aq dmm11!4dmm6I6I!6LMMs   AA	)r   r   r)   r*   r   r   r   r   r   r+   r   r   r   rS   r0   )r   rm   r,   ra   rb   r   r   r   s   `      @r   _string_expansionzURIVariable._string_expansion  s     =)%0UFFF1::&9:EBE88BEBBBUvFF199S*=%=>FE2VEKKM2E$+J88 !  
 qvvu%"(gve}}""5))r   var_dictc                 \   g }|| j                   | j                   iS | j                  D ]+  \  }}|j                  |d      }|s"|dk7  r|| j                  v r| j                  |   }|@d}| j                  t
        j                  k(  s| j                  t
        j                  k(  r| j                  }n}| j                  t
        j                  k(  s| j                  t
        j                  k(  r| j                  }n6| j                  t
        j                  k(  r| j                  }n| j                  } ||||d   |d         }||j                  |       . d}|rD| j                  j!                         | 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	   ra   rb   )rR   rT   r@   rV   rS   r   r"   r!   r   r$   r%   r   r#   r   r   rh   r-   r&   r   )r   r   return_valuesrm   optsr,   r   	expansions           r   expandzURIVariable.expand  s   : MM4==11.. %	/JD$LLt,EUb[TT]]-Bd+}H!6!66==H$B$BB 66	!:!::==H$J$JJ 11	("?"?? 55	 22	 !ud9otH~NH#$$X.K%	/N --/--335::=IJ  u%%r   )r   Nr4   )rC   rD   rE   __doc__r+   rW   rY   r[   r6   VariableValueboolr)   Optionalrg   r   r   r   r   VariableValueDictr   r   rM   r   r   rO   rO      s}   $C  (# ( (KT.. . 	.
 

3. 
C.`2*2* 2* 	2*
 

32* 
C2*h22 2 	2
 

32 
C2h** * 	*
 

3* 
C*> 9=N&

#45N&	
38	N&r   rO   r,   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)   N)r:   rd   r   )rt   r)   s     r   rw   z$is_list_of_tuples.<locals>.<genexpr>  s'     GA:a'7CFaK7Gs   *,)FNT)r:   listrd   allr,   s    r   r   r     s0     %$/GGG;r   c                 .    t        | t        t        f      S r4   )r:   r   rd   r   s    r   r   r   #  s    edE]++r   c                 V    t        | t        t        j                  j                  f      S r4   )r:   dictcollectionsabcMutableMappingr   s    r   r   r   '  s    edKOO$B$BCDDr   encodingc                 H    t        | t              r| j                  |      S | S r4   )r:   r+   encode)r,   r   s     r   _encoder   +  s     %||H%%Lr   r|   c                     t        | t        t        f      st        |       } t        j                  j                  t        |       |      S r4   )r:   r+   r;   r5   r6   r0   r   )r,   r|   s     r   r0   r0   1  s4    ec5\*E
<<gend33r   )zutf-8)8r   collections.abcr   enumstringtypingr)   urllib.parser5   Unionrg   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      sw  "     ggc5'3<= JJ"#FFIIc&&'GGC$$%	 FF3-.  V]]O40   &QWWS\ %)QWWS\ )(3}[M%B aggcl B~3tyy ~3D 
							'	'					&	&		"	"		/	/														 	 .
AGGAFF3=)*  W& W&t

55
WWT1::ajj6I1I)JKLLM
,QUU ,t ,EQUU Et E188 s  4 4c 4c 4r   