
    8'h]-                         d dl mZ d dlZd dlZd dlmZ d dlmZmZ dZ	d Z
e G d de             Zedd	       Zedd
       Zed        Zy)    )absolute_importN)public)RegisterOptionsSubscribeOptions)Patternregister	subscribeerrorconvert_starred_uric                     t        |       t        j                  k(  sJ | j                  d      }|dk(  rd}| |fS |dk(  r| d   dk(  rd}| dd } | |fS d}| j	                  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six	text_typecountreplace)uri	cnt_starsmatchs      M/var/www/html/trade_iq/venv/lib/python3.12/site-packages/autobahn/wamp/uri.pyr   r   .   s    : 9%&%		$IA~ : 
aCGtO#2h : kk$$:    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	Zeed
               Zeed               Zed        Zd Zed        Zed        Zed        Zy)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]*)>$Nc                 @   t        |      t        j                  k(  sJ t        |      dkD  sJ |t        j
                  t        j                  t        j                  fv sJ |t        j
                  k(  r|?t        |      t        k(  s-J |t        j                  k(  r|t        |      t        k(  sJ d}|j                  d      }g }i }d}t        t        |            D ]  }||   }	t        j                  j                  |	      }
|
r|
j                         d   }|dvrt        d      |dk(  r|t        |      dz
  k7  rt        d      |
j                         d   }||v rt        d      |dv r
t         ||<   n|d	k(  r
t"        ||<   nt        d
      |j%                  dj'                  |             |dz  }t        j(                  j                  |	      }
|
rR|
j                         d   }||v rt        d      t         ||<   |j%                  dj'                  |             |dz  }Pt        j*                  j                  |	      }
|
r|j%                  |	       |	dk(  r!|dz  }|j%                  d       t         ||<   t        d       |rNt        j,                  | _        ddj1                  |      z   dz   }t3        j4                  |      | _        || _        n#t        j:                  | _        d| _        d| _        || _        || _        || _         y)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
        r   N.r   )stringintsuffixzinvalid URIr%   )r#   r%   r$   zlogic errorz(?P<{0}>[a-z0-9_]+)r   z([a-z0-9][a-z0-9_\-]*)^z\.$)!r   r   r   lenr   URI_TARGET_ENDPOINTURI_TARGET_HANDLERURI_TARGET_EXCEPTIONr   r   splitrange_URI_NAMED_CONVERTED_COMPONENTr   groups	Exceptionstrr$   appendformat_URI_NAMED_COMPONENT_URI_COMPONENTURI_TYPE_WILDCARD_typejoinrecompile_pattern_namesURI_TYPE_EXACT_uri_target_options)selfr   targetoptions
componentsplncgroup_counti	componentr   ctypenameps                 r   __init__zPattern.__init__   s    CyCMM)*)3x!||'55!44!668 8 	9 8 W000?d7m&FGFw111?d7m7G&GHGGYYs^
s:' 2	+A"1I::@@KEq) ;;#M22H$c*o.A)A#M22||~a(2:#M2200"BtHe^"BtH $M22		/66t<=q 0066yAE||~a(2:#M224		/66t<=q **00;E		)$Bq 		34"%;M**e2	+h  22DJejjn$s*AJJqMDMDK !//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
        )r@   rA   s    r   rC   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
        )r7   rO   s    r   uri_typezPattern.uri_type   s     zz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>   rO   s    r   r   zPattern.uri   s     yyr   c                 X   g }i }| j                   t        j                  k(  r||fS | j                   t        j                  k(  rh| j                  j                  |      }|r@| j                  D ]-  }|j                  |      } | j                  |   |      }|||<   / ||fS t        d      y)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)	r7   r   r=   r6   r;   r   r<   groupr0   )rA   r   argskwargsr   keyvals          r   r   zPattern.match  s     ::///<ZZ7444MM'',E;; &C++c*C*$++c*3/C"%F3K& V|#
++ 5r   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
        )r?   r   r)   rO   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
        )r?   r   r*   rO   s    r   
is_handlerzPattern.is_handler,  s     ||w9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
        )r?   r   r+   rO   s    r   is_exceptionzPattern.is_exception6  s     ||w;;;;r   N)__name__
__module____qualname____doc__r)   r*   r+   r=   URI_TYPE_PREFIXr6   r9   r:   r5   r4   r.   rM   r   propertyrC   rQ   r   r   rZ   r\   r^    r   r   r   r   ]   s   
 NORZZ 9:N &2::&>? &0RZZ0Q%R"^ @        ,4 ; ; : : < <r   r   c                       fd}|S )z
    Decorator for WAMP procedure endpoints.

    :param uri:
    :type uri: str

    :param options:
    :type options: None or RegisterOptions
    c                 H   t        |       sJ Ht        j                  rdj                  | j                        }ndj                  | j
                        }n}t        | d      sg | _        | j                  j                  t        |t        j                               | S )Nz{}	_wampuris)callabler   PY2r3   	func_namer`   hasattrri   r2   r   r)   )freal_urirC   r   s     r   decoratezregister.<locals>.decorateL  s{    {{;ww <<4 <<

3Hq+&AK	78W-H-H'RSr   rf   r   rC   rp   s   `` r   r   r   A  s     Or   c                       fd}|S )z
    Decorator for WAMP event handlers.

    :param uri:
    :type uri: str

    :param options:
    :type options: None or SubscribeOptions
    c                     t        |       sJ t        | d      sg | _        | j                  j                  t	        t        j
                               | S Nri   )rj   rm   ri   r2   r   r*   )rn   rC   r   s    r   rp   zsubscribe.<locals>.decorateg  sF    {{q+&AK	73(B(BGLMr   rf   rq   s   `` r   r	   r	   \  s     Or   c                       fd}|S )z+
    Decorator for WAMP error classes.
    c                     t        | t              sJ t        | d      sg | _        | j                  j	                  t        t
        j                               | S rt   )
issubclassr0   rm   ri   r2   r   r+   )clsr   s    r   rp   zerror.<locals>.decorateu  sH    #y)*)sK(CMWS'*F*FGH
r   rf   )r   rp   s   ` r   r
   r
   p  s    
 Or   r_   )
__future__r   r9   r   autobahn.utilr   autobahn.wamp.typesr   r   __all__r   objectr   r   r	   r
   rf   r   r   <module>r~      s~   8 ' 	 
   A,^ `<f `< `<F  4  & 
 
r   