o
    >hRC                    @   s  d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl	Z	d dl
mZ d dlmZmZ d dlmZ zd dlZd dlZd dlmZ W n eyO   dZY nw d	Zd
Ze dZe dZe dZe dZe dZe dZe dZe dZ e dZ!e dZ"e dZ#dZ$dZ%dZ&e$e%e&gZ'g dZ(d Z)dZ*dZ+dZ,e)de*de+de,diZ-dd e-. D Z/d Z0dZ1dZ2dZ3d Z4d!Z5d"Z6e0de1d#e2d$e3d%e4d&e5d'e6d(iZ7d)d e7. D Z8d*d+ Z9d,d- Z:dyd/d0Z;d1ed2ee< fd3d4Z=			dzd1ed6e<d7e>d8e>d9e>d:e>d2e<fd;d<Z?d{d=d>Z@d|d1ed6e<d2eAfd?d@ZBd|d1ed6e<d2ee<ef fdAdBZCd|dCdDZDG dEdF dFeEZFG dGdH dHeFZGG dIdJ dJeFZHG dKdL dLeFZIG dMdN dNeFZJG dOdP dPeFZKG dQdR dReFZLG dSdT dTeFZMG dUdV dVeFZNG dWdX dXeFZOG dYdZ dZeFZPG d[d\ d\eFZQG d]d^ d^eFZRG d_d` d`eFZSG dadb dbeFZTG dcdd ddeFZUG dedf dfeFZVG dgdh dheFZWG didj djeFZXG dkdl dleFZYG dmdn dneFZZG dodp dpeFZ[G dqdr dreFZ\G dsdt dteFZ]G dudv dveFZ^G dwdx dxeFZ_dS )}    N)pformat)AnyDictOptional)hlval)ProtocolErrorInvalidUriError)ROLE_NAME_TO_CLASS)message_fbsFT)#MessageHelloWelcomeAbort	ChallengeAuthenticateGoodbyeErrorPublish	Published	Subscribe
SubscribedUnsubscribeUnsubscribedEventCallCancelResultRegister
Registered
UnregisterUnregistered
Invocation	InterruptYieldcheck_or_raise_uricheck_or_raise_realm_namecheck_or_raise_idcheck_or_raise_extrais_valid_enc_algois_valid_enc_serializeridentify_realm_name_categoryPAYLOAD_ENC_CRYPTO_BOXPAYLOAD_ENC_MQTT PAYLOAD_ENC_STANDARD_IDENTIFIERSz!^[A-Za-z][A-Za-z\d_\-@\.]{2,254}$z^0x([A-Fa-f\d]{40})$z^([a-z\d_\-@\.]{2,250})\.eth$z^eth\.([a-z\d_\-@\.]{2,250})$z!^(([\da-z_]+\.)|\.)*([\da-z_]+)?$z!^(([^\s\.#]+\.)|\.)*([^\s\.#]+)?$z^([\da-z_]+\.)*([\da-z_]+)$z^([^\s\.#]+\.)*([^\s\.#]+)$z^([\da-z_]+\.)*([\da-z_]*)$z^([^\s\.#]+\.)*([^\s\.#]*)$z^x_([a-z][\da-z_]+)?$	cryptoboxmqttxbr)jsonmsgpackcborubjsonflatbuffers         nullc                 C      i | ]\}}||qS  r;   .0valuekeyr;   r;   u/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/wamp/message.py
<dictcomp>       rA            r1   r2   r3   r4   opaquer5   c                 C   r:   r;   r;   r<   r;   r;   r@   rA      rB   c                 C      t | tko| tv pt| S )a'  
    For WAMP payload transparency mode, check if the provided ``enc_algo``
    identifier in the WAMP message is a valid one.

    Currently defined standard identifiers are:

    * ``"cryptobox"``
    * ``"mqtt"``
    * ``"xbr"``

    Users can select arbitrary identifiers too, but these MUST start with ``"x_"``.

    :param enc_algo: The payload transparency algorithm identifier to check.
    :type enc_algo: str

    :returns: Returns ``True`` if and only if the payload transparency
        algorithm identifier is valid.
    :rtype: bool
    )typestrr-   _CUSTOM_ATTRIBUTEmatch)enc_algor;   r;   r@   r(      s   r(   c                 C   rG   )am  
    For WAMP payload transparency mode, check if the provided ``enc_serializer``
    identifier in the WAMP message is a valid one.

    Currently, the only standard defined identifier are

    * ``"json"``
    * ``"msgpack"``
    * ``"cbor"``
    * ``"ubjson"``
    * ``"flatbuffers"``

    Users can select arbitrary identifiers too, but these MUST start with ``"x_"``.

    :param enc_serializer: The payload transparency serializer identifier to check.
    :type enc_serializer: str

    :returns: Returns ``True`` if and only if the payload transparency
        serializer identifier is valid.
    :rtype: bool
    )rH   rI    PAYLOAD_ENC_STANDARD_SERIALIZERSrJ   rK   )enc_serializerr;   r;   r@   r)      s   r)   (   c                 C   sh   t | tkr	| }nt | tkrt| d}n| d u rd}nd| }t||kr2|d | d S |S )Nascii-z{}z..)rH   rI   bytesbinasciib2a_hexdecodeformatlen)datamax_lensr;   r;   r@   b2a   s   
r[   r>   returnc                 C   sL   t | tkrdS t| rt| rdS t| rdS dS t| r$dS dS )az  
    Identify the real name category of the given value:

    * ``"standalone"``: A normal, standalone WAMP realm name, e.g. ``"realm1"``.
    * ``"eth"``: An Ethereum address, e.g. ``"0xe59C7418403CF1D973485B36660728a5f4A8fF9c"``.
    * ``"ens"``: An Ethereum ENS name, e.g. ``"wamp-proto.eth"``.
    * ``"reverse_ens"``: An Ethereum ENS name in reverse notation, e.g. ``"eth.wamp-proto"``.
    * ``None``: The value is not a WAMP realm name.

    :param value: The value for which to identify realm name category.
    :return: The category identified, one of ``["standalone", "eth", "ens", "reverse-ens"]``
        or ``None``.
    Nensreverse_ens
standaloneeth)rH   rI   _URI_PAT_REALM_NAMErK   _URI_PAT_REALM_NAME_ENS_URI_PAT_REALM_NAME_ENS_REVERSE_URI_PAT_REALM_NAME_ETH)r>   r;   r;   r@   r*      s   



r*   WAMP message invalidmessagestrictallow_empty_componentsallow_last_empty
allow_nonec              
   C   s   | du r|rdS t d|t| tkr%| du r|s%t d|t| |r4|r,t}n|r1t}nt}n|r9t}n|r>t}nt	}|
| sSt d|| |j||||| S )a^  
    Check a value for being a valid WAMP URI.

    If the value is not a valid WAMP URI is invalid, raises :class:`autobahn.wamp.exception.InvalidUriError`,
    otherwise returns the value.

    :param value: The value to check.
    :param message: Prefix for message in exception raised when value is invalid.
    :param strict: If ``True``, do a strict check on the URI (the WAMP spec SHOULD behavior).
    :param allow_empty_components: If ``True``, allow empty URI components (for pattern based
       subscriptions and registrations).
    :param allow_last_empty: If ``True``, allow the last URI component to be empty (for prefix based
       subscriptions and registrations).
    :param allow_none: If ``True``, allow ``None`` for URIs.
    :returns: The URI value (if valid).
    :raises: instance of :class:`autobahn.wamp.exception.InvalidUriError`
    Nz{0}: URI cannot be nullz{0}: invalid type {1} for URIz{0}: invalid value "{1}" for URI (did not match pattern "{2}" with options strict={3}, allow_empty_components={4}, allow_last_empty={5}, allow_none={6}))r   rV   rH   rI   _URI_PAT_STRICT_LAST_EMPTY_URI_PAT_STRICT_EMPTY_URI_PAT_STRICT_NON_EMPTY_URI_PAT_LOOSE_LAST_EMPTY_URI_PAT_LOOSE_EMPTY_URI_PAT_LOOSE_NON_EMPTYrK   pattern)r>   rf   rg   rh   ri   rj   patr;   r;   r@   r$     s*   
r$   c                 C   s   | du rt d|t| tkrt d|t| |r5t| s't| r)| S t d|| tjtjt| r<| S t d|| tj)a|  
    Check a value for being a valid WAMP URI.

    If the value is not a valid WAMP URI is invalid, raises :class:`autobahn.wamp.exception.InvalidUriError`,
    otherwise returns the value.

    :param value: The value to check, e.g. ``"realm1"`` or ``"com.example.myapp"`` or ``"eth.example"``.
    :param message: Prefix for message in exception raised when value is invalid.
    :param allow_eth: If ``True``, allow Ethereum addresses as realm names,
        e.g. ``"0xe59C7418403CF1D973485B36660728a5f4A8fF9c"``.
    :returns: The URI value (if valid).
    :raises: instance of :class:`autobahn.wamp.exception.InvalidUriError`
    Nz{0}: realm name cannot be nullz${0}: invalid type {1} for realm namezO{0}: invalid value "{1}" for realm name (did not match patterns "{2}" or "{3}")zE{0}: invalid value "{1}" for realm name (did not match pattern "{2}"))r   rV   rH   rI   ra   rK   rd   rq   )r>   rf   	allow_ethr;   r;   r@   r%   7  s,   
r%   c                 C   sD   t | tkrtd|t | | dk s| dkr td|| | S )a  
    Check a value for being a valid WAMP ID.

    If the value is not a valid WAMP ID, raises :class:`autobahn.wamp.exception.ProtocolError`,
    otherwise return the value.

    :param value: The value to check.
    :param message: Prefix for message in exception raised when value is invalid.
    :returns: The ID value (if valid).
    :raises: instance of :class:`autobahn.wamp.exception.ProtocolError`
    z{0}: invalid type {1} for IDr   l          z{0}: invalid value {1} for ID)rH   intr   rV   )r>   rf   r;   r;   r@   r&   ^  s
   r&   c                 C   sR   t | tkrtd|t | |  D ]}t|ts&td|t ||q| S )a  
    Check a value for being a valid WAMP extra dictionary.

    If the value is not a valid WAMP extra dictionary, raises :class:`autobahn.wamp.exception.ProtocolError`,
    otherwise return the value.

    :param value: The value to check.
    :param message: Prefix for message in exception raised when value is invalid.
    :returns: The extra dictionary (if valid).
    :raises: instance of :class:`autobahn.wamp.exception.ProtocolError`
    z${0}: invalid type {1} for WAMP extraz3{0}: invalid type {1} for key in WAMP extra ('{2}')rH   dictr   rV   keys
isinstancerI   )r>   rf   kr;   r;   r@   r'   s  s   
r'   c                 C   s^   | dur-t | tkrtd|t | |  D ]}t|ts*td|t ||q| S dS )a*  
    Check a value for being a valid WAMP kwargs dictionary.

    If the value is not a valid WAMP kwargs dictionary,
    raises :class:`autobahn.wamp.exception.ProtocolError`.
    Otherwise return the kwargs.

    The WAMP spec requires that the keys in kwargs are proper
    strings (unicode), not bytes. Note that the WAMP spec
    says nothing about keys in application payload. Key in the
    latter can be potentially of other type (if that is really
    wanted).

    :param kwargs: The keyword arguments to check.
    :type kwargs: dict

    :param message: Prefix for message in exception raised when
        value is invalid.
    :type message: str

    :returns: The kwargs dictionary (if valid).
    :rtype: dict

    :raises: instance of
        :class:`autobahn.wamp.exception.ProtocolError`
    Nz%{0}: invalid type {1} for WAMP kwargsz4{0}: invalid type {1} for key in WAMP kwargs ('{2}')ru   )kwargsrf   ry   r;   r;   r@   _validate_kwargs  s   
r{   c                   @   s   e Zd ZdZdZ	 dZd%ddZedd Zej	dd Zed	d
 Z
e
j	dd
 Z
edd Zej	dd Zedd Zej	dd Zdd Zdd ZdefddZedd Zdd Zedd Zdd  Zd!d" Zd#d$ ZdS )&r   zo
    WAMP message base class.

    .. note:: This is not supposed to be instantiated, but subclassed only.
    N	_from_fbs_serialized_correlation_id_correlation_uri_correlation_is_anchor_correlation_is_last_router_internalc                 C   s.   || _ i | _d | _d | _d | _d | _d | _d S Nr|   )selffrom_fbsr;   r;   r@   __init__  s   
zMessage.__init__c                 C      | j S r   )r   r   r;   r;   r@   correlation_id     zMessage.correlation_idc                 C   "   |d u st |tksJ || _d S r   )rH   rI   r   r   r>   r;   r;   r@   r        
c                 C   r   r   )r   r   r;   r;   r@   correlation_uri  r   zMessage.correlation_uric                 C   r   r   )rH   rI   r   r   r;   r;   r@   r     r   c                 C   r   r   )r   r   r;   r;   r@   correlation_is_anchor  r   zMessage.correlation_is_anchorc                 C   r   r   )rH   boolr   r   r;   r;   r@   r     r   c                 C   r   r   )r   r   r;   r;   r@   correlation_is_last  r   zMessage.correlation_is_lastc                 C   r   r   )rH   r   r   r   r;   r;   r@   r     r   c                 C   sL   t || jsdS | jD ]}|dvr#|ds#t| |t||ks# dS qdS )z
        Compare this message to another message for equality.

        :param other: The other message to compare with.
        :type other: obj

        :returns: ``True`` iff the messages are equal.
        :rtype: bool
        F)r~   r   r   r   r   _T)rx   	__class__	__slots__
startswithgetattr)r   otherry   r;   r;   r@   __eq__  s   

zMessage.__eq__c                 C      |  | S )z
        Compare this message to another message for inequality.

        :param other: The other message to compare with.
        :type other: obj

        :returns: ``True`` iff the messages are not equal.
        :rtype: bool
        r   r   r   r;   r;   r@   __ne__  s   
zMessage.__ne__r\   c              	   C   s<   d t| jj d dddttt|  ddddS )Nz{}
{}z::blueT)colorboldz    F)	rV   r   r   __name__uppertextwrapindentr   marshalr   r;   r;   r@   __str__  s   zMessage.__str__c                 C      t  )a   
        Factory method that parses a unserialized raw message (as returned byte
        :func:`autobahn.interfaces.ISerializer.unserialize`) into an instance
        of this class.

        :returns: An instance of this class.
        :rtype: obj
        NotImplementedError)wmsgr;   r;   r@   parse  s   
zMessage.parsec                 C   r   r   r   r   r;   r;   r@   r   )     zMessage.marshalc                 C   r   r   r   bufr;   r;   r@   cast,  r   zMessage.castc                 C   r   r   r   )r   builderr;   r;   r@   build0  r   zMessage.buildc                 C   s
   i | _ dS )z1
        Resets the serialization cache.
        N)r~   r   r;   r;   r@   uncache3  s   
zMessage.uncachec                 C   sh   || j vr/|jdkr%td}| |}|| | }t|| j |< n
|| 	 | j |< | j | S )a  
        Serialize this object into a wire level bytes representation and cache
        the resulting bytes. If the cache already contains an entry for the given
        serializer, return the cached representation directly.

        :param serializer: The wire level serializer to use.
        :type serializer: An instance that implements :class:`autobahn.interfaces.ISerializer`

        :returns: The serialized bytes.
        :rtype: bytes
        r5   i   )
r~   NAMEr5   Builderr   FinishOutputrR   	serializer   )r   
serializerr   objr   r;   r;   r@   r   9  s   





zMessage.serializer   )r   
__module____qualname____doc__MESSAGE_TYPEr   r   propertyr   setterr   r   r   r   r   rI   r   staticmethodr   r   r   r   r   r   r;   r;   r;   r@   r     sB    










r   c                   @   sF   e Zd ZdZdZ	 dZ							dddZedd Zd	d
 Z	dS )r   zU
    A WAMP ``HELLO`` message.

    Format: ``[HELLO, Realm|uri, Details|dict]``
    r6   )	realmrolesauthmethodsauthidauthrole	authextra	resumableresume_sessionresume_tokenNc
                 C   sj  |du st |tsJ t|tksJ t|dksJ |D ]}
|
dv s%J t ||
 tjjj|
 s3J q|rKt|t	ks>J |D ]
}t|tksJJ q@|du sWt|tksWJ |du sct|tkscJ |du sot|tksoJ |du s{t|t
ks{J |du st|tksJ |	du st|	tksJ t|  || _|| _|| _|| _|| _|| _|| _|| _|	| _dS )a  

        :param realm: The URI of the WAMP realm to join.
        :type realm: str

        :param roles: The WAMP session roles and features to announce.
        :type roles: dict of :class:`autobahn.wamp.role.RoleFeatures`

        :param authmethods: The authentication methods to announce.
        :type authmethods: list of str or None

        :param authid: The authentication ID to announce.
        :type authid: str or None

        :param authrole: The authentication role to announce.
        :type authrole: str or None

        :param authextra: Application-specific "extra data" to be forwarded to the client.
        :type authextra: dict or None

        :param resumable: Whether the client wants this to be a session that can be later resumed.
        :type resumable: bool or None

        :param resume_session: The session the client would like to resume.
        :type resume_session: int or None

        :param resume_token: The secure authorisation token to resume the session.
        :type resume_token: str or None
        Nr   
subscriber	publishercallercallee)rx   rI   rH   rv   rW   autobahnwamproler	   listr   rt   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   
authmethodr;   r;   r@   r   r  s4   '

zHello.__init__c              
   C   s  t | dkr| d tjksJ t | dkrtdt | t| d ddd}t| d d	}i }d
|vr8tdt|d
 d}t |dkrItd|D ]:}|dvrXtd|t| }t|| d|}d|v r~t|d d| |d$i |d }n| }|||< qKd}	d|v r|d }
t|
t	krtdt|
|
D ]}t|t
krtdt|q|
}	d}d|v r|d }t|t
krtdt||}d}d|v r|d }t|t
krtdt||}d}d|v r|d }t|tkrtdt||}d}d|v r#|d }t|tkr#tdt|d}d|v r>|d }t|tkr>td t|d}d!|v rZ|d! }t|t
krYtd"t|n|ratd#t|||	||||||	}|S )%
        Verifies and parses an unserialized raw message into an actual WAMP message instance.

        :param wmsg: The unserialized raw message.
        :type wmsg: list

        :returns: An instance of this class.
        r   r8   z$invalid message length {0} for HELLOr6   z'realm' in HELLOT)rj   r7   z'details' in HELLOr   z5missing mandatory roles attribute in options in HELLOz'roles' in 'details' in HELLOz#empty 'roles' in 'details' in HELLOr   z3invalid role '{0}' in 'roles' in 'details' in HELLOz+role '{0}' in 'roles' in 'details' in HELLOfeaturesz9'features' in role '{0}' in 'roles' in 'details' in HELLONr   z2invalid type {0} for 'authmethods' detail in HELLOz:invalid type {0} for item in 'authmethods' detail in HELLOr   z-invalid type {0} for 'authid' detail in HELLOr   z/invalid type {0} for 'authrole' detail in HELLOr   z0invalid type {0} for 'authextra' detail in HELLOr   z0invalid type {0} for 'resumable' detail in HELLOresume-sessionz5invalid type {0} for 'resume-session' detail in HELLOresume-tokenz3invalid type {0} for 'resume-token' detail in HELLOzDresume-token must be provided if resume-session is provided in HELLOr;   )rW   r   r   r   rV   r$   r'   r	   rH   r   rI   rv   r   rt   )r   r   detailsr   details_rolesr   role_clsdetails_rolerole_featuresr   details_authmethodsauth_methodr   details_authidr   details_authroler   details_authextrar   r   r   r   r;   r;   r@   r     s   




zHello.parsec                 C   s,  di i}| j  D ]?}i |d |j< |jD ]2}|dsG|dkrGt||durGd|d |j vr9di i|d |j< t|||d |j d |< qq	| jdurS| j|d< | jdur]| j|d< | jdurg| j|d< | j	durq| j	|d	< | j
dur{| j
|d
< | jdur| j|d< | jdur| j|d< tj| j|gS )
        Marshal this object into a raw message for subsequent serialization to bytes.

        :returns: The serialized raw message.
        :rtype: list
        r   r   ROLENr   r   r   r   r   r   r   r   )r   valuesr   __dict__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   featurer;   r;   r@   r   !  s2   
 













zHello.marshal)NNNNNNN
r   r   r   r   r   r   r   r   r   r   r;   r;   r;   r@   r   Z  s     
C
kr   c                   @   L   e Zd ZdZdZ	 dZ										dddZedd Zd	d
 Z	dS )r   zZ
    A WAMP ``WELCOME`` message.

    Format: ``[WELCOME, Session|id, Details|dict]``
    r7   )sessionr   r   r   r   r   authproviderr   resumedr   r   customNc                 C   s  t |tksJ t |tksJ t|dksJ |D ]}|dv s"J t|| tjjj| s0J q|du s=t |t	ks=J |du sIt |t	ksIJ |du sUt |t	ksUJ |du sat |t	ksaJ |du smt |t	ksmJ |du syt |tksyJ |	du st |	t
ksJ |
du st |
t
ksJ |du st |t	ksJ |du st |tksJ |r|D ]	}t|sJ qt|  || _|| _|| _|| _|| _|| _|| _|| _|	| _|
| _|| _|pi | _dS )a0  

        :param session: The WAMP session ID the other peer is assigned.
        :type session: int

        :param roles: The WAMP roles to announce.
        :type roles: dict of :class:`autobahn.wamp.role.RoleFeatures`

        :param realm: The effective realm the session is joined on.
        :type realm: str or None

        :param authid: The authentication ID assigned.
        :type authid: str or None

        :param authrole: The authentication role assigned.
        :type authrole: str or None

        :param authmethod: The authentication method in use.
        :type authmethod: str or None

        :param authprovider: The authentication provided in use.
        :type authprovider: str or None

        :param authextra: Application-specific "extra data" to be forwarded to the client.
        :type authextra: arbitrary or None

        :param resumed: Whether the session is a resumed one.
        :type resumed: bool or None

        :param resumable: Whether this session can be resumed later.
        :type resumable: bool or None

        :param resume_token: The secure authorisation token to resume the session.
        :type resume_token: str or None

        :param custom: Implementation-specific "custom attributes" (`x_my_impl_attribute`) to be set.
        :type custom: dict or None
        r   brokerdealerN)rH   rt   rv   rW   rx   r   r   r   r	   rI   r   rJ   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   ry   r;   r;   r@   r   d  s@   3
zWelcome.__init__c                 C   sB  t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}|dd	}|d
d	}|dd	}|dd	}|dd	}|dd	}d	}	d|v ri|d }	t|	t	ksitdt|	d	}
d|v r|d }
t|
t	kstdt|
d	}d|v r|d }t|t
kstdt|n|
rtdi }d|vrtdt|d d}t |dkrtd|D ]<}|dvrtd|t| }t|| d|}d|v rt|d d| |di || d }n| }|||< qi }|D ]}t|r|| ||< q t|||||||||	|
||}|S ) r   r   r8   z&invalid message length {0} for WELCOMEr6   z'session' in WELCOMEr7   z'details' in WELCOMEr   Nr   r   r   r   r   r   z0invalid type {0} for 'resumed' detail in WELCOMEr   z2invalid type {0} for 'resumable' detail in WELCOMEr   z5invalid type {0} for 'resume_token' detail in WELCOMEz8resume_token required when resumable is given in WELCOMEr   z7missing mandatory roles attribute in options in WELCOMEz'roles' in 'details' in WELCOMEz%empty 'roles' in 'details' in WELCOMEr   z5invalid role '{0}' in 'roles' in 'details' in WELCOMEz-role '{0}' in 'roles' in 'details' in WELCOMEr   z;'features' in role '{0}' in 'roles' in 'details' in WELCOMEr;   )rW   r   r   r   rV   r&   r'   getrH   r   rI   r	   rJ   rK   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ry   r   r;   r;   r@   r     sh   
zWelcome.parsec                 C   s@  i }| | j | jr| j|d< | jr| j|d< | jr | j|d< | jr(| j|d< | jr0| j|d< | jr8| j|d< | jr@| j|d< | j	rH| j	|d< | j
rP| j
|d	< i |d
< | j D ]?}i |d
 |j< |jD ]2}|ds|dkrt||durd|d
 |j vrdi i|d
 |j< t|||d
 |j d |< qeqYtj| j|gS )r   r   r   r   r   r   r   r   r   r   r   r   r   Nr   )updater   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r;   r@   r     s>   









 zWelcome.marshal
NNNNNNNNNNr   r;   r;   r;   r@   r   I  s&    
U
Sr   c                   @   8   e Zd ZdZdZ	 dZdddZedd Zd	d
 Z	dS )r   zV
    A WAMP ``ABORT`` message.

    Format: ``[ABORT, Details|dict, Reason|uri]``
    r8   )reasonrf   Nc                 C   sB   t |tksJ |du st |tksJ t|  || _|| _dS )z

        :param reason: WAMP or application error URI for aborting reason.
        :type reason: str

        :param message: Optional human-readable closing message, e.g. for logging purposes.
        :type message: str or None
        N)rH   rI   r   r   r   rf   )r   r   rf   r;   r;   r@   r   O  s
   	

zAbort.__init__c                 C   s   t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}d}d	|v rG|d	 }t|tkrEtd
t||}t||}|S )r   r   r8   z$invalid message length {0} for ABORTr6   z'details' in ABORTr7   z'reason' in ABORTNrf   z.invalid type {0} for 'message' detail in ABORT)	rW   r   r   r   rV   r'   r$   rH   rI   )r   r   r   rf   details_messager   r;   r;   r@   r   _  s   
zAbort.parsec                 C   s"   i }| j r
| j |d< tj|| jgS )r   rf   )rf   r   r   r   r   r   r;   r;   r@   r     s   
zAbort.marshalr   r   r;   r;   r;   r@   r   >  s    

 r   c                   @   r   )r   z_
    A WAMP ``CHALLENGE`` message.

    Format: ``[CHALLENGE, Method|string, Extra|dict]``
    rC   )methodextraNc                 C   F   t |tksJ |du st |tksJ t|  || _|pi | _dS )z

        :param method: The authentication method.
        :type method: str

        :param extra: Authentication method specific information.
        :type extra: dict or None
        N)rH   rI   rv   r   r   r   r   )r   r   r   r;   r;   r@   r     
   	
zChallenge.__init__c                 C   ~   t | dkr| d tjksJ t | dkrtdt | | d }t|tkr1tdt|t| d d}t||}|S )r   r   r8   z(invalid message length {0} for CHALLENGEr6   z*invalid type {0} for 'method' in CHALLENGEr7   z'extra' in CHALLENGE)rW   r   r   r   rV   rH   rI   r'   )r   r   r   r   r;   r;   r@   r        
zChallenge.parsec                 C      t j| j| jgS r   )r   r   r   r   r   r;   r;   r@   r        zChallenge.marshalr   r   r;   r;   r;   r@   r         

r   c                   @   r   )r   zh
    A WAMP ``AUTHENTICATE`` message.

    Format: ``[AUTHENTICATE, Signature|string, Extra|dict]``
    rD   )	signaturer   Nc                 C   r   )z

        :param signature: The signature for the authentication challenge.
        :type signature: str

        :param extra: Authentication method specific information.
        :type extra: dict or None
        N)rH   rI   rv   r   r   r  r   )r   r  r   r;   r;   r@   r     r   zAuthenticate.__init__c                 C   r   )r   r   r8   z+invalid message length {0} for AUTHENTICATEr6   z0invalid type {0} for 'signature' in AUTHENTICATEr7   z'extra' in AUTHENTICATE)rW   r   r   r   rV   rH   rI   r'   )r   r  r   r   r;   r;   r@   r     r   zAuthenticate.parsec                 C   r   r   )r   r   r  r   r   r;   r;   r@   r     r   zAuthenticate.marshalr   r   r;   r;   r;   r@   r     r  r   c                   @   sD   e Zd ZdZdZ	 dZ	 dZeddfddZedd	 Z	d
d Z
dS )r   zZ
    A WAMP ``GOODBYE`` message.

    Format: ``[GOODBYE, Details|dict, Reason|uri]``
    rE   zwamp.close.normalr   rf   r   Nc                 C   s`   t |tksJ |du st |tksJ |du s t |tks J t|  || _|| _|| _dS )a  

        :param reason: Optional WAMP or application error URI for closing reason.
        :type reason: str

        :param message: Optional human-readable closing message, e.g. for logging purposes.
        :type message: str or None

        :param resumable: From the server: Whether the session is able to be resumed (true) or destroyed (false). From the client: Whether it should be resumable (true) or destroyed (false).
        :type resumable: bool or None
        N)rH   rI   r   r   r   r   rf   r   )r   r   rf   r   r;   r;   r@   r   /  s   

zGoodbye.__init__c                 C   s   t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}d}d}d	|v rI|d	 }t|tkrGtd
t||}d|v r`|d }t|t	kr`tdt|t|||d}|S )r   r   r8   z&invalid message length {0} for GOODBYEr6   z'details' in GOODBYEr7   z'reason' in GOODBYENrf   z0invalid type {0} for 'message' detail in GOODBYEr   z2invalid type {0} for 'resumable' detail in GOODBYEr  )
rW   r   r   r   rV   r'   r$   rH   rI   r   )r   r   r   rf   r   r   r   r;   r;   r@   r   D  s*   zGoodbye.parsec                 C   s2   i }| j r
| j |d< | jr| j|d< tj|| jgS )r   rf   r   )rf   r   r   r   r   r   r;   r;   r@   r   m  s   

zGoodbye.marshal)r   r   r   r   r   DEFAULT_REASONr   r   r   r   r   r;   r;   r;   r@   r     s    
(r   c                   @   r   )r   a  
    A WAMP ``ERROR`` message.

    Formats:

    * ``[ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri]``
    * ``[ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list]``
    * ``[ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict]``
    * ``[ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Payload|binary]``
       )request_typerequesterrorargsrz   payloadrL   enc_keyrN   r   callee_authidcallee_authroleforward_forNc                 C   sJ  t |tksJ t |tksJ t |tksJ |du s&t |ttfv s&J |du s2t |tks2J |du s>t |tks>J |du sP|durN|du rN|du sPJ |du sZt|sZJ |du rf|du rf|	du sp|durn|duspJ |du s|t |tks|J |	du st|	sJ |
du st |
tksJ |du st |tksJ |du st |tksJ |du st |tksJ |r|D ]:}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v rt |d tksJ qt	
|  || _|| _|| _|| _t|| _|| _|| _|| _|	| _|
| _|| _|| _|| _dS )a  

        :param request_type: The WAMP message type code for the original request.
        :type request_type: int

        :param request: The WAMP request ID of the original request (`Call`, `Subscribe`, ...) this error occurred for.
        :type request: int

        :param error: The WAMP or application error URI for the error that occurred.
        :type error: str

        :param args: Positional values for application-defined exception.
           Must be serializable using any serializers in use.
        :type args: list or None

        :param kwargs: Keyword values for application-defined exception.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None

        :param callee: The WAMP session ID of the effective callee that responded with the error. Only filled if callee is disclosed.
        :type callee: None or int

        :param callee_authid: The WAMP authid of the responding callee. Only filled if callee is disclosed.
        :type callee_authid: None or unicode

        :param callee_authrole: The WAMP authrole of the responding callee. Only filled if callee is disclosed.
        :type callee_authrole: None or unicode

        :param forward_for: When this Error is forwarded for a client/callee (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   )rH   rt   rI   r   tuplerv   rR   r(   r)   r   r   r  r  r  r	  r{   rz   r
  rL   r  rN   r   r  r  r  )r   r  r  r  r	  rz   r
  rL   r  rN   r   r  r  r  ffr;   r;   r@   r     sF   9$,(


zError.__init__c                 C   sj  t | dkr| d tjksJ t | dvrtdt | | d }t|tkr/td||tjtjt	jt
jtjtjtjfvrHtd|t| d d}t| d	 d
}t| d d}d}d}d}d}d}	d}
d}d}d}d}t | dkrt| d tkr| d }|dd}|rt|std||dd}	|	rt|	tkrtdt|	|dd}
|
rt|
std|
n6t | dkr| d }|durt|tkrtdt|t | dkr| d }t|tkrtdt|d|v r|d }t|tkrtdt||}d|v r-|d }t|tkr+tdt||}d|v rH|d }t|tkrFtdt||}d|v r|d }d}t|tkr|D ]<}t|tkrg n2d |vsut|d  tkrw n"d!|vst|d! tkr nd"|vst|d" tkr nq\d#}|std$t||||||||	|
||||d%}|S )&r   r   )rD   rE      z$invalid message length {0} for ERRORr6   z,invalid type {0} for 'request_type' in ERRORz-invalid value {0} for 'request_type' in ERRORr7   z'request' in ERRORr8   z'details' in ERRORrC   z'error' in ERRORNrE   rD   rL   0invalid value {0} for 'enc_algo' detail in EVENTr  .invalid type {0} for 'enc_key' detail in EVENTrN   6invalid value {0} for 'enc_serializer' detail in EVENTz$invalid type {0} for 'args' in ERRORz&invalid type {0} for 'kwargs' in ERRORr   z-invalid type {0} for 'callee' detail in ERRORr  z4invalid type {0} for 'callee_authid' detail in ERRORr  z6invalid type {0} for 'callee_authrole' detail in ERRORr  Fr   r   r   Tz?invalid type/value {0} for/within 'forward_for' option in ERROR)
r	  rz   r
  rL   r  rN   r   r  r  r  )rW   r   r   r   rV   rH   rt   r   r   r   r   r   r   r!   r&   r'   r$   rR   r   r(   rI   r)   r   rv   )r   r  r  r   r  r	  rz   r
  rL   r  rN   r   r  r  r  detail_calleedetail_callee_authiddetail_callee_authrolevalidr  r   r;   r;   r@   r     s   



zError.parsec                 C   s
  i }| j dur| j |d< | jdur| j|d< | jdur | j|d< | jdur*| j|d< | jrX| jdur7| j|d< | jdurA| j|d< | jdurK| j|d< | j| j	| j
|| j| jgS | jrj| j| j	| j
|| j| j| jgS | jrz| j| j	| j
|| j| jgS | j| j	| j
|| jgS )	r   Nr   r  r  r  rL   r  rN   )r   r  r  r  r
  rL   r  rN   r   r  r  r  rz   r	  r   r;   r;   r@   r     s,   













zError.marshalr   r   r;   r;   r;   r@   r   ~  s(    
g
 r   c                   @   sz  e Zd ZdZdZ	 dZ																				dNddZdd Zd	d
 Ze	dd Z
e
jdd Z
e	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	d d! Zejd"d! Ze	d#d$ Zejd%d$ Ze	d&d' Zejd(d' Ze	d)d* Zejd+d* Ze	d,d- Zejd.d- Ze	d/d0 Zejd1d0 Ze	d2d3 Zejd4d3 Ze	d5d6 Zejd7d6 Ze	d8d9 Zejd:d9 Ze	d;d< Zejd=d< Ze	d>d? Zejd@d? Ze	dAdB ZejdCdB ZedDdE ZdFdG Z edHdI Z!dJdK Z"dLdM Z#dS )Or   aZ  
    A WAMP ``PUBLISH`` message.

    Formats:

    * ``[PUBLISH, Request|id, Options|dict, Topic|uri]``
    * ``[PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list]``
    * ``[PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict]``
    * ``[PUBLISH, Request|id, Options|dict, Topic|uri, Payload|binary]``
       )_request_topic_args_kwargs_payload	_enc_algo_enc_serializer_enc_key_acknowledge_exclude_me_exclude_exclude_authid_exclude_authrole	_eligible_eligible_authid_eligible_authrole_retain_transaction_hash_forward_forNc                 C   s  |du st |tksJ |du st |tksJ |du s(t |ttttfv s(J |du s7t |tttfv s7J |du sCt |tksCJ |du sU|durS|du rS|du sUJ |du sat |tksaJ |du smt |tksmJ |du syt |tksyJ |du st |tksJ |du st |tksJ |r|D ]
}t |tksJ q|	du st |	tksJ |	r|	D ]
}t |tksJ q|
du st |
tksJ |
r|
D ]
}t |tksJ q|du st |tksJ |r|D ]
}t |tksJ q|du st |tksJ |r|D ]}t |tksJ q|du st |tksJ |r/|D ]}t |tks-J q"|du s;t|s;J |du rJ|du rJ|du sV|durT|dusVJ |du sdt |tksdJ |du spt	|spJ |du s~t |tks~J |r|D ]C}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v rt |d tksJ qt
j| |d || _|| _|| _t|| _|| _|| _|| _|| _|	| _|
| _|| _|| _|| _|| _|| _|| _|| _|| _|| _dS )a  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param topic: The WAMP or application URI of the PubSub topic the event should
           be published to.
        :type topic: str

        :param args: Positional values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type args: list or tuple or None

        :param kwargs: Keyword values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param acknowledge: If True, acknowledge the publication with a success or
           error response.
        :type acknowledge: bool or None

        :param exclude_me: If ``True``, exclude the publisher from receiving the event, even
           if he is subscribed (and eligible).
        :type exclude_me: bool or None

        :param exclude: List of WAMP session IDs to exclude from receiving this event.
        :type exclude: list of int or None

        :param exclude_authid: List of WAMP authids to exclude from receiving this event.
        :type exclude_authid: list of str or None

        :param exclude_authrole: List of WAMP authroles to exclude from receiving this event.
        :type exclude_authrole: list of str or None

        :param eligible: List of WAMP session IDs eligible to receive this event.
        :type eligible: list of int or None

        :param eligible_authid: List of WAMP authids eligible to receive this event.
        :type eligible_authid: list of str or None

        :param eligible_authrole: List of WAMP authroles eligible to receive this event.
        :type eligible_authrole: list of str or None

        :param retain: If ``True``, request the broker retain this event.
        :type retain: bool or None

        :param transaction_hash: An application provided transaction hash for the published event, which may
            be used in the router to throttle or deduplicate the events on the topic. See the discussion
            `here <https://github.com/wamp-proto/wamp-proto/issues/391#issuecomment-998577967>`_.
        :type transaction_hash: str

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None or None

        :param forward_for: When this Call is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   r   ) rH   rt   rI   r   r  rR   rv   r   r(   r)   r   r   r  r  r  r{   r  r  r"  r#  r$  r%  r&  r'  r(  r)  r*  r+  r  r!  r   r,  )r   r  topicr	  rz   r
  acknowledge
exclude_meexcludeexclude_authidexclude_authroleeligibleeligible_authideligible_authroleretaintransaction_hashrL   r  rN   r  r   	sessionidr   r   r  r;   r;   r@   r     s   W $6 .$

zPublish.__init__c                 C   sT  t || jsdS t| |sdS |j| jkrdS |j| jkr dS |j| jkr(dS |j| jkr0dS |j| jkr8dS |j	| j	kr@dS |j
| j
krHdS |j| jkrPdS |j| jkrXdS |j| jkr`dS |j| jkrhdS |j| jkrpdS |j| jkrxdS |j| jkrdS |j| jkrdS |j| jkrdS |j| jkrdS |j| jkrdS |j| jkrdS dS NFT)rx   r   r   r   r  r.  r	  rz   r
  r/  r0  r1  r2  r3  r4  r5  r6  r7  r8  rL   r  rN   r  r   r;   r;   r@   r     sV   zPublish.__eq__c                 C   r   r   r   r   r;   r;   r@   r        zPublish.__ne__c                 C   "   | j d u r| jr| j | _ | j S r   )r  r}   Requestr   r;   r;   r@   r       zPublish.requestc                 C   r   r   )rH   rt   r  r   r;   r;   r@   r    r   c                 C   0   | j d u r| jr| j }|r|d| _ | j S Nutf8r  r}   TopicrU   r   rZ   r;   r;   r@   r.    
   
zPublish.topicc                 C   r   r   rH   rI   r  r   r;   r;   r@   r.    r   c                 C   6   | j d u r| jr| j rtt| j | _ | j S r   r  r}   
ArgsLengthcbor2loadsrR   ArgsAsBytesr   r;   r;   r@   r	       
zPublish.argsc                 C   &   |d u st |ttfv sJ || _d S r   rH   r   r  r  r   r;   r;   r@   r	       
c                 C   rG  r   r  r}   KwargsLengthrJ  rK  rR   KwargsAsBytesr   r;   r;   r@   rz     rM  zPublish.kwargsc                 C   r   r   rH   rv   r  r   r;   r;   r@   rz     r   c                 C   ,   | j d u r| jr| j r| j | _ | j S r   r  r}   PayloadLengthPayloadAsBytesr   r;   r;   r@   r
       
zPublish.payloadc                 C   r   r   rH   rR   r  r   r;   r;   r@   r
    r   c                 C   *   | j d u r| jr| j }|r|| _ | j S r   )r"  r}   Acknowledge)r   r/  r;   r;   r@   r/    
   
zPublish.acknowledgec                 C   r   r   )rH   r   r"  r   r;   r;   r@   r/    r   c                 C   s.   | j d u r| jr| j }|du r|| _ | j S )NF)r#  r}   	ExcludeMe)r   r0  r;   r;   r@   r0    s
   
zPublish.exclude_mec                 C   r   r   )rH   r   r#  r   r;   r;   r@   r0  %  r   c                 C   P   | j d u r%| jr%| j r%g }t| j D ]}|| j| q|| _ | j S r   )r$  r}   ExcludeLengthrangeappendExclude)r   r1  jr;   r;   r@   r1  *     
zPublish.excludec                 C   @   |d u st |tksJ |r|D ]
}t |tksJ q|| _d S r   )rH   r   rt   r$  r   r>   xr;   r;   r@   r1  4  
   
c                 C   V   | j d u r(| jr(| j r(g }t| j D ]}|| j|d q|| _ | j S r@  )r%  r}   ExcludeAuthidLengthra  rb  ExcludeAuthidrU   )r   r2  rd  r;   r;   r@   r2  <     
zPublish.exclude_authidc                 C   rf  r   )rH   r   rI   r%  rg  r;   r;   r@   r2  F  ri  c                 C   rj  r@  )r&  r}   ExcludeAuthroleLengthra  rb  ExcludeAuthrolerU   )r   r3  rd  r;   r;   r@   r3  N  rm  zPublish.exclude_authrolec                 C   rf  r   )rH   r   rI   r&  rg  r;   r;   r@   r3  X  ri  c                 C   r_  r   )r'  r}   EligibleLengthra  rb  Eligible)r   r4  rd  r;   r;   r@   r4  `  re  zPublish.eligiblec                 C   rf  r   )rH   r   rt   r'  rg  r;   r;   r@   r4  j  ri  c                 C   rj  r@  )r(  r}   EligibleAuthidLengthra  rb  EligibleAuthidrU   )r   r5  rd  r;   r;   r@   r5  r  rm  zPublish.eligible_authidc                 C   rf  r   )rH   r   rI   r(  rg  r;   r;   r@   r5  |  ri  c                 C   rj  r@  )r)  r}   EligibleAuthroleLengthra  rb  EligibleAuthrolerU   )r   r6  rd  r;   r;   r@   r6    rm  zPublish.eligible_authrolec                 C   rf  r   )rH   r   rI   r)  rg  r;   r;   r@   r6    ri  c                 C   r[  r   )r*  r}   Retain)r   r7  r;   r;   r@   r7    r]  zPublish.retainc                 C   r   r   )rH   r   r*  r   r;   r;   r@   r7    r   c                 C   r?  r@  r+  r}   TransactionHashrU   rD  r;   r;   r@   r8    rE  zPublish.transaction_hashc                 C   r   r   rH   rI   r+  r   r;   r;   r@   r8    r   c                 C   r[  r   r  r}   EncAlgor   rL   r;   r;   r@   rL     r]  zPublish.enc_algoc                 C   $   |d u s|t ttfv sJ || _d S r   ENC_ALGO_CRYPTOBOXENC_ALGO_MQTTENC_ALGO_XBRr  r   r;   r;   r@   rL        
c                 C   rU  r   r!  r}   EncKeyLengthEncKeyAsBytesr   r;   r;   r@   r    rY  zPublish.enc_keyc                 C   r   r   rH   rR   r!  r   r;   r;   r@   r    r   c                 C   r[  r   r   r}   EncSerializerr   rN   r;   r;   r@   rN     r]  zPublish.enc_serializerc                 C   &   |d u s|t tttfv sJ || _d S r   ENC_SER_JSONENC_SER_MSGPACKENC_SER_CBORENC_SER_UBJSONr   r   r;   r;   r@   rN     rP  c                 C   r   r   r,  r   r;   r;   r@   r       zPublish.forward_forc                 C   
   || _ d S r   r  r   r;   r;   r@   r       
c                 C      t tj | ddS Nr   r-  )r   r
   GetRootAsPublishr   r;   r;   r@   r        zPublish.castc                 C   s|  | j }|r|t|}| j}|r|t|}| j}|r$||}| j}|r.||}| j}|r8||}| j	}|rB||}| j
}|rctj|t| t|D ]}	||	 qT|t|}| j}
|
rg }|
D ]
}||| qltj|t| t|D ]}|| q|t|}
| j}|
rg }|D ]
}||| qtj|t| t|D ]}|| q|t|}| j}|rtj|t| t|D ]}	||	 q|t|}| j}|rg }|D ]
}||| qtj|t| t|D ]}|| q|t|}| j}|rIg }|D ]}||| q tj|t| t|D ]}|| q9|t|}tj| | jd ur]tj|| j |rgtj|| |rqtj || |r{tj!|| |rtj"|| | j#rtj$|| j# | j%rtj&|| j% |rtj'|| | j(d urtj)|| j( | j*d urtj+|| j* |rtj,|| |
rtj-||
 |rtj.|| |rtj/|| |rtj0|| |rtj1|| | j2d urtj3|| j2 |d urtj4|| j tj5|}tj67| tj68|tj9j: tj6;|| tj6<|}|S r   )=r	  CreateByteVectorrJ  dumpsrz   r
  r.  CreateStringr8  r  r1  r
   
PublishGenPublishStartExcludeAuthidVectorrW   reversedPrependUint64	EndVectorr2  rb  PrependUOffsetTRelativer3  !PublishStartExcludeAuthroleVectorr4   PublishStartEligibleAuthidVectorr5  r6  "PublishStartEligibleAuthroleVectorPublishStartr  PublishAddRequestPublishAddTopicPublishAddArgsPublishAddKwargsPublishAddPayloadrL   PublishAddEncAlgorN   PublishAddEncSerializerPublishAddEncKeyr/  PublishAddAcknowledger0  PublishAddExcludeMePublishAddExcludePublishAddExcludeAuthidPublishAddExcludeAuthrolePublishAddEligiblePublishAddEligibleAuthidPublishAddEligibleAuthroler7  PublishAddRetainPublishAddTransactionHash
PublishEndr   MessageStartMessageAddMsgTypeMessageTypePUBLISHMessageAddMsg
MessageEnd)r   r   r	  rz   r
  r.  r8  r  r1  r   r2  r%  r   or3  r&  r   r4  r5  r(  r6  r)  msg	union_msgr;   r;   r@   r     s   




zPublish.buildc           $      C   s  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}t| d d	}d
}d
}d
}t | dkrt| d t	t
fv r| d }|dd
}|r`t|s`td||dd
}|rwt|t	krwtdt||dd
}	|	rt|	std|	n>t | dkr| d }t|tt	t
fvrtdt|t | dkr| d }t|tt	t
fvrtdt|d
}d
}d
}	d
}
d
}d
}d
}d
}d
}d
}d
}d
}d
}d
}d|v r|d }t|tkrtdt||}
d|v r|d }t|tkrtdt||}d|v rD|d }t|tkr,tdt||D ]}t|tkr@tdt|q.|}d|v ru|d }t|tkr]tdt||D ]}t|t	krqtdt|q_|}d|v r|d }t|tkrtd t||D ]}t|t	krtd!t|q|}d"|v r|d" }t|tkrtd#t||D ]}t|tkrtd$t|q|}d%|v r|d% }t|tkrtd&t||D ]}t|t	krtd't|q|}d(|v r9|d( } t| tkr!td)t| | D ]}t|t	kr5td*t|q#| }d+|v rR|d+ }t|tkrRtd,t|d-|v rk|d- }t|t	krktd.t|d/|v r|d/ }d0}!t|tkr|D ]<}"t|"tkr n2d1|"vst|"d1 tkr n"d2|"vst|"d2 t	kr nd3|"vst|"d3 t	kr nqd4}!|!std5t||fi d6|d7|d8|d|
d|d|d|d|d"|d%|d(|d+|d-|d|d|d|	d/|}#|#S )9r   r   rC   rD   rE   z&invalid message length {0} for PUBLISHr6   z'request' in PUBLISHr7   z'options' in PUBLISHr8   z'topic' in PUBLISHNrD   rC   rL   z2invalid value {0} for 'enc_algo' option in PUBLISHr  z0invalid type {0} for 'enc_key' option in PUBLISHrN   z8invalid value {0} for 'enc_serializer' option in PUBLISHz&invalid type {0} for 'args' in PUBLISHz(invalid type {0} for 'kwargs' in PUBLISHr/  z4invalid type {0} for 'acknowledge' option in PUBLISHr0  z3invalid type {0} for 'exclude_me' option in PUBLISHr1  z0invalid type {0} for 'exclude' option in PUBLISHz9invalid type {0} for value in 'exclude' option in PUBLISHr2  z7invalid type {0} for 'exclude_authid' option in PUBLISHz@invalid type {0} for value in 'exclude_authid' option in PUBLISHr3  z9invalid type {0} for 'exclude_authrole' option in PUBLISHzBinvalid type {0} for value in 'exclude_authrole' option in PUBLISHr4  z1invalid type {0} for 'eligible' option in PUBLISHz:invalid type {0} for value in 'eligible' option in PUBLISHr5  z8invalid type {0} for 'eligible_authid' option in PUBLISHzAinvalid type {0} for value in 'eligible_authid' option in PUBLISHr6  z:invalid type {0} for 'eligible_authrole' option in PUBLISHzCinvalid type {0} for value in 'eligible_authrole' option in PUBLISHr7  z/invalid type {0} for 'retain' option in PUBLISHr8  z9invalid type {0} for 'transaction_hash' option in PUBLISHr  Fr   r   r   TzAinvalid type/value {0} for/within 'forward_for' option in PUBLISHr	  rz   r
  )rW   r   r   r   rV   r&   r'   r$   rH   rI   rR   r   r(   r)   r   rv   r   rt   )$r   r  optionsr.  r	  rz   r
  rL   r  rN   r/  r0  r1  r2  r3  r4  r5  r6  r7  r8  r  option_acknowledgeoption_exclude_meoption_exclude
_sessionidoption_exclude_authid_authidoption_exclude_authrole	_authroleoption_eligible	sessionIdoption_eligible_authidoption_eligible_authroler  r  r   r;   r;   r@   r   t	  sT   









	
zPublish.parsec                 C   s&  i }| j d ur| j |d< | jd ur| j|d< | jd ur | j|d< | jd ur*| j|d< | jd ur4| j|d< | jd ur>| j|d< | jd urH| j|d< | jd urR| j|d< | jd ur\| j|d	< | j	d urf| j	|d
< | j
r| jd urs| j|d< | jd ur}| j|d< | jd ur| j|d< | jd ur| j|d< |S )Nr/  r0  r1  r2  r3  r4  r5  r6  r7  r8  rL   r  rN   r  )r/  r0  r1  r2  r3  r4  r5  r6  r7  r8  r
  rL   r  rN   r  r   r  r;   r;   r@   marshal_optionsA
  s>   



























zPublish.marshal_optionsc                 C   r   |   }| jrtj| j|| j| jgS | jr"tj| j|| j| j| jgS | jr0tj| j|| j| jgS tj| j|| jgS r   )r  r
  r   r   r  r.  rz   r	  r  r;   r;   r@   r   g
     zPublish.marshal)NNNNNNNNNNNNNNNNNNNN)$r   r   r   r   r   r   r   r   r   r   r  r   r.  r	  rz   r
  r/  r0  r1  r2  r3  r4  r5  r6  r7  r8  rL   r  rN   r  r   r   r   r   r  r   r;   r;   r;   r@   r     s    <
 /-














	

	

	

	

	

	













 
 M&r   c                   @   6   e Zd ZdZdZ	 dZdd Zedd Zdd	 Z	d
S )r   zh
    A WAMP ``PUBLISHED`` message.

    Format: ``[PUBLISHED, PUBLISH.Request|id, Publication|id]``
       )r  publicationc                 C   :   t |tksJ t |tksJ t|  || _|| _dS )z

        :param request: The request ID of the original `PUBLISH` request.
        :type request: int

        :param publication: The publication ID for the published event.
        :type publication: int
        N)rH   rt   r   r   r  r  )r   r  r  r;   r;   r@   r   
  
   	

zPublished.__init__c                 C   f   t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}t||}|S )r   r   r8   z(invalid message length {0} for PUBLISHEDr6   z'request' in PUBLISHEDr7   z'publication' in PUBLISHED)rW   r   r   r   rV   r&   )r   r  r  r   r;   r;   r@   r   
     
zPublished.parsec                 C   r   r   )r   r   r  r  r   r;   r;   r@   r   
  r   zPublished.marshalNr   r;   r;   r;   r@   r   {
      
r   c                   @   sR   e Zd ZdZdZ	 dZdZdZdZ			ddd	Z	e
d
d Zdd Zdd ZdS )r   zi
    A WAMP ``SUBSCRIBE`` message.

    Format: ``[SUBSCRIBE, Request|id, Options|dict, Topic|uri]``
        exactprefixwildcard)r  r.  rK   get_retainedr  Nc                 C   s8  t |tksJ t |tksJ |du st |tksJ |du s,|tjtjtjfv s,J |du s8t |tu s8J |du sDt |tksDJ |r|D ]:}t |t	ksRJ d|v r^t |d tks`J d|v rr|d du stt |d tkstJ d|v rt |d tksJ qHt
|  || _|| _|ptj| _|| _|| _dS )a  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param topic: The WAMP or application URI of the PubSub topic to subscribe to.
        :type topic: str

        :param match: The topic matching method to be used for the subscription.
        :type match: str

        :param get_retained: Whether the client wants the retained message we may have along with the subscription.
        :type get_retained: bool or None

        :param forward_for: When this Subscribe is forwarded over a router-to-router link,
            or via an intermediary router.
        :type forward_for: list[dict]
        Nr   r   r   )rH   rt   rI   r   MATCH_EXACTMATCH_PREFIXMATCH_WILDCARDr   r   rv   r   r   r  r.  rK   r  r  )r   r  r.  rK   r  r  r  r;   r;   r@   r   
  s$    (

zSubscribe.__init__c                 C   s  t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}t| d d	d
d}tj}d}d}d|v rf|d }t	|t
krStdt	||tjtjtjfvrdtd||}d|v r}|d }t	|tkr}tdt	|d|v r|d }d}t	|tkr|D ]4}	t	|	tkr n+d|	vst	|	d tkr nd|	vst	|	d t
kr nd|	vst	|	d t
kr nqd
}|stdt|||||d}
|
S )r   r   rC   z(invalid message length {0} for SUBSCRIBEr6   z'request' in SUBSCRIBEr7   z'options' in SUBSCRIBEr8   z'topic' in SUBSCRIBET)rh   NrK   z0invalid type {0} for 'match' option in SUBSCRIBEz1invalid value {0} for 'match' option in SUBSCRIBEr  z7invalid type {0} for 'get_retained' option in SUBSCRIBEr  Fr   r   r   zCinvalid type/value {0} for/within 'forward_for' option in SUBSCRIBE)rK   r  r  )rW   r   r   r   rV   r&   r'   r$   r  rH   rI   r  r  r   r   rv   rt   )r   r  r  r.  rK   r  r  option_matchr  r  r   r;   r;   r@   r     sN   zSubscribe.parsec                 C   sL   i }| j r| j tjkr| j |d< | jd ur| j|d< | jd ur$| j|d< |S )NrK   r  r  )rK   r   r  r  r  r  r;   r;   r@   r  @  s   




zSubscribe.marshal_optionsc                 C      t j| j|  | jgS r   )r   r   r  r  r.  r   r;   r;   r@   r   N     zSubscribe.marshalNNN)r   r   r   r   r   r  r  r  r   r   r   r   r  r   r;   r;   r;   r@   r   
  s     
,
>r   c                   @   r  )r   zm
    A WAMP ``SUBSCRIBED`` message.

    Format: ``[SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id]``
    !   )r  subscriptionc                 C   r  )z

        :param request: The request ID of the original ``SUBSCRIBE`` request.
        :type request: int

        :param subscription: The subscription ID for the subscribed topic (or topic pattern).
        :type subscription: int
        N)rH   rt   r   r   r  r  )r   r  r  r;   r;   r@   r   i  r  zSubscribed.__init__c                 C   r  )r   r   r8   z)invalid message length {0} for SUBSCRIBEDr6   z'request' in SUBSCRIBEDr7   z'subscription' in SUBSCRIBED)rW   r   r   r   rV   r&   )r   r  r  r   r;   r;   r@   r   y  r  zSubscribed.parsec                 C   r   r   )r   r   r  r  r   r;   r;   r@   r     r   zSubscribed.marshalNr   r;   r;   r;   r@   r   X  r  r   c                   @   r   )r   z
    A WAMP ``UNSUBSCRIBE`` message.

    Formats:

    * ``[UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]``
    * ``[UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id, Options|dict]``
    "   )r  r  r  Nc                 C   s   t |tksJ t |tksJ |rO|D ]:}t |tksJ d|v r*t |d tks,J d|v r>|d du s@t |d tks@J d|v rLt |d tksNJ qt|  || _|| _|| _dS )a  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param subscription: The subscription ID for the subscription to unsubscribe from.
        :type subscription: int

        :param forward_for: When this Unsubscribe is forwarded over a router-to-router link,
            or via an intermediary router.
        :type forward_for: list[dict]
        r   r   Nr   )	rH   rt   rv   rI   r   r   r  r  r  )r   r  r  r  r  r;   r;   r@   r     s   (

zUnsubscribe.__init__c                 C   .  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}d}t | d	kr;t| d	 d
}d}|rd|v r|d }d}t|tkr|D ]4}t|t	kr[ n+d|vsgt|d t
kri nd|vsut|d tkrw nd|vst|d tkr nqQd}|stdt|||d}|S )r   r   r8   rC   z/invalid message length {0} for WAMP UNSUBSCRIBEr6   z'request' in UNSUBSCRIBEr7   z'subscription' in UNSUBSCRIBENr8   z'options' in UNSUBSCRIBEr  Fr   r   r   TzEinvalid type/value {0} for/within 'forward_for' option in UNSUBSCRIBEr  )rW   r   r   r   rV   r&   r'   rH   r   rv   rt   rI   )r   r  r  r  r  r  r  r   r;   r;   r@   r     8   zUnsubscribe.parsec                 C   2   | j rd| j i}tj| j| j|gS tj| j| jgS r   r  )r  r   r   r  r  r  r;   r;   r@   r     
   zUnsubscribe.marshalr   r   r;   r;   r;   r@   r     s    	

-r   c                   @   r   )r   z
    A WAMP ``UNSUBSCRIBED`` message.

    Formats:

    * ``[UNSUBSCRIBED, UNSUBSCRIBE.Request|id]``
    * ``[UNSUBSCRIBED, UNSUBSCRIBE.Request|id, Details|dict]``
    #   )r  r  r   Nc                 C      t |tksJ |du st |tksJ |du s t |tks J |dkr(|du s2|dkr0|dks2J t|  || _|| _|| _dS )a  

        :param request: The request ID of the original ``UNSUBSCRIBE`` request or
            ``0`` is router triggered unsubscribe ("router revocation signaling").
        :type request: int

        :param subscription: If unsubscribe was actively triggered by router, the ID
            of the subscription revoked.
        :type subscription: int or None

        :param reason: The reason (an URI) for an active (router initiated) revocation.
        :type reason: str or None.
        Nr   )rH   rt   rI   r   r   r  r  r   )r   r  r  r   r;   r;   r@   r     s   $

zUnsubscribed.__init__c                 C      t | dkr| d tjksJ t | dvrtdt | t| d d}d}d}t | dkrZt| d d}d	|v rO|d	 }t|tkrMtd
t||}d|v rZt	|d d}t|||}|S )r   r   r7   r8   z+invalid message length {0} for UNSUBSCRIBEDr6   z'request' in UNSUBSCRIBEDNr7   z'details' in UNSUBSCRIBEDr  z:invalid type {0} for 'subscription' detail in UNSUBSCRIBEDr   z'reason' in UNSUBSCRIBED)
rW   r   r   r   rV   r&   r'   rH   rt   r$   )r   r  r  r   r   details_subscriptionr   r;   r;   r@   r   5  "   zUnsubscribed.parsec                 C   Z   | j dus
| jdur'i }| j dur| j |d< | jdur | j|d< tj| j|gS tj| jgS )r   Nr   r  )r   r  r   r   r  r   r;   r;   r@   r   [     



zUnsubscribed.marshalNNr   r;   r;   r;   r@   r     s    	

%r   c                   @   s  e Zd ZdZdZ	 dZ					dCddZdd Zd	d
 Ze	dd Z
e
jdd Z
e	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Ze	d d! Zejd"d! Ze	d#d$ Zejd%d$ Ze	d&d' Zejd(d' Ze	d)d* Zejd+d* Ze	d,d- Zejd.d- Ze	d/d0 Zejd1d0 Ze	d2d3 Zejd4d3 Ze	d5d6 Zejd7d6 Ze	d8d9 Zejd:d9 Zed;d< Zd=d> Zed?d@ ZdAdB ZdS )Dr   a  
    A WAMP ``EVENT`` message.

    Formats:

    * ``[EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict]``
    * ``[EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list]``
    * ``[EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentsKw|dict]``
    * ``[EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Payload|binary]``
    $   )_subscription_publicationr  r  r  r  r   r!  
_publisher_publisher_authid_publisher_authroler  	_retainedr+  _x_acknowledged_deliveryr,  Nc                 C   s  |du st |tksJ |du st |tksJ |du s&t |ttfv s&J |du s2t |tks2J |du s>t |tks>J |du sP|durN|du rN|du sPJ |du s\t |tks\J |du sht |tkshJ |du stt |tkstJ |	du st |	tksJ |
du st |
tksJ |du st |tksJ |du st |tksJ |du st|sJ |du r|du r|du s|dur|dusJ |du st |tksJ |du st	|sJ |du st |tksJ |r-|D ]A}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v r*t |d tks,J qt
j| |d || _|| _|| _t|| _|| _|| _|| _|| _|	| _|
| _|| _|| _|| _|| _|| _|| _dS )a
  

        :param subscription: The subscription ID this event is dispatched under.
        :type subscription: int

        :param publication: The publication ID of the dispatched event.
        :type publication: int

        :param args: Positional values for application-defined exception.
           Must be serializable using any serializers in use.
        :type args: list or tuple or None

        :param kwargs: Keyword values for application-defined exception.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param publisher: The WAMP session ID of the publisher. Only filled if publisher is disclosed.
        :type publisher: None or int

        :param publisher_authid: The WAMP authid of the publisher. Only filled if publisher is disclosed.
        :type publisher_authid: None or unicode

        :param publisher_authrole: The WAMP authrole of the publisher. Only filled if publisher is disclosed.
        :type publisher_authrole: None or unicode

        :param topic: For pattern-based subscriptions, the event MUST contain the actual topic published to.
        :type topic: str or None

        :param retained: Whether the message was retained by the broker on the topic, rather than just published.
        :type retained: bool or None

        :param transaction_hash: An application provided transaction hash for the originating call, which may
            be used in the router to throttle or deduplicate the calls on the procedure. See the discussion
            `here <https://github.com/wamp-proto/wamp-proto/issues/391#issuecomment-998577967>`_.
        :type transaction_hash: str

        :param x_acknowledged_delivery: Whether this Event should be acknowledged.
        :type x_acknowledged_delivery: bool or None

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None

        :param forward_for: When this Event is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   r-  )rH   rt   r   r  rv   rR   rI   r   r(   r)   r   r   r  r  r  r{   r  r  r  r  r  r  r   r+  r  r  r!  r   r,  )r   r  r  r	  rz   r
  r   publisher_authidpublisher_authroler.  retainedr8  x_acknowledged_deliveryrL   r  rN   r  r   r  r;   r;   r@   r     sR   ;$, ."

zEvent.__init__c                 C   s$  t || jsdS t| |sdS |j| jkrdS |j| jkr dS |j| jkr(dS |j| jkr0dS |j| jkr8dS |j	| j	kr@dS |j
| j
krHdS |j| jkrPdS |j| jkrXdS |j| jkr`dS |j| jkrhdS |j| jkrpdS |j| jkrxdS |j| jkrdS |j| jkrdS |j| jkrdS dS r:  )rx   r   r   r   r  r  r	  rz   r
  r   r  r  r.  r  r8  r  rL   r  rN   r  r   r;   r;   r@   r     sJ   zEvent.__eq__c                 C   r   r   r   r   r;   r;   r@   r   >  r;  zEvent.__ne__c                 C   r<  r   )r  r}   Subscriptionr   r;   r;   r@   r  A  r>  zEvent.subscriptionc                 C   r   r   )rH   rt   r  r   r;   r;   r@   r  G  r   c                 C   r<  r   )r  r}   Publicationr   r;   r;   r@   r  L  r>  zEvent.publicationc                 C   r   r   )rH   rt   r  r   r;   r;   r@   r  R  r   c                 C   rG  r   rH  r   r;   r;   r@   r	  W  rM  z
Event.argsc                 C   rN  r   rO  r   r;   r;   r@   r	  ^  rP  c                 C   rG  r   rQ  r   r;   r;   r@   rz   c  rM  zEvent.kwargsc                 C   r   r   rT  r   r;   r;   r@   rz   j  r   c                 C   rU  r   rV  r   r;   r;   r@   r
  o  rY  zEvent.payloadc                 C   r   r   rZ  r   r;   r;   r@   r
  v  r   c                 C   r[  r   )r  r}   	Publisher)r   r   r;   r;   r@   r   {  r]  zEvent.publisherc                 C   r   r   )rH   rt   r  r   r;   r;   r@   r     r   c                 C   r?  r@  )r  r}   PublisherAuthidrU   rD  r;   r;   r@   r    rE  zEvent.publisher_authidc                 C   r   r   )rH   rI   r  r   r;   r;   r@   r    r   c                 C   r?  r@  )r  r}   PublisherAuthrolerU   rD  r;   r;   r@   r    rE  zEvent.publisher_authrolec                 C   r   r   )rH   rI   r  r   r;   r;   r@   r    r   c                 C   r?  r@  rB  rD  r;   r;   r@   r.    rE  zEvent.topicc                 C   r   r   rF  r   r;   r;   r@   r.    r   c                 C   r<  r   )r   r}   Retainedr   r;   r;   r@   r    r>  zEvent.retainedc                 C   r   r   )rH   r   r   r   r;   r;   r@   r    r   c                 C   r?  r@  rw  rD  r;   r;   r@   r8    rE  zEvent.transaction_hashc                 C   r   r   ry  r   r;   r;   r@   r8    r   c                 C   r[  r   )r  r}   r\  )r   r  r;   r;   r@   r    r]  zEvent.x_acknowledged_deliveryc                 C   r   r   )rH   r   r  r   r;   r;   r@   r    r   c                 C   r[  r   rz  r|  r;   r;   r@   rL     r]  zEvent.enc_algoc                 C   r}  r   r~  r   r;   r;   r@   rL     r  c                 C   rU  r   r  r   r;   r;   r@   r    rY  zEvent.enc_keyc                 C   r   r   r  r   r;   r;   r@   r    r   c                 C   r[  r   r  r  r;   r;   r@   rN     r]  zEvent.enc_serializerc                 C   r  r   r  r   r;   r;   r@   rN     rP  c                 C   r   r   r  r   r;   r;   r@   r    r  zEvent.forward_forc                 C   r  r   r  r   r;   r;   r@   r    r  c                 C   r  r  )r   r
   GetRootAsEventr   r;   r;   r@   r     r  z
Event.castc                 C   s6  | j }|r|t|}| j}|r|t|}| j}|r$||}| j}|r.||}| j}|r8||}| j	}|rB||}| j
}|rL||}| j}	|	rV||	}	tj| | jrgtj|| j | jrrtj|| j |r{tj|| |rtj|| |rtj|| | jrtj|| j |rtj|| |rtj|| |rtj|| | jd urtj|| j |d urtj|| | jd urtj|| j | j rtj!|| j  |	rtj"||	 | j#rtj$|| j# tj%|}
tj&'| tj&(|tj)j* tj&+||
 tj&,|}|S r   )-r	  r  rJ  r  rz   r
  r  r  r  r.  r8  r  r
   EventGen
EventStartr  EventAddSubscriptionr  EventAddPublicationEventAddArgsEventAddKwargsEventAddPayloadr   EventAddPublisherEventAddPublisherAuthidEventAddPublisherAuthroleEventAddTopicr  EventAddRetainedEventAddTransactionHashr  EventAddAcknowledgerL   EventAddEncAlgoEventAddEncKeyrN   EventAddEncSerializerEventEndr   r  r  r  EVENTr  r  )r   r   r	  rz   r
  r  r  r.  r8  r  r  r  r;   r;   r@   r     sz   







zEvent.buildc                 C   s  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}t| d d	}d
}d
}d
}d
}d
}d
}	t | dkrt| d tkr| d }|	dd
}|rdt
|sdtd||	dd
}|r{t|tkr{tdt||	dd
}	|	rt|	std|	n6t | dkr| d }|d
urt|tkrtdt|t | dkr| d }t|tkrtdt|d
}
d
}d
}d
}d
}d
}d
}d
}d|v r|d }t|tkrtdt||}
d|v r	|d }t|tkrtdt||}d|v r$|d }t|tkr"tdt||}d|v r?|d }t|tkr=tdt||}d|v rX|d }t|tkrXtdt|d|v rs|d }t|tkrqtd t||}d!|v r|d! }t|tkrtd"t|d#|v r|d# }d$}t|tkr|D ]<}t|tkr n2d%|vst|d% tkr n"d&|vst|d& tkr nd'|vst|d' tkr nqd(}|std)t||||||
|||||||||	|d*}|S )+r   r   r  z$invalid message length {0} for EVENTr6   z'subscription' in EVENTr7   z'publication' in EVENTr8   z'details' in EVENTNrD   rC   rL   r  r  r  rN   r  z$invalid type {0} for 'args' in EVENTz&invalid type {0} for 'kwargs' in EVENTr   z0invalid type {0} for 'publisher' detail in EVENTr  z7invalid type {0} for 'publisher_authid' detail in EVENTr  z9invalid type {0} for 'publisher_authrole' detail in EVENTr.  z,invalid type {0} for 'topic' detail in EVENTr  z/invalid type {0} for 'retained' detail in EVENTr8  7invalid type {0} for 'transaction_hash' detail in EVENTr  z>invalid type {0} for 'x_acknowledged_delivery' detail in EVENTr  Fr   r   r   Tz?invalid type/value {0} for/within 'forward_for' option in EVENT)r	  rz   r
  r   r  r  r.  r  r8  r  rL   r  rN   r  )rW   r   r   r   rV   r&   r'   rH   rR   r   r(   rI   r)   r   rv   rt   r   )r   r  r  r   r	  rz   r
  rL   r  rN   r   r  r  r.  r  r8  r  r  detail_publisherdetail_publisher_authiddetail_publisher_authroledetail_topicdetail_transaction_hashr  r  r   r;   r;   r@   r   Z  s   






zEvent.parsec                 C   J  i }| j dur| j |d< | jdur| j|d< | jdur | j|d< | jdur*| j|d< | jdur4| j|d< | jdur>| j|d< | jdurH| j|d< | jdurR| j|d	< | jr~| j	dur_| j	|d
< | j
duri| j
|d< | jdurs| j|d< tj| j| j|| jgS | jrtj| j| j|| j| jgS | jrtj| j| j|| jgS tj| j| j|gS )r   Nr   r  r  r.  r  r8  r  r  rL   r  rN   )r   r  r  r.  r  r8  r  r  r
  rL   r  rN   r   r   r  r  rz   r	  r   r;   r;   r@   r     <   





















zEvent.marshal)NNNNNNNNNNNNNNNNN) r   r   r   r   r   r   r   r   r   r   r  r   r  r	  rz   r
  r   r  r  r.  r  r8  r  rL   r  rN   r  r   r   r   r   r   r;   r;   r;   r@   r   m  s    2
g'
































R
 r   c                   @   r  )EventReceivedzd
    A WAMP ``EVENT_RECEIVED`` message.

    Format: ``[EVENT_RECEIVED, EVENT.Publication|id]``
    iQ  )r  c                 C   s$   t |tksJ t|  || _dS )zl

        :param publication: The publication ID for the sent event.
        :type publication: int
        N)rH   rt   r   r   r  )r   r  r;   r;   r@   r   2  s   

zEventReceived.__init__c                 C   sV   t | dkr| d tjksJ t | dkrtdt | t| d d}t|}|S )r   r   r7   z-invalid message length {0} for EVENT_RECEIVEDr6   z'publication' in EVENT_RECEIVED)rW   r(  r   r   rV   r&   )r   r  r   r;   r;   r@   r   =  s   zEventReceived.parsec                 C   s   t j| jgS r   )r(  r   r  r   r;   r;   r@   r   S  s   zEventReceived.marshalNr   r;   r;   r;   r@   r(  !  s    
r(  c                   @   sZ   e Zd ZdZdZ	 dZ													dddZedd Zd	d
 Z	dd Z
dS )r   a[  
    A WAMP ``CALL`` message.

    Formats:

    * ``[CALL, Request|id, Options|dict, Procedure|uri]``
    * ``[CALL, Request|id, Options|dict, Procedure|uri, Arguments|list]``
    * ``[CALL, Request|id, Options|dict, Procedure|uri, Arguments|list, ArgumentsKw|dict]``
    * ``[CALL, Request|id, Options|dict, Procedure|uri, Payload|binary]``
    0   )r  	procedurer	  rz   r
  timeoutreceive_progressr8  rL   r  rN   r   caller_authidcaller_authroler  Nc                 C   s  t |tksJ t |tksJ |du st |ttfv sJ |du s*t |tks*J |du s6t |tks6J |du sH|durF|du rF|du sHJ |du sTt |tksTJ |du s`t |tks`J |du slt |tkslJ |	du svt|	svJ |
du st |
tksJ |du st	|sJ |	du r|
du r|du s|dur|	dusJ |du st |tksJ |du st |tksJ |du st |tksJ |du st |tksJ |r|D ]?}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v rt |d tksJ qt
|  || _|| _|| _t|| _|| _|| _|| _|| _|	| _|
| _|| _|| _|| _|| _|| _dS )a	  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param procedure: The WAMP or application URI of the procedure which should be called.
        :type procedure: str

        :param args: Positional values for application-defined call arguments.
           Must be serializable using any serializers in use.
        :type args: list or tuple or None

        :param kwargs: Keyword values for application-defined call arguments.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param timeout: If present, let the callee automatically cancel
           the call after this ms.
        :type timeout: int or None

        :param receive_progress: If ``True``, indicates that the caller wants to receive
           progressive call results.
        :type receive_progress: bool or None

        :param transaction_hash: An application provided transaction hash for the originating call, which may
            be used in the router to throttle or deduplicate the calls on the procedure. See the discussion
            `here <https://github.com/wamp-proto/wamp-proto/issues/391#issuecomment-998577967>`_.
        :type transaction_hash: str

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None

        :param caller: The WAMP session ID of the caller. Only filled if caller is disclosed.
        :type caller: None or int

        :param caller_authid: The WAMP authid of the caller. Only filled if caller is disclosed.
        :type caller_authid: None or unicode

        :param caller_authrole: The WAMP authrole of the caller. Only filled if caller is disclosed.
        :type caller_authrole: None or unicode

        :param forward_for: When this Publish is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   )rH   rt   rI   r   r  rv   rR   r   r(   r)   r   r   r  r*  r	  r{   rz   r
  r+  r,  r8  rL   r  rN   r   r-  r.  r  )r   r  r*  r	  rz   r
  r+  r,  r8  rL   r  rN   r   r-  r.  r  r  r;   r;   r@   r     sN   E$,."


zCall.__init__c                 C   s  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}t| d d	}d
}d
}d
}d
}d
}d
}	t | dkrt| d t	t
fv r| d }|dd
}|rft|sftd||dd
}|r}t|t	kr}tdt||dd
}	|	rt|	std|	n6t | dkr| d }|d
urt|tkrtdt|t | dkr| d }t|tkrtdt|d
}
d
}d
}d
}d
}d
}d
}d|v r|d }t|tkrtdt||dk rtd||}
d|v r|d }t|tkrtdt||}d|v r/|d }t|t	kr-tdt||}d|v rJ|d }t|tkrHtdt||}d|v re|d }t|t	krctdt||}d |v r|d  }t|t	kr~td!t||}d"|v r|d" }d#}t|tkr|D ]<}t|tkr n2d$|vst|d$ tkr n"d%|vst|d% t	kr nd&|vst|d& t	kr nqd'}|std(t||||||
|||||	||||d)}|S )*r   r   r  z#invalid message length {0} for CALLr6   z'request' in CALLr7   z'options' in CALLr8   z'procedure' in CALLNrD   rC   rL   z/invalid value {0} for 'enc_algo' detail in CALLr  z-invalid type {0} for 'enc_key' detail in CALLrN   z5invalid value {0} for 'enc_serializer' detail in CALLz#invalid type {0} for 'args' in CALLz%invalid type {0} for 'kwargs' in CALLr+  z-invalid type {0} for 'timeout' option in CALLz.invalid value {0} for 'timeout' option in CALLr,  z6invalid type {0} for 'receive_progress' option in CALLr8  z6invalid type {0} for 'transaction_hash' detail in CALLr   z,invalid type {0} for 'caller' detail in CALLr-  z3invalid type {0} for 'caller_authid' detail in CALLr.  z5invalid type {0} for 'caller_authrole' detail in CALLr  Fr   r   r   Tz>invalid type/value {0} for/within 'forward_for' option in CALL)r	  rz   r
  r+  r,  r8  rL   r  rN   r   r-  r.  r  )rW   r   r   r   rV   r&   r'   r$   rH   rI   rR   r   r(   r)   r   rv   rt   r   )r   r  r  r*  r	  rz   r
  rL   r  rN   r+  r,  r8  r   r-  r.  r  option_timeoutoption_receive_progressoption_transaction_hashoption_calleroption_caller_authidoption_caller_authroler  r  r   r;   r;   r@   r     s    





z
Call.parsec                 C   s   i }| j d ur| j |d< | jd ur| j|d< | jd ur | j|d< | jrA| jd ur-| j|d< | jd ur7| j|d< | jd urA| j|d< | jd urK| j|d< | jd urU| j|d< | j	d ur_| j	|d	< | j
d uri| j
|d
< |S )Nr+  r,  r8  rL   r  rN   r   r-  r.  r  )r+  r,  r8  r
  rL   r  rN   r   r-  r.  r  r  r;   r;   r@   r    s.   



















zCall.marshal_optionsc                 C   r  r   )r  r
  r   r   r  r*  rz   r	  r  r;   r;   r@   r     r  zCall.marshal)NNNNNNNNNNNNN)r   r   r   r   r   r   r   r   r   r  r   r;   r;   r;   r@   r   ]  s0    
v
  r   c                   @   sD   e Zd ZdZdZ	 dZdZdZdZddd	Z	e
d
d Zdd ZdS )r   z
    A WAMP ``CANCEL`` message.

    Format: ``[CANCEL, CALL.Request|id, Options|dict]``

    See: https://wamp-proto.org/static/rfc/draft-oberstet-hybi-crossbar-wamp.html#rfc.section.14.3.4
    1   skipkill
killnowait)r  moder  Nc                 C   s   t |tksJ |du st |tksJ |d| j| j| jfv s!J |du s-t |tks-J |rl|D ]:}t |tks;J d|v rGt |d tksIJ d|v r[|d du s]t |d tks]J d|v rit |d tkskJ q1t	|  || _
|| _|| _dS )a  

        :param request: The WAMP request ID of the original `CALL` to cancel.
        :type request: int

        :param mode: Specifies how to cancel the call (``"skip"``, ``"killnowait"`` or ``"kill"``).
        :type mode: str or None

        :param forward_for: When this Cancel is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   )rH   rt   rI   SKIP
KILLNOWAITKILLr   rv   r   r   r  r9  r  )r   r  r9  r  r  r;   r;   r@   r     s   (

zCancel.__init__c           	      C   sd  t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}d}d}d	|v rZ|d	 }t|tkrGtd
t||tj	tj
tjfvrXtd||}d|v r|d }d}t|tkr|D ]4}t|tkrv n+d|vst|d tkr nd|vst|d tkr nd|vst|d tkr nqld}|stdt|||d}|S )r   r   r8   z%invalid message length {0} for CANCELr6   z'request' in CANCELr7   z'options' in CANCELNr9  z,invalid type {0} for 'mode' option in CANCELz/invalid value '{0}' for 'mode' option in CANCELr  Fr   r   r   Tz@invalid type/value {0} for/within 'forward_for' option in CANCEL)r9  r  )rW   r   r   r   rV   r&   r'   rH   rI   r:  r;  r<  r   rv   rt   )	r   r  r  r9  r  option_moder  r  r   r;   r;   r@   r     sB   zCancel.parsec                 C   s:   i }| j dur| j |d< | jdur| j|d< tj| j|gS )r   Nr9  r  )r9  r  r   r   r  r  r;   r;   r@   r   /  s   



zCancel.marshalr  )r   r   r   r   r   r:  r<  r;  r   r   r   r   r   r;   r;   r;   r@   r     s    

8r   c                   @   N   e Zd ZdZdZ	 dZ											dddZedd Zd	d
 Z	dS )r   aO  
    A WAMP ``RESULT`` message.

    Formats:

    * ``[RESULT, CALL.Request|id, Details|dict]``
    * ``[RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list]``
    * ``[RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict]``
    * ``[RESULT, CALL.Request|id, Details|dict, Payload|binary]``
    2   r  r	  rz   r
  progressrL   r  rN   r   r  r  r  Nc                 C   s<  t |tksJ |du st |ttfv sJ |du s"t |tks"J |du s.t |tks.J |du s@|dur>|du r>|du s@J |du sLt |tksLJ |du sVt|sVJ |du sbt |tksbJ |du slt	|slJ |du rx|du rx|du s|dur|dusJ |	du st |	tksJ |
du st |
tksJ |du st |tksJ |du st |tksJ |r|D ]:}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v rt |d tksJ qt
|  || _|| _t|| _|| _|| _|| _|| _|| _|	| _|
| _|| _|| _dS )as  

        :param request: The request ID of the original `CALL` request.
        :type request: int

        :param args: Positional values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type args: list or tuple or None

        :param kwargs: Keyword values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param progress: If ``True``, this result is a progressive call result, and subsequent
           results (or a final error) will follow.
        :type progress: bool or None

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None

        :param callee: The WAMP session ID of the effective callee that responded with the result. Only filled if callee is disclosed.
        :type callee: None or int

        :param callee_authid: The WAMP authid of the responding callee. Only filled if callee is disclosed.
        :type callee_authid: None or unicode

        :param callee_authrole: The WAMP authrole of the responding callee. Only filled if callee is disclosed.
        :type callee_authrole: None or unicode

        :param forward_for: When this Result is forwarded for a client/callee (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   rH   rt   r   r  rv   rR   r   r(   rI   r)   r   r   r  r	  r{   rz   r
  rA  rL   r  rN   r   r  r  r  r   r  r	  rz   r
  rA  rL   r  rN   r   r  r  r  r  r;   r;   r@   r   `  sB   6$,(


zResult.__init__c                 C   s<  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}d}d}d}d}d}d}d}	d}
d}d}d}t | d	krt| d
 tt	fv r| d
 }|
dd}|rit|sitd||
dd}|rt|tkrtdt||
dd}	|	rt|	std|	n6t | d
kr| d
 }|durt|tkrtdt|t | d	kr| d	 }t|tkrtdt|d|v r|d }t|tkrtdt||}d|v r|d }t|tkrtdt||}
d|v r|d }t|tkrtdt||}d|v r2|d }t|tkr0tdt||}d|v r|d }d}t|tkr|D ]<}t|tkrQ n2d|vs_t|d tkra n"d|vsot|d tkrq nd|vst|d tkr nqFd }|std!t||||||||	|
|||d"}|S )#r   r   r8   rC   rD   z%invalid message length {0} for RESULTr6   z'request' in RESULTr7   z'details' in RESULTNrC   r8   rL   z1invalid value {0} for 'enc_algo' detail in RESULTr  z/invalid type {0} for 'enc_key' detail in RESULTrN   z7invalid value {0} for 'enc_serializer' detail in RESULTz%invalid type {0} for 'args' in RESULTz'invalid type {0} for 'kwargs' in RESULTrA  z0invalid type {0} for 'progress' option in RESULTr   z.invalid type {0} for 'callee' detail in RESULTr  z5invalid type {0} for 'callee_authid' detail in RESULTr  z7invalid type {0} for 'callee_authrole' detail in RESULTr  Fr   r   r   Tz@invalid type/value {0} for/within 'forward_for' option in RESULTr	  rz   r
  rA  rL   r  rN   r   r  r  r  )rW   r   r   r   rV   r&   r'   rH   rI   rR   r   r(   r)   r   rv   r   rt   )r   r  r   r	  rz   r
  rA  rL   r  rN   r   r  r  r  detail_progressr  r  r  r  r  r   r;   r;   r@   r     s    


zResult.parsec                 C      i }| j dur| j |d< | jdur| j|d< | jdur | j|d< | jdur*| j|d< | jdur4| j|d< | jr^| jdurA| j|d< | jdurK| j|d< | jdurU| j|d	< t	j
| j|| jgS | jrlt	j
| j|| j| jgS | jrxt	j
| j|| jgS t	j
| j|gS 
r   NrA  r   r  r  r  rL   r  rN   )rA  r   r  r  r  r
  rL   r  rN   r   r   r  rz   r	  r   r;   r;   r@   r   =  0   















zResult.marshalNNNNNNNNNNNr   r;   r;   r;   r@   r   @  s(    
b
zr   c                   @   sn   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ddZedd Zdd Zdd ZdS )r   zk
    A WAMP ``REGISTER`` message.

    Format: ``[REGISTER, Request|id, Options|dict, Procedure|uri]``
    @   r  r  r  singlefirstlast
roundrobinrandomall)r  r*  rK   invokeconcurrencyforce_reregisterr  Nc           	      C   s  t |tksJ t |tksJ |du st |tksJ |du s,|tjtjtjfv s,J |du s8t |tks8J |du sL|tjtjtj	tj
tjfv sLJ |du s\t |tkrZ|dks\J |dv sbJ |du snt |tksnJ |r|D ]:}t |tks|J d|v rt |d tksJ d|v r|d du st |d tksJ d|v rt |d tksJ qrt|  || _|| _|ptj| _|ptj| _|| _|| _|| _dS )a  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param procedure: The WAMP or application URI of the RPC endpoint provided.
        :type procedure: str

        :param match: The procedure matching policy to be used for the registration.
        :type match: str

        :param invoke: The procedure invocation policy to be used for the registration.
        :type invoke: str

        :param concurrency: The (maximum) concurrency to be used for the registration.
        :type concurrency: int

        :param forward_for: When this Register is forwarded over a router-to-router link,
            or via an intermediary router.
        :type forward_for: list[dict]
        Nr   )NTFr   r   r   )rH   rt   rI   r   r  r  r  INVOKE_SINGLEINVOKE_FIRSTINVOKE_LASTINVOKE_ROUNDROBININVOKE_RANDOMr   rv   r   r   r  r*  rK   rR  rS  rT  r  )	r   r  r*  rK   rR  rS  rT  r  r  r;   r;   r@   r     s.    ( (

zRegister.__init__c              	   C   s  t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}tj}tj}d}d}d}d	|v rb|d	 }t	|t
krOtd
t	||tjtjtjfvr`td||}|tjkrld}	d}
n|tjkrvd}	d}
n|tjkrd}	d}
ntdt| d d|	|
d}d|v r|d }t	|t
krtdt	||tjtjtjtjtjfvrtd||}d|v r|d }t	|tkrtdt	||dk rtd||}|dd}|dvrtdt	||dur|}d|v rS|d }d}t	|tkrL|D ]<}t	|tkr n2d|vs&t	|d tkr( n"d|vs6t	|d t
kr8 nd|vsFt	|d t
krH nqd}|sStdt|||||||d }|S )!r   r   rC   z'invalid message length {0} for REGISTERr6   z'request' in REGISTERr7   z'options' in REGISTERNrK   z/invalid type {0} for 'match' option in REGISTERz0invalid value {0} for 'match' option in REGISTERFTzlogic errorr8   z'procedure' in REGISTER)rh   ri   rR  z0invalid type {0} for 'invoke' option in REGISTERz1invalid value {0} for 'invoke' option in REGISTERrS  z5invalid type {0} for 'concurrency' option in REGISTERz6invalid value {0} for 'concurrency' option in REGISTERrT  )TFNz9invalid type {0} for 'force_reregister option in REGISTERr  r   r   r   zBinvalid type/value {0} for/within 'forward_for' option in REGISTER)rK   rR  rS  rT  r  )rW   r   r   r   rV   r&   r'   r  rU  rH   rI   r  r  	Exceptionr$   rV  rW  rX  rY  rt   r   r   rv   )r   r  r  rK   rR  rS  rT  r  r  rh   ri   r*  option_invokeoptions_concurrencyoptions_reregisterr  r  r   r;   r;   r@   r     s   



zRegister.parsec                 C   sx   i }| j r| j tjkr| j |d< | jr| jtjkr| j|d< | jr&| j|d< | jd ur0| j|d< | jd ur:| j|d< |S )NrK   rR  rS  rT  r  )rK   r   r  rR  rU  rS  rT  r  r  r;   r;   r@   r  &  s   






zRegister.marshal_optionsc                 C   r  r   )r   r   r  r  r*  r   r;   r;   r@   r   :  r  zRegister.marshal)NNNNN)r   r   r   r   r   r  r  r  rU  rV  rW  rX  rY  
INVOKE_ALLr   r   r   r   r  r   r;   r;   r;   r@   r   c  s0    
6
kr   c                   @   r  )r   zl
    A WAMP ``REGISTERED`` message.

    Format: ``[REGISTERED, REGISTER.Request|id, Registration|id]``
    A   )r  registrationc                 C   r  )z

        :param request: The request ID of the original ``REGISTER`` request.
        :type request: int

        :param registration: The registration ID for the registered procedure (or procedure pattern).
        :type registration: int
        N)rH   rt   r   r   r  r`  )r   r  r`  r;   r;   r@   r   U  r  zRegistered.__init__c                 C   r  )r   r   r8   z)invalid message length {0} for REGISTEREDr6   z'request' in REGISTEREDr7   z'registration' in REGISTERED)rW   r   r   r   rV   r&   )r   r  r`  r   r;   r;   r@   r   e  r  zRegistered.parsec                 C   r   r   )r   r   r  r`  r   r;   r;   r@   r   |  r   zRegistered.marshalNr   r;   r;   r;   r@   r   D  r  r   c                   @   r   )r   z
    A WAMP `UNREGISTER` message.

    Formats:

    * ``[UNREGISTER, Request|id, REGISTERED.Registration|id]``
    * ``[UNREGISTER, Request|id, REGISTERED.Registration|id, Options|dict]``
    B   )r  r`  r  Nc                 C   s@   t |tksJ t |tksJ t|  || _|| _|| _dS )a  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param registration: The registration ID for the registration to unregister.
        :type registration: int

        :param forward_for: When this Unregister is forwarded over a router-to-router link,
            or via an intermediary router.
        :type forward_for: list[dict]
        N)rH   rt   r   r   r  r`  r  )r   r  r`  r  r;   r;   r@   r     s   

zUnregister.__init__c                 C   r  )r   r   r  z.invalid message length {0} for WAMP UNREGISTERr6   z'request' in UNREGISTERr7   z'registration' in UNREGISTERNr8   z'options' in UNREGISTERr  Fr   r   r   TzDinvalid type/value {0} for/within 'forward_for' option in UNREGISTERr  )rW   r   r   r   rV   r&   r'   rH   r   rv   rt   rI   )r   r  r`  r  r  r  r  r   r;   r;   r@   r     r  zUnregister.parsec                 C   r  r  )r  r   r   r  r`  r  r;   r;   r@   r     r  zUnregister.marshalr   r   r;   r;   r;   r@   r     s    	

-r   c                   @   r   )r    z
    A WAMP ``UNREGISTERED`` message.

    Formats:

    * ``[UNREGISTERED, UNREGISTER.Request|id]``
    * ``[UNREGISTERED, UNREGISTER.Request|id, Details|dict]``
    C   )r  r`  r   Nc                 C   r  )ay  

        :param request: The request ID of the original ``UNREGISTER`` request.
        :type request: int

        :param registration: If unregister was actively triggered by router, the ID
            of the registration revoked.
        :type registration: int or None

        :param reason: The reason (an URI) for revocation.
        :type reason: str or None.
        Nr   )rH   rt   rI   r   r   r  r`  r   )r   r  r`  r   r;   r;   r@   r     s   $

zUnregistered.__init__c                 C   r  )r   r   r  z+invalid message length {0} for UNREGISTEREDr6   z'request' in UNREGISTEREDNr7   z'details' in UNREGISTEREDr`  z:invalid type {0} for 'registration' detail in UNREGISTEREDr   z'reason' in UNREGISTERED)
rW   r    r   r   rV   r&   r'   rH   rt   r$   )r   r  r`  r   r   details_registrationr   r;   r;   r@   r     r  zUnregistered.parsec                 C   r  )r   Nr   r`  )r   r`  r    r   r  r   r;   r;   r@   r   @  r  zUnregistered.marshalr  r   r;   r;   r;   r@   r      s    	

%r    c                   @   sT   e Zd ZdZdZ	 dZ														dddZedd Zd	d
 Z	dS )r!   a  
    A WAMP ``INVOCATION`` message.

    Formats:

    * ``[INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict]``
    * ``[INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list]``
    * ``[INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict]``
    * ``[INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, Payload|binary]``
    D   )r  r`  r	  rz   r
  r+  r,  r   r-  r.  r*  r8  rL   r  rN   r  Nc                 C   s  t |tksJ t |tksJ |du st |ttfv sJ |du s*t |tks*J |du s6t |tks6J |du sH|durF|du rF|du sHJ |du sTt |tksTJ |du s`t |tks`J |du slt |tkslJ |	du sxt |	tksxJ |
du st |
tksJ |du st |tksJ |du st |tksJ |du st|sJ |du st |tksJ |du st	|sJ |du r|du r|du s|dur|dusJ |du st |tksJ |r#|D ]?}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v r t |d tks"J qt
|  || _|| _|| _t|| _|| _|| _|| _|| _|	| _|
| _|| _|| _|| _|| _|| _|| _dS )a	  

        :param request: The WAMP request ID of this request.
        :type request: int

        :param registration: The registration ID of the endpoint to be invoked.
        :type registration: int

        :param args: Positional values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type args: list or tuple or None

        :param kwargs: Keyword values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param timeout: If present, let the callee automatically cancels
           the invocation after this ms.
        :type timeout: int or None

        :param receive_progress: Indicates if the callee should produce progressive results.
        :type receive_progress: bool or None

        :param caller: The WAMP session ID of the caller. Only filled if caller is disclosed.
        :type caller: None or int

        :param caller_authid: The WAMP authid of the caller. Only filled if caller is disclosed.
        :type caller_authid: None or unicode

        :param caller_authrole: The WAMP authrole of the caller. Only filled if caller is disclosed.
        :type caller_authrole: None or unicode

        :param procedure: For pattern-based registrations, the invocation MUST include the actual procedure being called.
        :type procedure: str or None

        :param transaction_hash: An application provided transaction hash for the originating call, which may
            be used in the router to throttle or deduplicate the calls on the procedure. See the discussion
            `here <https://github.com/wamp-proto/wamp-proto/issues/391#issuecomment-998577967>`_.
        :type transaction_hash: str

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None

        :param forward_for: When this Call is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   )rH   rt   r   r  rv   rR   r   rI   r(   r)   r   r   r  r`  r	  r{   rz   r
  r+  r,  r   r-  r.  r*  r8  rL   r  rN   r  )r   r  r`  r	  rz   r
  r+  r,  r   r-  r.  r*  r8  rL   r  rN   r  r  r;   r;   r@   r   v  sR   H$,."


zInvocation.__init__c                 C   s  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}t| d d	}d
}d
}d
}d
}d
}d
}	t | dkrt| d tkr| d }|	dd
}|rdt
|sdtd||	dd
}|r{t|tkr{tdt||	dd
}	|	rt|	std|	n6t | dkr| d }|d
urt|tkrtdt|t | dkr| d }t|tkrtdt|d
}
d
}d
}d
}d
}d
}d
}d
}d|v r|d }t|tkrtdt||dk rtd||}
d|v r|d }t|tkrtdt||}d|v r/|d }t|tkr-tdt||}d|v rJ|d }t|tkrHtdt||}d|v re|d }t|tkrctdt||}d |v r|d  }t|tkr~td!t||}d"|v r|d" }t|tkrtd#t||}d$|v r|d$ }d%}t|tkr|D ]<}t|tkr n2d&|vst|d& tkr n"d'|vst|d' tkr nd(|vst|d( tkr nqd)}|std*t||||||
|||||||||	|d+}|S ),r   r   r  z)invalid message length {0} for INVOCATIONr6   z'request' in INVOCATIONr7   z'registration' in INVOCATIONr8   z'details' in INVOCATIONNrD   rC   rL   z5invalid value {0} for 'enc_algo' detail in INVOCATIONr  z3invalid type {0} for 'enc_key' detail in INVOCATIONrN   z;invalid value {0} for 'enc_serializer' detail in INVOCATIONz)invalid type {0} for 'args' in INVOCATIONz+invalid type {0} for 'kwargs' in INVOCATIONr+  z3invalid type {0} for 'timeout' detail in INVOCATIONz4invalid value {0} for 'timeout' detail in INVOCATIONr,  z<invalid type {0} for 'receive_progress' detail in INVOCATIONr   z2invalid type {0} for 'caller' detail in INVOCATIONr-  z9invalid type {0} for 'caller_authid' detail in INVOCATIONr.  z;invalid type {0} for 'caller_authrole' detail in INVOCATIONr*  z5invalid type {0} for 'procedure' detail in INVOCATIONr8  r   r  Fr   r   r   TzDinvalid type/value {0} for/within 'forward_for' option in INVOCATION)r	  rz   r
  r+  r,  r   r-  r.  r*  r8  rL   r  rN   r  )rW   r!   r   r   rV   r&   r'   rH   rR   r   r(   rI   r)   r   rv   rt   r   )r   r  r`  r   r	  rz   r
  rL   r  rN   r+  r,  r   r-  r.  r*  r8  r  detail_timeoutdetail_receive_progressdetail_callerdetail_caller_authiddetail_caller_authroledetail_procedurer%  r  r  r   r;   r;   r@   r     s   






zInvocation.parsec                 C   r&  )r   Nr+  r,  r   r-  r.  r*  r8  r  rL   r  rN   )r+  r,  r   r-  r.  r*  r8  r  r
  rL   r  rN   r!   r   r  r`  rz   r	  r  r;   r;   r@   r     r'  zInvocation.marshal)NNNNNNNNNNNNNNr   r;   r;   r;   r@   r!   R  s0    
v
 r!   c                   @   s@   e Zd ZdZdZ	 dZdZdZdddZe	d	d
 Z
dd ZdS )r"   z
    A WAMP ``INTERRUPT`` message.

    Format: ``[INTERRUPT, INVOCATION.Request|id, Options|dict]``

    See: https://wamp-proto.org/static/rfc/draft-oberstet-hybi-crossbar-wamp.html#rfc.section.14.3.4
    E   r7  r8  )r  r9  r   r  Nc                 C   s  t |tksJ |du st |tksJ |du s"|| j| jfv s"J |du s.t |tks.J |du s:t |tks:J |ry|D ]:}t |tksHJ d|v rTt |d tksVJ d|v rh|d du sjt |d tksjJ d|v rvt |d tksxJ q>t|  || _	|| _
|| _|| _dS )aV  

        :param request: The WAMP request ID of the original ``INVOCATION`` to interrupt.
        :type request: int

        :param mode: Specifies how to interrupt the invocation (``"killnowait"`` or ``"kill"``).
            With ``"kill"``, the router will wait for the callee to return an ERROR before
            proceeding (sending back an ERROR to the original caller). With ``"killnowait"`` the
            router will immediately proceed (on the caller side returning an ERROR) - but still
            expects the callee to send an ERROR to conclude the message exchange for the inflight
            call.
        :type mode: str or None

        :param reason: The reason (an URI) for the invocation interrupt, eg actively
            triggered by the caller (``"wamp.error.canceled"`` - ApplicationError.CANCELED) or
            passively because of timeout (``"wamp.error.timeout"`` - ApplicationError.TIMEOUT).
        :type reason: str or None.

        :param forward_for: When this Call is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   )rH   rt   rI   r<  r;  r   rv   r   r   r  r9  r   r  )r   r  r9  r   r  r  r;   r;   r@   r     s    (

zInterrupt.__init__c           
      C   s|  t | dkr| d tjksJ t | dkrtdt | t| d d}t| d d}d}d}d}d	|v rZ|d	 }t|tkrItd
t||tj	tj
fvrXtd||}d|v ret|d d}d|v r|d }d}t|tkr|D ]4}t|tkr n+d|vst|d tkr nd|vst|d tkr nd|vst|d tkr nqwd}|stdt||||d}	|	S )r   r   r8   z(invalid message length {0} for INTERRUPTr6   z'request' in INTERRUPTr7   z'options' in INTERRUPTNr9  z/invalid type {0} for 'mode' option in INTERRUPTz2invalid value '{0}' for 'mode' option in INTERRUPTr   z"reason" in INTERRUPTr  Fr   r   r   TzCinvalid type/value {0} for/within 'forward_for' option in INTERRUPT)r9  r   r  )rW   r"   r   r   rV   r&   r'   rH   rI   r<  r;  r$   r   rv   rt   )
r   r  r  r9  r   r  r=  r  r  r   r;   r;   r@   r      sH   zInterrupt.parsec                 C   sN   i }| j dur| j |d< | jdur| j|d< | jdur | j|d< tj| j|gS )r   Nr9  r   r  )r9  r   r  r"   r   r  r  r;   r;   r@   r   =  s   





zInterrupt.marshalr  )r   r   r   r   r   r<  r;  r   r   r   r   r   r;   r;   r;   r@   r"     s    
+
<r"   c                   @   r>  )r#   aP  
    A WAMP ``YIELD`` message.

    Formats:

    * ``[YIELD, INVOCATION.Request|id, Options|dict]``
    * ``[YIELD, INVOCATION.Request|id, Options|dict, Arguments|list]``
    * ``[YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict]``
    * ``[YIELD, INVOCATION.Request|id, Options|dict, Payload|binary]``
    F   r@  Nc                 C   s<  t |tksJ |du st |ttfv sJ |du s"t |tks"J |du s.t |tks.J |du s@|dur>|du r>|du s@J |du sLt |tksLJ |du sVt|sVJ |du rb|du rb|du sl|durj|duslJ |du sxt |tksxJ |du st	|sJ |	du st |	tksJ |
du st |
tksJ |du st |tksJ |du st |tksJ |r|D ]:}t |tksJ d|v rt |d tksJ d|v r|d du st |d tksJ d|v rt |d tksJ qt
|  || _|| _t|| _|| _|| _|| _|| _|| _|	| _|
| _|| _|| _dS )aj  

        :param request: The WAMP request ID of the original call.
        :type request: int

        :param args: Positional values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type args: list or tuple or None

        :param kwargs: Keyword values for application-defined event payload.
           Must be serializable using any serializers in use.
        :type kwargs: dict or None

        :param payload: Alternative, transparent payload. If given, ``args`` and ``kwargs`` must be left unset.
        :type payload: bytes or None

        :param progress: If ``True``, this result is a progressive invocation result, and subsequent
           results (or a final error) will follow.
        :type progress: bool or None

        :param enc_algo: If using payload transparency, the encoding algorithm that was used to encode the payload.
        :type enc_algo: str or None

        :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
        :type enc_key: str or None

        :param enc_serializer: If using payload transparency, the payload object serializer that was used encoding the payload.
        :type enc_serializer: str or None

        :param callee: The WAMP session ID of the effective callee that responded with the error. Only filled if callee is disclosed.
        :type callee: None or int

        :param callee_authid: The WAMP authid of the responding callee. Only filled if callee is disclosed.
        :type callee_authid: None or unicode

        :param callee_authrole: The WAMP authrole of the responding callee. Only filled if callee is disclosed.
        :type callee_authrole: None or unicode

        :param forward_for: When this Call is forwarded for a client (or from an intermediary router).
        :type forward_for: list[dict]
        Nr   r   r   rB  rC  r;   r;   r@   r   r  sB   6$,(


zYield.__init__c                 C   s8  t | dkr| d tjksJ t | dvrtdt | t| d d}t| d d}d}d}d}d}d}d}t | d	krt| d
 tkr| d
 }|	dd}|r]t
|s]td||	dd}|rtt|tkrttdt||	dd}|rt|std|n6t | d
kr| d
 }|durt|tkrtdt|t | d	kr| d	 }t|tkrtdt|d}	d}
d}d}d}d|v r|d }t|tkrtdt||}	d|v r|d }t|tkrtdt||}
d|v r|d }t|tkrtdt||}d|v r0|d }t|tkr.tdt||}d|v r|d }d}t|tkr|D ]<}t|tkrO n2d|vs]t|d tkr_ n"d|vsmt|d tkro nd|vs}t|d tkr nqDd }|std!t|||||	||||
|||d"}|S )#r   r   rD  z$invalid message length {0} for YIELDr6   z'request' in YIELDr7   z'options' in YIELDNrC   r8   rL   z0invalid value {0} for 'enc_algo' detail in YIELDr  z.invalid type {0} for 'enc_key' detail in YIELDrN   z6invalid value {0} for 'enc_serializer' detail in YIELDz$invalid type {0} for 'args' in YIELDz&invalid type {0} for 'kwargs' in YIELDrA  z/invalid type {0} for 'progress' option in YIELDr   z-invalid type {0} for 'callee' detail in YIELDr  z4invalid type {0} for 'callee_authid' detail in YIELDr  z6invalid type {0} for 'callee_authrole' detail in YIELDr  Fr   r   r   Tz?invalid type/value {0} for/within 'forward_for' option in YIELDrE  )rW   r#   r   r   rV   r&   r'   rH   rR   r   r(   rI   r)   r   rv   r   rt   )r   r  r  r	  rz   r
  rL   r  rN   rA  r   r  r  r  option_progressoption_calleeoption_callee_authidoption_callee_authroler  r  r   r;   r;   r@   r     s   


zYield.parsec                 C   rG  rH  )rA  r   r  r  r  r
  rL   r  rN   r#   r   r  rz   r	  r  r;   r;   r@   r   M  rI  zYield.marshalrJ  r   r;   r;   r;   r@   r#   R  s(    
_
{r#   )rO   )re   FFFF)re   T)re   )`rerS   r   pprintr   typingr   r   r   r   autobahn.utilr   autobahn.wamp.exceptionr   r   autobahn.wamp.roler	   rJ  r5   autobahn.wampr
   ImportError_HAS_WAMP_FLATBUFFERS__all__compilera   rd   rb   rc   rl   ro   rm   rp   rk   rn   rJ   r+   r,   PAYLOAD_ENC_XBRr-   rM   ENC_ALGO_NONEr  r  r  	ENC_ALGOSitemsENC_ALGOS_FROMSTRENC_SER_NONEr  r  r  r  ENC_SER_OPAQUEENC_SER_FLATBUFFERSENC_SERSENC_SERS_FROMSTRr(   r)   r[   rI   r*   r   r$   r%   rt   r&   r'   r{   objectr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(  r   r   r   r   r   r   r    r!   r"   r#   r;   r;   r;   r@   <module>   s
  
%














3' 
$ 0 p vPEEf  .       XB Bne     9<  d   % bBhd  m 