o
    @Bi]-                     @   s   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d Z
eG dd	 d	eZedd
dZedddZedd ZdS )    )absolute_importN)public)RegisterOptionsSubscribeOptions)Patternregister	subscribeerrorconvert_starred_uric                 C   st   t | tjks	J | d}|dkrd}| |fS |dkr.| d dkr.d}| dd } | |fS 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six	text_typecountreplace)uri	cnt_starsmatch r   Q/var/www/html/Trade-python/venv/lib/python3.10/site-packages/autobahn/wamp/uri.pyr
   .   s   

r
   c                   @   s   e Zd ZdZdZdZdZdZdZdZ	e
dZ	 e
dZ	 e
dZ	 dd	d
Zeedd Zeedd Zedd Zdd Zedd Zedd Zed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]*)>$Nc                 C   sV  t |tjks	J t|dksJ |tjtjtjfv sJ |tjkr/|du s.t |tks.J n|tjkrA|du s@t |t	ks@J nd}|
d}g }i }d}tt|D ]}|| }	tj|	}
|
r|
 d }|dvrptd|dkr|t|d krtd|
 d }||v rtd|dv rt||< n|d	krt||< ntd
|d| |d7 }qTtj|	}
|
r|
 d }||v rtdt||< |d| |d7 }qTtj|	}
|
r||	 qT|	dkr|d7 }|d t||< qTtd|rtj| _dd| d }t|| _|| _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
        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pr   r   r   __init__   s   








zPattern.__init__c                 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<   r=   r   r   r   r?         	zPattern.optionsc                 C   rJ   )z
        Returns the URI type of this pattern

        :return:
        :rtype: Pattern.URI_TYPE_EXACT, Pattern.URI_TYPE_PREFIX or Pattern.URI_TYPE_WILDCARD
        )r3   rK   r   r   r   uri_type   rL   zPattern.uri_typec                 C   rJ   )z
        Returns the original URI (pattern) for this pattern.

        :returns: The URI (pattern), e.g. ``"com.myapp.product.<product:int>.update"``.
        :rtype: str
        )r:   rK   r   r   r   r      s   zPattern.uric                 C   sx   g }i }| j tjkr||fS | j tjkr:| j|}|r6| jD ]}||}| j| |}|||< q||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)	r3   r   r9   r2   r7   r   r8   groupr,   )r=   r   argskwargsr   keyvalr   r   r   r     s   


zPattern.matchc                 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%   rK   r   r   r   is_endpoint"     zPattern.is_endpointc                 C   rS   )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&   rK   r   r   r   
is_handler,  rU   zPattern.is_handlerc                 C   rS   )z
        Check if this pattern is for an exception.

        :returns: ``True``, iff this pattern is for an exception.
        :rtype: bool
        )r;   r   r'   rK   r   r   r   is_exception6  rU   zPattern.is_exceptionN)__name__
__module____qualname____doc__r%   r&   r'   r9   URI_TYPE_PREFIXr2   r5   r6   r1   r0   r*   rI   r   propertyr?   rM   r   r   rT   rV   rW   r   r   r   r   r   ]   s<    



`		
	
	
	r   c                        fdd}|S )z
    Decorator for WAMP procedure endpoints.

    :param uri:
    :type uri: str

    :param options:
    :type options: None or RegisterOptions
    c                    sd   t | sJ d u rtjrd| j}n	d| j}n}t| ds%g | _| jt	|t	j
  | S )Nz{}	_wampuris)callabler   PY2r/   	func_namerY   hasattrr`   r.   r   r%   )freal_urir?   r   r   r   decorateL  s   
zregister.<locals>.decorater   r   r?   rh   r   rg   r   r   A  s   r   c                    r_   )z
    Decorator for WAMP event handlers.

    :param uri:
    :type uri: str

    :param options:
    :type options: None or SubscribeOptions
    c                    s6   t | sJ t| dsg | _| jttj  | S Nr`   )ra   rd   r`   r.   r   r&   )re   rg   r   r   rh   g  s
   
zsubscribe.<locals>.decorater   ri   r   rg   r   r   \  s   r   c                    s    fdd}|S )z+
    Decorator for WAMP error classes.
    c                    s6   t | tsJ t| dsg | _| jt tj | S rj   )
issubclassr,   rd   r`   r.   r   r'   )clsr   r   r   rh   u  s
   
zerror.<locals>.decorater   )r   rh   r   rm   r   r	   p  s   r	   rX   )
__future__r   r5   r   autobahn.utilr   autobahn.wamp.typesr   r   __all__r
   objectr   r   r   r	   r   r   r   r   <module>   s    	/ d