U
    •uÄc‘5  ã                   @   s¸   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	e
dœdd„ZeG d	d
„ d
eƒƒZedee
 ee ee dœdd„ƒZedee
 ee ee dœdd„ƒZee
dœdd„ƒZdS )é    N)ÚOptionalÚUnion)Úpublic)ÚRegisterOptionsÚSubscribeOptions)ÚPatternÚregisterÚ	subscribeÚerrorÚconvert_starred_uri©Úuric                 C   sf   t | ƒtkst‚|  d¡}|dkr(d}n6|dkrN| d dkrNd}| 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é   éÿÿÿÿÚprefixNZwildcardÚ )ÚtypeÚstrÚAssertionErrorÚcountÚreplace)r   Z	cnt_starsÚmatch© r   úT/var/www/html/VPFITNESS/school/venv/lib/python3.8/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eeeeeef  ee 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]*)>$N)r   ÚtargetÚoptionsÚcheck_typesc                 C   st  t |ƒtkst‚t|ƒdks t‚|tjtjtjfks8t‚|tjkr\|dks„t |ƒtks„t‚n(|tjkr€|dks„t |ƒt	ks„t‚nd}| 
d¡}d}g }i }d}	tt|ƒƒD �]b}
||
 }tj |¡}|�rh| ¡ \}}|dkrætdƒ‚|dk�r
|
t|ƒd k�r
tdƒ‚||k�rtdƒ‚|d	k�r0t||< n|d
k�rDt||< ntdƒ‚| d ||¡¡ |	d7 }	qªtj |¡}|�r¼| ¡ d }||k�r˜tdƒ‚t||< | d ||¡¡ |	d7 }	qªtj |¡}|�rÚ| |¡ qª|dk�r|	d7 }	| d |¡¡ t||	< qªtdƒ‚qª|�rDt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

        :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   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    Ú
componentsZ_URI_COMP_CHARSÚplZncZgroup_countÚiZ	componentr   ÚnameZ	comp_typeÚpr   r   r   Ú__init__…   s„    þ












zPattern.__init__c                 C   s   | 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   õ   s    	zPattern.optionsc                 C   s   | 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
        )r5   rG   r   r   r   Úuri_type   s    	zPattern.uri_typec                 C   s   | 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<   rG   r   r   r   r     s    zPattern.uric                 C   sx   g }i }| j tjkr||fS | j tjkrt| j |¡}|rl| 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)	r5   r   r;   r4   r9   r   r:   ÚgroupÚ
ValueError)r@   r   ÚargsÚkwargsr   ÚkeyÚvalr   r   r   r     s    


zPattern.matchc                 C   s   | 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(   rG   r   r   r   Úis_endpoint/  s    zPattern.is_endpointc                 C   s   | 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)   rG   r   r   r   Ú
is_handler9  s    zPattern.is_handlerc                 C   s   | 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*   rG   r   r   r   Úis_exceptionC  s    zPattern.is_exception)NN) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r(   r)   r*   r;   ZURI_TYPE_PREFIXr4   r7   r8   r3   r2   r-   r   r#   r   r   r   r   ÚboolrF   r   Úpropertyr   rH   r   r   rO   rP   rQ   r   r   r   r   r   Z   s<   


  ÿÿp		
	
	
	r   )r   r   r    c                    s   ‡ ‡‡fd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                    sR   t | ƒst‚ˆd kr"d | j¡}nˆ}t| dƒs6g | _| j t|tjˆˆ ƒ¡ | S )Nz{}Ú	_wampuris)	Úcallabler   r1   rR   ÚhasattrrX   r0   r   r(   )ÚfZreal_uri©r    r   r   r   r   Údecorateb  s    
zregister.<locals>.decorater   ©r   r   r    r]   r   r\   r   r   N  s    
r   c                    s   ‡ ‡‡fd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                    s8   t | ƒst‚t| dƒsg | _| j tˆtjˆˆ ƒ¡ | S ©NrX   )rY   r   rZ   rX   r0   r   r)   )r[   r\   r   r   r]   ƒ  s
    
zsubscribe.<locals>.decorater   r^   r   r\   r   r	   o  s    r	   c                    s   ‡ fdd„}|S )z+
    Decorator for WAMP error classes.
    c                    s6   t | tƒst‚t| dƒsg | _| j tˆ tjƒ¡ | S r_   )Ú
issubclassÚ	Exceptionr   rZ   rX   r0   r   r*   )Úclsr   r   r   r]   ‘  s
    
zerror.<locals>.decorater   )r   r]   r   r   r   r
   Œ  s    r
   )NN)NN)r7   Útypingr   r   Zautobahn.utilr   Zautobahn.wamp.typesr   r   Ú__all__r   r   Úobjectr   rV   r   r	   r
   r   r   r   r   Ú<module>   s   	/ t" "