
    af5              	       &   d dl Z d dlmZmZ d dlmZ d dlmZmZ dZ	de
fdZe G d d	e                      Zeddee
         d
ee         dee         fd            Zeddee
         d
ee         dee         fd            Zede
fd            ZdS )    N)OptionalUnion)public)RegisterOptionsSubscribeOptions)Patternregister	subscribeerrorconvert_starred_uriuric                     t          |           t          k    sJ |                     d          }|dk    rd}n7|dk    r| d         dk    rd}| dd         } nd}|                     dd	          } | |fS )
a  
    Convert a starred URI to a standard WAMP URI and a detected matching
    policy. A starred URI is one that may contain the character '*' used
    to mark URI wildcard components or URI prefixes. Starred URIs are
    more comfortable / intuitive to use at the user/API level, but need
    to be converted for use on the wire (WAMP protocol level).

    This function takes a possibly starred URI, detects the matching policy
    implied by stars, and returns a pair (uri, match) with any stars
    removed from the URI and the detected matching policy.

    An URI like 'com.example.topic1' (without any stars in it) is
    detected as an exact-matching URI.

    An URI like 'com.example.*' (with exactly one star at the very end)
    is detected as a prefix-matching URI on 'com.example.'.

    An URI like 'com.*.foobar.*' (with more than one star anywhere) is
    detected as a wildcard-matching URI on 'com..foobar.' (in this example,
    there are two wildcard URI components).

    Note that an URI like 'com.example.*' is always detected as
    a prefix-matching URI 'com.example.'. You cannot express a wildcard-matching
    URI 'com.example.' using the starred URI notation! A wildcard matching on
    'com.example.' is different from prefix-matching on 'com.example.' (which
    matches a strict superset of the former!). This is one reason we don't use
    starred URIs for WAMP at the protocol level.
    *r   exact   prefixNwildcard )typestrcountreplace)r   	cnt_starsmatchs      C/var/www/html/env/lib/python3.11/site-packages/autobahn/wamp/uri.pyr   r   +   s    : 99		#IA~~	aCGsNN#2#h kk#r"":    c            
          e Zd ZdZdZdZdZdZdZdZ	 e
j        d          Z	  e
j        d          Z	  e
j        d          Z	 	 	 dd	ed
edeeeef                  dee         fdZeed                         Zeed                         Zed             Zd Zed             Zed             Zed             ZdS )r   z
    A WAMP URI Pattern.

    .. todo::

       * suffix matches
       * args + kwargs
       * uuid converter
       * multiple URI patterns per decorated object
       * classes: Pattern, EndpointPattern, ..
    r         z^[a-z0-9][a-z0-9_\-]*$z^<([a-z][a-z0-9_]*)>$z^<([a-z][a-z0-9_]*):([a-z]*)>$Nr   targetoptionscheck_typesc                    t          |          t          k    sJ t          |          dk    sJ |t          j        t          j        t          j        fv sJ |t          j        k    r|t          |          t          k    sJ n/|t          j        k    r|t          |          t          k    sJ nd}|	                    d          }d}g }i }d}	t          t          |                    D ]}
||
         }t          j                            |          }|r|                                \  }}|dvrt          d          |dk    r%|
t          |          dz
  k    rt          d          ||v rt          d          |d	v rt          ||<   n |d
k    rt          ||<   nt          d          |                    d                    ||                     |	dz  }	t          j                            |          }|rg|                                d         }||v rt          d          t          ||<   |                    d                    ||                     |	dz  }	zt          j                            |          }|r|                    |           |dk    r9|	dz  }	|                    d                    |                     t          ||	<   t          d          |rMt          j        | _        dd                    |          z   dz   }t/          j        |          | _        || _        nt          j        | _        d| _        d| _        || _        || _        || _        || _        dS )a  

        :param uri: The URI or URI pattern, e.g. ``"com.myapp.product.<product:int>.update"``.
        :type uri: str

        :param target: The target for this pattern: a procedure endpoint (a callable),
           an event handler (a callable) or an exception (a class).
        :type target: callable or obj

        :param options: An optional options object
        :type options: None or RegisterOptions or SubscribeOptions

        :param check_types: Enable automatic type checking against (Python 3.5+) type hints
            specified on the ``endpoint`` callable. Types are checked at run-time on each
            invocation of the ``endpoint`` callable. When a type mismatch occurs, the error
            is forwarded to the callee code in ``onUserError`` override method of
            :class:`autobahn.wamp.protocol.ApplicationSession`. An error
            of type :class:`autobahn.wamp.exception.TypeCheckError` is also raised and
            returned to the caller (via the router).
        :type check_types: bool

        r   N.z	[^\s\.#]+)r   stringintsuffixzinvalid URIr(   r   )r   r&   r(   r'   zlogic errorz
(?P<{}>{})r   z({})^z\.$) r   r   lenr   URI_TARGET_ENDPOINTURI_TARGET_HANDLERURI_TARGET_EXCEPTIONr   r   splitrange_URI_NAMED_CONVERTED_COMPONENTr   groups	TypeErrorr'   appendformat_URI_NAMED_COMPONENT_URI_COMPONENTURI_TYPE_WILDCARD_typejoinrecompile_pattern_namesURI_TYPE_EXACT_uri_target_options_check_types)selfr   r!   r"   r#   
components_URI_COMP_CHARSplncgroup_counti	componentr   name	comp_typeps                   r   __init__zPattern.__init__   sy   0 S		S    C176"5"79 9 9 9 9 W000OtG}}'G'G'GGw111OtG}}8H'H'H'HHGYYs^^
& s:'' 1	+ 1	+A"1I:@@KKE "',,..i$FFF#M222((Q#j//A2E-E-E#M2222::#M222 ;;;"BtHH%''"BtHH $M222		,--dODDEEEq 066yAAE ||~~a(2::#M2224		,--dODDEEEq *00;;E 		)$$$Bq 		'..99:::"%;M*** 
	 2DJejjnn$s*AJqMMDMDKK !/DJ DMDK	'r   c                     | j         S )z
        Returns the Options instance (if present) for this pattern.

        :return: None or the Options instance
        :rtype: None or RegisterOptions or SubscribeOptions
        )rB   rD   s    r   r"   zPattern.options   s     }r   c                     | j         S )z
        Returns the URI type of this pattern

        :return:
        :rtype: Pattern.URI_TYPE_EXACT, Pattern.URI_TYPE_PREFIX or Pattern.URI_TYPE_WILDCARD
        )r9   rQ   s    r   uri_typezPattern.uri_type   s     zr   c                     | j         S )z
        Returns the original URI (pattern) for this pattern.

        :returns: The URI (pattern), e.g. ``"com.myapp.product.<product:int>.update"``.
        :rtype: str
        )r@   rQ   s    r   r   zPattern.uri  s     yr   c                 <   g }i }| j         t          j        k    r||fS | j         t          j        k    ri| j                            |          }|r>| j        D ]2}|                    |          } | j        |         |          }|||<   3||fS t          d          dS )a-  
        Match the given (fully qualified) URI according to this pattern
        and return extracted args and kwargs.

        :param uri: The URI to match, e.g. ``"com.myapp.product.123456.update"``.
        :type uri: str

        :returns: A tuple ``(args, kwargs)``
        :rtype: tuple
        zno matchN)	r9   r   r?   r8   r=   r   r>   group
ValueError)rD   r   argskwargsr   keyvals          r   r   zPattern.match  s     :///<Z7444M'',,E -; & &C++c**C*$+c*3//C"%F3KKV|# ,,, 54r   c                 ,    | j         t          j        k    S )z
        Check if this pattern is for a procedure endpoint.

        :returns: ``True``, iff this pattern is for a procedure endpoint.
        :rtype: bool
        )rA   r   r,   rQ   s    r   is_endpointzPattern.is_endpoint/  s     |w:::r   c                 ,    | j         t          j        k    S )z
        Check if this pattern is for an event handler.

        :returns: ``True``, iff this pattern is for an event handler.
        :rtype: bool
        )rA   r   r-   rQ   s    r   
is_handlerzPattern.is_handler9  s     |w999r   c                 ,    | j         t          j        k    S )z
        Check if this pattern is for an exception.

        :returns: ``True``, iff this pattern is for an exception.
        :rtype: bool
        )rA   r   r.   rQ   s    r   is_exceptionzPattern.is_exceptionC  s     |w;;;r   NN) __name__
__module____qualname____doc__r,   r-   r.   r?   URI_TYPE_PREFIXr8   r;   r<   r7   r6   r1   r   r'   r   r   r   r   boolrO   r   propertyr"   rS   r   r   r]   r_   ra    r   r   r   r   Z   s       
 
 NORZ 9::N &2:&>?? &0RZ0Q%R%R" mq/3n( n(C n( n(xFVXgFg@h7i n(&tnn( n( n( n(`   X V   X V   V- - -4 ; ; V; : : V: < < V< < <r   r   r"   r#   c                       fd}|S )a  
    Decorator for WAMP procedure endpoints.

    :param uri:
    :type uri: str

    :param options:
    :type options: None or RegisterOptions

    :param check_types: Enable automatic type checking against (Python 3.5+) type hints
        specified on the ``endpoint`` callable. Types are checked at run-time on each
        invocation of the ``endpoint`` callable. When a type mismatch occurs, the error
        is forwarded to the callee code in ``onUserError`` override method of
        :class:`autobahn.wamp.protocol.ApplicationSession`. An error
        of type :class:`autobahn.wamp.exception.TypeCheckError` is also raised and
        returned to the caller (via the router).
    :type check_types: bool
    c                     t          |           sJ d                    | j                  }n}t          | d          sg | _        | j                            t          |t          j                             | S )Nz{}	_wampuris)callabler5   rc   hasattrrm   r4   r   r,   )freal_urir#   r"   r   s     r   decoratezregister.<locals>.decorateb  sy    {{{;{{1:..HHHq+&& 	AK	78W-H'S^__```r   rj   r   r"   r#   rr   s   ``` r   r	   r	   N  s/    (	 	 	 	 	 	 	 Or   c                       fd}|S )a  
    Decorator for WAMP event handlers.

    :param uri:
    :type uri: str

    :param options:
    :type options: None or SubscribeOptions

    :param check_types: Enable automatic type checking against (Python 3.5+) type hints
        specified on the ``endpoint`` callable. Types are checked at run-time on each
        invocation of the ``endpoint`` callable. When a type mismatch occurs, the error
        is forwarded to the callee code in ``onUserError`` override method of
        :class:`autobahn.wamp.protocol.ApplicationSession`. An error
        of type :class:`autobahn.wamp.exception.TypeCheckError` is also raised and
        returned to the caller (via the router).
    :type check_types: bool
    c                     t          |           sJ t          | d          sg | _        | j                            t	          t          j                             | S Nrm   )rn   ro   rm   r4   r   r-   )rp   r#   r"   r   s    r   rr   zsubscribe.<locals>.decorate  sY    {{{q+&& 	AK	73(BG[YYZZZr   rj   rs   s   ``` r   r
   r
   o  s/    (       Or   c                       fd}|S )z+
    Decorator for WAMP error classes.
    c                     t          | t                    sJ t          | d          sg | _        | j                            t          t
          j                             | S rv   )
issubclass	Exceptionro   rm   r4   r   r.   )clsr   s    r   rr   zerror.<locals>.decorate  sZ    #y))**)sK(( 	CMWS'*FGGHHH
r   rj   )r   rr   s   ` r   r   r     s#    
     Or   rb   )r;   typingr   r   autobahn.utilr   autobahn.wamp.typesr   r   __all__r   r   objectr   rh   r	   r
   r   rj   r   r   <module>r      s{  8 
			 " " " " " " " "             A A A A A A A A,S , , , ,^ p< p< p< p< p<f p< p< p<f  (3- (?*C YabfYg    @  8C= 84D+E [cdh[i    8 
s 
 
 
 
 
 
r   