You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

types.py 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. ###############################################################################
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) Crossbar.io Technologies GmbH
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. ###############################################################################
  26. from __future__ import absolute_import
  27. import six
  28. from autobahn.util import public
  29. from autobahn.wamp.request import Subscription, Registration
  30. __all__ = (
  31. 'ComponentConfig',
  32. 'HelloReturn',
  33. 'Accept',
  34. 'Deny',
  35. 'Challenge',
  36. 'HelloDetails',
  37. 'SessionDetails',
  38. 'SessionIdent',
  39. 'CloseDetails',
  40. 'SubscribeOptions',
  41. 'EventDetails',
  42. 'PublishOptions',
  43. 'RegisterOptions',
  44. 'CallDetails',
  45. 'CallOptions',
  46. 'CallResult',
  47. 'EncodedPayload'
  48. )
  49. @public
  50. class ComponentConfig(object):
  51. """
  52. WAMP application component configuration. An instance of this class is
  53. provided to the constructor of :class:`autobahn.wamp.protocol.ApplicationSession`.
  54. """
  55. __slots__ = (
  56. 'realm',
  57. 'extra',
  58. 'keyring',
  59. 'controller',
  60. 'shared',
  61. 'runner',
  62. )
  63. def __init__(self, realm=None, extra=None, keyring=None, controller=None, shared=None, runner=None):
  64. """
  65. :param realm: The realm the session would like to join or ``None`` to let the router
  66. auto-decide the realm (if the router is configured and allowing to do so).
  67. :type realm: str
  68. :param extra: Optional user-supplied object with extra configuration.
  69. This can be any object you like, and is accessible in your
  70. `ApplicationSession` subclass via `self.config.extra`. `dict` is
  71. a good default choice. Important: if the component is to be hosted
  72. by Crossbar.io, the supplied value must be JSON serializable.
  73. :type extra: arbitrary
  74. :param keyring: A mapper from WAMP URIs to "from"/"to" Ed25519 keys. When using
  75. WAMP end-to-end encryption, application payload is encrypted using a
  76. symmetric message key, which in turn is encrypted using the "to" URI (topic being
  77. published to or procedure being called) public key and the "from" URI
  78. private key. In both cases, the key for the longest matching URI is used.
  79. :type keyring: obj implementing IKeyRing or None
  80. :param controller: A WAMP ApplicationSession instance that holds a session to
  81. a controlling entity. This optional feature needs to be supported by a WAMP
  82. component hosting run-time.
  83. :type controller: instance of ApplicationSession or None
  84. :param shared: A dict object to exchange user information or hold user objects shared
  85. between components run under the same controlling entity. This optional feature
  86. needs to be supported by a WAMP component hosting run-time. Use with caution, as using
  87. this feature can introduce coupling between components. A valid use case would be
  88. to hold a shared database connection pool.
  89. :type shared: dict or None
  90. :param runner: Instance of ApplicationRunner when run under this.
  91. :type runner: :class:`autobahn.twisted.wamp.ApplicationRunner`
  92. """
  93. assert(realm is None or type(realm) == six.text_type)
  94. # assert(keyring is None or ...) # FIXME
  95. self.realm = realm
  96. self.extra = extra
  97. self.keyring = keyring
  98. self.controller = controller
  99. self.shared = shared
  100. self.runner = runner
  101. def __str__(self):
  102. return u"ComponentConfig(realm=<{}>, extra={}, keyring={}, controller={}, shared={}, runner={})".format(self.realm, self.extra, self.keyring, self.controller, self.shared, self.runner)
  103. @public
  104. class HelloReturn(object):
  105. """
  106. Base class for ``HELLO`` return information.
  107. """
  108. @public
  109. class Accept(HelloReturn):
  110. """
  111. Information to accept a ``HELLO``.
  112. """
  113. __slots__ = (
  114. 'realm',
  115. 'authid',
  116. 'authrole',
  117. 'authmethod',
  118. 'authprovider',
  119. 'authextra',
  120. )
  121. def __init__(self, realm=None, authid=None, authrole=None, authmethod=None, authprovider=None, authextra=None):
  122. """
  123. :param realm: The realm the client is joined to.
  124. :type realm: str
  125. :param authid: The authentication ID the client is assigned, e.g. ``"joe"`` or ``"joe@example.com"``.
  126. :type authid: str
  127. :param authrole: The authentication role the client is assigned, e.g. ``"anonymous"``, ``"user"`` or ``"com.myapp.user"``.
  128. :type authrole: str
  129. :param authmethod: The authentication method that was used to authenticate the client, e.g. ``"cookie"`` or ``"wampcra"``.
  130. :type authmethod: str
  131. :param authprovider: The authentication provider that was used to authenticate the client, e.g. ``"mozilla-persona"``.
  132. :type authprovider: str
  133. :param authextra: Application-specific authextra to be forwarded to the client in `WELCOME.details.authextra`.
  134. :type authextra: dict
  135. """
  136. assert(realm is None or type(realm) == six.text_type)
  137. assert(authid is None or type(authid) == six.text_type)
  138. assert(authrole is None or type(authrole) == six.text_type)
  139. assert(authmethod is None or type(authmethod) == six.text_type)
  140. assert(authprovider is None or type(authprovider) == six.text_type)
  141. assert(authextra is None or type(authextra) == dict)
  142. self.realm = realm
  143. self.authid = authid
  144. self.authrole = authrole
  145. self.authmethod = authmethod
  146. self.authprovider = authprovider
  147. self.authextra = authextra
  148. def __str__(self):
  149. return u"Accept(realm=<{}>, authid=<{}>, authrole=<{}>, authmethod={}, authprovider={}, authextra={})".format(self.realm, self.authid, self.authrole, self.authmethod, self.authprovider, self.authextra)
  150. @public
  151. class Deny(HelloReturn):
  152. """
  153. Information to deny a ``HELLO``.
  154. """
  155. __slots__ = (
  156. 'reason',
  157. 'message',
  158. )
  159. def __init__(self, reason=u'wamp.error.not_authorized', message=None):
  160. """
  161. :param reason: The reason of denying the authentication (an URI, e.g. ``u'wamp.error.not_authorized'``)
  162. :type reason: str
  163. :param message: A human readable message (for logging purposes).
  164. :type message: str
  165. """
  166. assert(type(reason) == six.text_type)
  167. assert(message is None or type(message) == six.text_type)
  168. self.reason = reason
  169. self.message = message
  170. def __str__(self):
  171. return u"Deny(reason=<{}>, message='{}')".format(self.reason, self.message)
  172. @public
  173. class Challenge(HelloReturn):
  174. """
  175. Information to challenge the client upon ``HELLO``.
  176. """
  177. __slots__ = (
  178. 'method',
  179. 'extra',
  180. )
  181. def __init__(self, method, extra=None):
  182. """
  183. :param method: The authentication method for the challenge (e.g. ``"wampcra"``).
  184. :type method: str
  185. :param extra: Any extra information for the authentication challenge. This is
  186. specific to the authentication method.
  187. :type extra: dict
  188. """
  189. assert(type(method) == six.text_type)
  190. assert(extra is None or type(extra) == dict)
  191. self.method = method
  192. self.extra = extra or {}
  193. def __str__(self):
  194. return u"Challenge(method={}, extra={})".format(self.method, self.extra)
  195. @public
  196. class HelloDetails(object):
  197. """
  198. Provides details of a WAMP session while still attaching.
  199. """
  200. __slots__ = (
  201. 'realm',
  202. 'authmethods',
  203. 'authid',
  204. 'authrole',
  205. 'authextra',
  206. 'session_roles',
  207. 'pending_session',
  208. 'resumable',
  209. 'resume_session',
  210. 'resume_token',
  211. )
  212. def __init__(self, realm=None, authmethods=None, authid=None, authrole=None, authextra=None, session_roles=None, pending_session=None, resumable=None, resume_session=None, resume_token=None):
  213. """
  214. :param realm: The realm the client wants to join.
  215. :type realm: str or None
  216. :param authmethods: The authentication methods the client is willing to perform.
  217. :type authmethods: list of str or None
  218. :param authid: The authid the client wants to authenticate as.
  219. :type authid: str or None
  220. :param authrole: The authrole the client wants to authenticate as.
  221. :type authrole: str or None
  222. :param authextra: Any extra information the specific authentication method requires the client to send.
  223. :type authextra: arbitrary or None
  224. :param session_roles: The WAMP session roles and features by the connecting client.
  225. :type session_roles: dict or None
  226. :param pending_session: The session ID the session will get once successfully attached.
  227. :type pending_session: int or None
  228. :param resumable:
  229. :type resumable: bool or None
  230. :param resume_session: The session the client would like to resume.
  231. :type resume_session: int or None
  232. :param resume_token: The secure authorisation token to resume the session.
  233. :type resume_token: str or None
  234. """
  235. assert(realm is None or type(realm) == six.text_type)
  236. assert(authmethods is None or (type(authmethods) == list and all(type(x) == six.text_type for x in authmethods)))
  237. assert(authid is None or type(authid) == six.text_type)
  238. assert(authrole is None or type(authrole) == six.text_type)
  239. assert(authextra is None or type(authextra) == dict)
  240. # assert(session_roles is None or ...) # FIXME
  241. assert(pending_session is None or type(pending_session) in six.integer_types)
  242. assert(resumable is None or type(resumable) == bool)
  243. assert(resume_session is None or type(resume_session) == int)
  244. assert(resume_token is None or type(resume_token) == six.text_type)
  245. self.realm = realm
  246. self.authmethods = authmethods
  247. self.authid = authid
  248. self.authrole = authrole
  249. self.authextra = authextra
  250. self.session_roles = session_roles
  251. self.pending_session = pending_session
  252. self.resumable = resumable
  253. self.resume_session = resume_session
  254. self.resume_token = resume_token
  255. def __str__(self):
  256. return u"HelloDetails(realm=<{}>, authmethods={}, authid=<{}>, authrole=<{}>, authextra={}, session_roles={}, pending_session={}, resumable={}, resume_session={}, resume_token={})".format(self.realm, self.authmethods, self.authid, self.authrole, self.authextra, self.session_roles, self.pending_session, self.resumable, self.resume_session, self.resume_token)
  257. @public
  258. class SessionDetails(object):
  259. """
  260. Provides details for a WAMP session upon open.
  261. .. seealso:: :func:`autobahn.wamp.interfaces.ISession.onJoin`
  262. """
  263. __slots__ = (
  264. 'realm',
  265. 'session',
  266. 'authid',
  267. 'authrole',
  268. 'authmethod',
  269. 'authprovider',
  270. 'authextra',
  271. 'serializer',
  272. 'resumed',
  273. 'resumable',
  274. 'resume_token',
  275. )
  276. def __init__(self, realm, session, authid=None, authrole=None, authmethod=None, authprovider=None, authextra=None,
  277. serializer=None, resumed=None, resumable=None, resume_token=None):
  278. """
  279. :param realm: The realm this WAMP session is attached to.
  280. :type realm: str
  281. :param session: WAMP session ID of this session.
  282. :type session: int
  283. :param resumed: Whether the session is a resumed one.
  284. :type resumed: bool or None
  285. :param resumable: Whether this session can be resumed later.
  286. :type resumable: bool or None
  287. :param resume_token: The secure authorisation token to resume the session.
  288. :type resume_token: str or None
  289. """
  290. assert(type(realm) == six.text_type)
  291. assert(type(session) in six.integer_types)
  292. assert(authid is None or type(authid) == six.text_type)
  293. assert(authrole is None or type(authrole) == six.text_type)
  294. assert(authmethod is None or type(authmethod) == six.text_type)
  295. assert(authprovider is None or type(authprovider) == six.text_type)
  296. assert(authextra is None or type(authextra) == dict)
  297. assert(serializer is None or type(serializer) == six.text_type)
  298. assert(resumed is None or type(resumed) == bool)
  299. assert(resumable is None or type(resumable) == bool)
  300. assert(resume_token is None or type(resume_token) == six.text_type)
  301. self.realm = realm
  302. self.session = session
  303. self.authid = authid
  304. self.authrole = authrole
  305. self.authmethod = authmethod
  306. self.authprovider = authprovider
  307. self.authextra = authextra
  308. self.serializer = serializer
  309. self.resumed = resumed
  310. self.resumable = resumable
  311. self.resume_token = resume_token
  312. def marshal(self):
  313. obj = {
  314. u'realm': self.realm,
  315. u'session': self.session,
  316. u'authid': self.authid,
  317. u'authrole': self.authrole,
  318. u'authmethod': self.authmethod,
  319. u'authprovider': self.authprovider,
  320. u'authextra': self.authextra,
  321. u'serializer': self.serializer,
  322. u'resumed': self.resumed,
  323. u'resumable': self.resumable,
  324. u'resume_token': self.resume_token
  325. }
  326. return obj
  327. def __str__(self):
  328. return u"""
  329. SessionDetails(realm=<{}>,
  330. session={},
  331. authid=<{}>,
  332. authrole=<{}>,
  333. authmethod={},
  334. authprovider={},
  335. authextra={},
  336. serializer=<{}>,
  337. resumed={},
  338. resumable={},
  339. resume_token={})""".format(self.realm, self.session, self.authid, self.authrole, self.authmethod, self.authprovider, self.authextra, self.serializer, self.resumed, self.resumable, self.resume_token)
  340. @public
  341. class SessionIdent(object):
  342. """
  343. WAMP session identification information.
  344. A WAMP session joined on a realm on a WAMP router is identified technically
  345. by its session ID (``session``) already.
  346. The permissions the session has are tied to the WAMP authentication role (``authrole``).
  347. The subject behind the session, eg the user or the application component is identified
  348. by the WAMP authentication ID (``authid``). One session is always authenticated under/as
  349. one specific ``authid``, but a given ``authid`` might have zero, one or many sessions
  350. joined on a router at the same time.
  351. """
  352. __slots__ = (
  353. 'session',
  354. 'authid',
  355. 'authrole',
  356. )
  357. def __init__(self, session=None, authid=None, authrole=None):
  358. """
  359. :param session: WAMP session ID of the session.
  360. :type session: int
  361. :param authid: The WAMP authid of the session.
  362. :type authid: str
  363. :param authrole: The WAMP authrole of the session.
  364. :type authrole: str
  365. """
  366. assert(session is None or type(session) in six.integer_types)
  367. assert(authid is None or type(authid) == six.text_type)
  368. assert(type(authrole) == six.text_type)
  369. self.session = session
  370. self.authid = authid
  371. self.authrole = authrole
  372. def __str__(self):
  373. return u"SessionIdent(session={}, authid={}, authrole={})".format(self.session, self.authid, self.authrole)
  374. def marshal(self):
  375. obj = {
  376. u'session': self.session,
  377. u'authid': self.authid,
  378. u'authrole': self.authrole,
  379. }
  380. return obj
  381. @staticmethod
  382. def from_calldetails(call_details):
  383. """
  384. Create a new session identification object from the caller information
  385. in the call details provided.
  386. :param call_details: Details of a WAMP call.
  387. :type call_details: :class:`autobahn.wamp.types.CallDetails`
  388. :returns: New session identification object.
  389. :rtype: :class:`autobahn.wamp.types.SessionIdent`
  390. """
  391. assert isinstance(call_details, CallDetails)
  392. if call_details.forward_for:
  393. caller = call_details.forward_for[0]
  394. session_ident = SessionIdent(caller['session'],
  395. caller['authid'],
  396. caller['authrole'])
  397. else:
  398. session_ident = SessionIdent(call_details.caller,
  399. call_details.caller_authid,
  400. call_details.caller_authrole)
  401. return session_ident
  402. @staticmethod
  403. def from_eventdetails(event_details):
  404. """
  405. Create a new session identification object from the publisher information
  406. in the event details provided.
  407. :param event_details: Details of a WAMP event.
  408. :type event_details: :class:`autobahn.wamp.types.EventDetails`
  409. :returns: New session identification object.
  410. :rtype: :class:`autobahn.wamp.types.SessionIdent`
  411. """
  412. assert isinstance(event_details, EventDetails)
  413. if event_details.forward_for:
  414. publisher = event_details.forward_for[0]
  415. session_ident = SessionIdent(publisher['session'],
  416. publisher['authid'],
  417. publisher['authrole'])
  418. else:
  419. session_ident = SessionIdent(event_details.publisher,
  420. event_details.publisher_authid,
  421. event_details.publisher_authrole)
  422. return session_ident
  423. @public
  424. class CloseDetails(object):
  425. """
  426. Provides details for a WAMP session upon close.
  427. .. seealso:: :func:`autobahn.wamp.interfaces.ISession.onLeave`
  428. """
  429. REASON_DEFAULT = u"wamp.close.normal"
  430. REASON_TRANSPORT_LOST = u"wamp.close.transport_lost"
  431. __slots__ = (
  432. 'reason',
  433. 'message',
  434. )
  435. def __init__(self, reason=None, message=None):
  436. """
  437. :param reason: The close reason (an URI, e.g. ``wamp.close.normal``)
  438. :type reason: str
  439. :param message: Closing log message.
  440. :type message: str
  441. """
  442. assert(reason is None or type(reason) == six.text_type)
  443. assert(message is None or type(message) == six.text_type)
  444. self.reason = reason
  445. self.message = message
  446. def marshal(self):
  447. obj = {
  448. u'reason': self.reason,
  449. u'message': self.message
  450. }
  451. return obj
  452. def __str__(self):
  453. return u"CloseDetails(reason=<{}>, message='{}')".format(self.reason, self.message)
  454. @public
  455. class SubscribeOptions(object):
  456. """
  457. Used to provide options for subscribing in
  458. :func:`autobahn.wamp.interfaces.ISubscriber.subscribe`.
  459. """
  460. __slots__ = (
  461. 'match',
  462. 'details',
  463. 'details_arg',
  464. 'get_retained',
  465. 'forward_for',
  466. 'correlation_id',
  467. 'correlation_uri',
  468. 'correlation_is_anchor',
  469. 'correlation_is_last',
  470. )
  471. def __init__(self, match=None, details=None, details_arg=None, forward_for=None, get_retained=None,
  472. correlation_id=None, correlation_uri=None, correlation_is_anchor=None,
  473. correlation_is_last=None):
  474. """
  475. :param match: The topic matching method to be used for the subscription.
  476. :type match: str
  477. :param details: When invoking the handler, provide event details in a keyword
  478. parameter ``details``.
  479. :type details: bool
  480. :param details_arg: DEPCREATED (use "details" flag). When invoking the handler
  481. provide event details in this keyword argument to the callable.
  482. :type details_arg: str
  483. :param get_retained: Whether the client wants the retained message we may have along with the subscription.
  484. :type get_retained: bool or None
  485. """
  486. assert(match is None or (type(match) == six.text_type and match in [u'exact', u'prefix', u'wildcard']))
  487. assert(details is None or (type(details) == bool and details_arg is None))
  488. assert(details_arg is None or type(details_arg) == str) # yes, "str" is correct here, since this is about Python identifiers!
  489. assert(get_retained is None or type(get_retained) is bool)
  490. assert(forward_for is None or type(forward_for) == list)
  491. if forward_for:
  492. for ff in forward_for:
  493. assert type(ff) == dict
  494. assert 'session' in ff and type(ff['session']) in six.integer_types
  495. assert 'authid' in ff and (ff['authid'] is None or type(ff['authid']) == six.text_type)
  496. assert 'authrole' in ff and type(ff['authrole']) == six.text_type
  497. self.match = match
  498. # FIXME: this is for backwards compat, but we'll deprecate it in the future
  499. self.details = details
  500. if details:
  501. self.details_arg = 'details'
  502. else:
  503. self.details_arg = details_arg
  504. self.get_retained = get_retained
  505. self.forward_for = forward_for
  506. self.correlation_id = correlation_id
  507. self.correlation_uri = correlation_uri
  508. self.correlation_is_anchor = correlation_is_anchor
  509. self.correlation_is_last = correlation_is_last
  510. def message_attr(self):
  511. """
  512. Returns options dict as sent within WAMP messages.
  513. """
  514. options = {}
  515. if self.match is not None:
  516. options[u'match'] = self.match
  517. if self.get_retained is not None:
  518. options[u'get_retained'] = self.get_retained
  519. if self.forward_for is not None:
  520. options[u'forward_for'] = self.forward_for
  521. return options
  522. def __str__(self):
  523. return u"SubscribeOptions(match={}, details={}, details_arg={}, get_retained={}, forward_for={})".format(self.match, self.details, self.details_arg, self.get_retained, self.forward_for)
  524. @public
  525. class EventDetails(object):
  526. """
  527. Provides details on an event when calling an event handler
  528. previously registered.
  529. """
  530. __slots__ = (
  531. 'subscription',
  532. 'publication',
  533. 'publisher',
  534. 'publisher_authid',
  535. 'publisher_authrole',
  536. 'topic',
  537. 'retained',
  538. 'enc_algo',
  539. 'forward_for',
  540. )
  541. def __init__(self, subscription, publication, publisher=None, publisher_authid=None, publisher_authrole=None,
  542. topic=None, retained=None, enc_algo=None, forward_for=None):
  543. """
  544. :param subscription: The (client side) subscription object on which this event is delivered.
  545. :type subscription: instance of :class:`autobahn.wamp.request.Subscription`
  546. :param publication: The publication ID of the event (always present).
  547. :type publication: int
  548. :param publisher: The WAMP session ID of the original publisher of this event.
  549. Only filled when publisher is disclosed.
  550. :type publisher: None or int
  551. :param publisher_authid: The WAMP authid of the original publisher of this event.
  552. Only filled when publisher is disclosed.
  553. :type publisher_authid: str or None
  554. :param publisher_authrole: The WAMP authrole of the original publisher of this event.
  555. Only filled when publisher is disclosed.
  556. :type publisher_authrole: str or None
  557. :param topic: For pattern-based subscriptions, the actual topic URI being published to.
  558. Only filled for pattern-based subscriptions.
  559. :type topic: str or None
  560. :param retained: Whether the message was retained by the broker on the topic, rather than just published.
  561. :type retained: bool or None
  562. :param enc_algo: Payload encryption algorithm that
  563. was in use (currently, either ``None`` or ``u'cryptobox'``).
  564. :type enc_algo: str or None
  565. :param forward_for: When this Event is forwarded for a client (or from an intermediary router).
  566. :type forward_for: list[dict]
  567. """
  568. assert(isinstance(subscription, Subscription))
  569. assert(type(publication) in six.integer_types)
  570. assert(publisher is None or type(publisher) in six.integer_types)
  571. assert(publisher_authid is None or type(publisher_authid) == six.text_type)
  572. assert(publisher_authrole is None or type(publisher_authrole) == six.text_type)
  573. assert(topic is None or type(topic) == six.text_type)
  574. assert(retained is None or type(retained) is bool)
  575. assert(enc_algo is None or type(enc_algo) == six.text_type)
  576. assert(forward_for is None or type(forward_for) == list)
  577. if forward_for:
  578. for ff in forward_for:
  579. assert type(ff) == dict
  580. assert 'session' in ff and type(ff['session']) in six.integer_types
  581. assert 'authid' in ff and (ff['authid'] is None or type(ff['authid']) == six.text_type)
  582. assert 'authrole' in ff and type(ff['authrole']) == six.text_type
  583. self.subscription = subscription
  584. self.publication = publication
  585. self.publisher = publisher
  586. self.publisher_authid = publisher_authid
  587. self.publisher_authrole = publisher_authrole
  588. self.topic = topic
  589. self.retained = retained
  590. self.enc_algo = enc_algo
  591. self.forward_for = forward_for
  592. def __str__(self):
  593. return u"EventDetails(subscription={}, publication={}, publisher={}, publisher_authid={}, publisher_authrole={}, topic=<{}>, retained={}, enc_algo={}, forward_for={})".format(self.subscription, self.publication, self.publisher, self.publisher_authid, self.publisher_authrole, self.topic, self.retained, self.enc_algo, self.forward_for)
  594. @public
  595. class PublishOptions(object):
  596. """
  597. Used to provide options for subscribing in
  598. :func:`autobahn.wamp.interfaces.IPublisher.publish`.
  599. """
  600. __slots__ = (
  601. 'acknowledge',
  602. 'exclude_me',
  603. 'exclude',
  604. 'exclude_authid',
  605. 'exclude_authrole',
  606. 'eligible',
  607. 'eligible_authid',
  608. 'eligible_authrole',
  609. 'retain',
  610. 'forward_for',
  611. 'correlation_id',
  612. 'correlation_uri',
  613. 'correlation_is_anchor',
  614. 'correlation_is_last',
  615. )
  616. def __init__(self,
  617. acknowledge=None,
  618. exclude_me=None,
  619. exclude=None,
  620. exclude_authid=None,
  621. exclude_authrole=None,
  622. eligible=None,
  623. eligible_authid=None,
  624. eligible_authrole=None,
  625. retain=None,
  626. forward_for=None,
  627. correlation_id=None,
  628. correlation_uri=None,
  629. correlation_is_anchor=None,
  630. correlation_is_last=None):
  631. """
  632. :param acknowledge: If ``True``, acknowledge the publication with a success or
  633. error response.
  634. :type acknowledge: bool
  635. :param exclude_me: If ``True``, exclude the publisher from receiving the event, even
  636. if he is subscribed (and eligible).
  637. :type exclude_me: bool or None
  638. :param exclude: A single WAMP session ID or a list thereof to exclude from receiving this event.
  639. :type exclude: int or list of int or None
  640. :param exclude_authid: A single WAMP authid or a list thereof to exclude from receiving this event.
  641. :type exclude_authid: str or list of str or None
  642. :param exclude_authrole: A single WAMP authrole or a list thereof to exclude from receiving this event.
  643. :type exclude_authrole: list of str or None
  644. :param eligible: A single WAMP session ID or a list thereof eligible to receive this event.
  645. :type eligible: int or list of int or None
  646. :param eligible_authid: A single WAMP authid or a list thereof eligible to receive this event.
  647. :type eligible_authid: str or list of str or None
  648. :param eligible_authrole: A single WAMP authrole or a list thereof eligible to receive this event.
  649. :type eligible_authrole: str or list of str or None
  650. :param retain: If ``True``, request the broker retain this event.
  651. :type retain: bool or None
  652. :param forward_for: When this Event is forwarded for a client (or from an intermediary router).
  653. :type forward_for: list[dict]
  654. """
  655. assert(acknowledge is None or type(acknowledge) == bool)
  656. assert(exclude_me is None or type(exclude_me) == bool)
  657. assert(exclude is None or type(exclude) in six.integer_types or (type(exclude) == list and all(type(x) in six.integer_types for x in exclude)))
  658. assert(exclude_authid is None or type(exclude_authid) == six.text_type or (type(exclude_authid) == list and all(type(x) == six.text_type for x in exclude_authid)))
  659. assert(exclude_authrole is None or type(exclude_authrole) == six.text_type or (type(exclude_authrole) == list and all(type(x) == six.text_type for x in exclude_authrole)))
  660. assert(eligible is None or type(eligible) in six.integer_types or (type(eligible) == list and all(type(x) in six.integer_types for x in eligible)))
  661. assert(eligible_authid is None or type(eligible_authid) == six.text_type or (type(eligible_authid) == list and all(type(x) == six.text_type for x in eligible_authid)))
  662. assert(eligible_authrole is None or type(eligible_authrole) == six.text_type or (type(eligible_authrole) == list and all(type(x) == six.text_type for x in eligible_authrole)))
  663. assert(retain is None or type(retain) == bool)
  664. assert(forward_for is None or type(forward_for) == list), 'forward_for, when present, must have list type - was {}'.format(type(forward_for))
  665. if forward_for:
  666. for ff in forward_for:
  667. assert type(ff) == dict, 'forward_for must be type dict - was {}'.format(type(ff))
  668. assert 'session' in ff, 'forward_for must have session attribute'
  669. assert type(ff['session']) in six.integer_types, 'forward_for.session must have integer type - was {}'.format(type(ff['session']))
  670. assert 'authid' in ff, 'forward_for must have authid attributed'
  671. assert type(ff['authid']) == six.text_type, 'forward_for.authid must have str type - was {}'.format(type(ff['authid']))
  672. assert 'authrole' in ff, 'forward_for must have authrole attribute'
  673. assert type(ff['authrole']) == six.text_type, 'forward_for.authrole must have str type - was {}'.format(type(ff['authrole']))
  674. self.acknowledge = acknowledge
  675. self.exclude_me = exclude_me
  676. self.exclude = exclude
  677. self.exclude_authid = exclude_authid
  678. self.exclude_authrole = exclude_authrole
  679. self.eligible = eligible
  680. self.eligible_authid = eligible_authid
  681. self.eligible_authrole = eligible_authrole
  682. self.retain = retain
  683. self.forward_for = forward_for
  684. self.correlation_id = correlation_id
  685. self.correlation_uri = correlation_uri
  686. self.correlation_is_anchor = correlation_is_anchor
  687. self.correlation_is_last = correlation_is_last
  688. def message_attr(self):
  689. """
  690. Returns options dict as sent within WAMP messages.
  691. """
  692. options = {}
  693. if self.acknowledge is not None:
  694. options[u'acknowledge'] = self.acknowledge
  695. if self.exclude_me is not None:
  696. options[u'exclude_me'] = self.exclude_me
  697. if self.exclude is not None:
  698. options[u'exclude'] = self.exclude if type(self.exclude) == list else [self.exclude]
  699. if self.exclude_authid is not None:
  700. options[u'exclude_authid'] = self.exclude_authid if type(self.exclude_authid) == list else [self.exclude_authid]
  701. if self.exclude_authrole is not None:
  702. options[u'exclude_authrole'] = self.exclude_authrole if type(self.exclude_authrole) == list else [self.exclude_authrole]
  703. if self.eligible is not None:
  704. options[u'eligible'] = self.eligible if type(self.eligible) == list else [self.eligible]
  705. if self.eligible_authid is not None:
  706. options[u'eligible_authid'] = self.eligible_authid if type(self.eligible_authid) == list else [self.eligible_authid]
  707. if self.eligible_authrole is not None:
  708. options[u'eligible_authrole'] = self.eligible_authrole if type(self.eligible_authrole) == list else [self.eligible_authrole]
  709. if self.retain is not None:
  710. options[u'retain'] = self.retain
  711. if self.forward_for is not None:
  712. options[u'forward_for'] = self.forward_for
  713. return options
  714. def __str__(self):
  715. return u"PublishOptions(acknowledge={}, exclude_me={}, exclude={}, exclude_authid={}, exclude_authrole={}, eligible={}, eligible_authid={}, eligible_authrole={}, retain={}, forward_for={})".format(self.acknowledge, self.exclude_me, self.exclude, self.exclude_authid, self.exclude_authrole, self.eligible, self.eligible_authid, self.eligible_authrole, self.retain, self.forward_for)
  716. @public
  717. class RegisterOptions(object):
  718. """
  719. Used to provide options for registering in
  720. :func:`autobahn.wamp.interfaces.ICallee.register`.
  721. """
  722. __slots__ = (
  723. 'match',
  724. 'invoke',
  725. 'concurrency',
  726. 'force_reregister',
  727. 'forward_for',
  728. 'details',
  729. 'details_arg',
  730. 'correlation_id',
  731. 'correlation_uri',
  732. 'correlation_is_anchor',
  733. 'correlation_is_last',
  734. )
  735. def __init__(self, match=None, invoke=None, concurrency=None, force_reregister=None, forward_for=None,
  736. details=None, details_arg=None, correlation_id=None, correlation_uri=None,
  737. correlation_is_anchor=None, correlation_is_last=None):
  738. """
  739. :param match: Type of matching to use on the URI (`exact`, `prefix` or `wildcard`)
  740. :param invoke: Type of invoke mechanism to use (`single`, `first`, `last`, `roundrobin`, `random`)
  741. :param concurrency: if used, the number of times a particular
  742. endpoint may be called concurrently (e.g. if this is 3, and
  743. there are already 3 calls in-progress a 4th call will receive
  744. an error)
  745. :param details_arg: When invoking the endpoint, provide call details
  746. in this keyword argument to the callable.
  747. :type details_arg: str
  748. :param details: When invoking the endpoint, provide call details in a keyword
  749. parameter ``details``.
  750. :type details: bool
  751. :param details_arg: DEPCREATED (use "details" flag). When invoking the endpoint,
  752. provide call details in this keyword argument to the callable.
  753. :type details_arg: str
  754. :param force_reregister: if True, any other session that has
  755. already registered this URI will be 'kicked out' and this
  756. session will become the one that's registered (the previous
  757. session must have used `force_reregister=True` as well)
  758. :type force_reregister: bool
  759. :param forward_for: When this Register is forwarded over a router-to-router link,
  760. or via an intermediary router.
  761. :type forward_for: list[dict]
  762. """
  763. assert(match is None or (type(match) == six.text_type and match in [u'exact', u'prefix', u'wildcard']))
  764. assert(invoke is None or (type(invoke) == six.text_type and invoke in [u'single', u'first', u'last', u'roundrobin', u'random']))
  765. assert(concurrency is None or (type(concurrency) in six.integer_types and concurrency > 0))
  766. assert(details is None or (type(details) == bool and details_arg is None))
  767. assert(details_arg is None or type(details_arg) == str) # yes, "str" is correct here, since this is about Python identifiers!
  768. assert force_reregister in [None, True, False]
  769. assert(forward_for is None or type(forward_for) == list)
  770. if forward_for:
  771. for ff in forward_for:
  772. assert type(ff) == dict
  773. assert 'session' in ff and type(ff['session']) in six.integer_types
  774. assert 'authid' in ff and (ff['authid'] is None or type(ff['authid']) == six.text_type)
  775. assert 'authrole' in ff and type(ff['authrole']) == six.text_type
  776. self.match = match
  777. self.invoke = invoke
  778. self.concurrency = concurrency
  779. self.force_reregister = force_reregister
  780. self.forward_for = forward_for
  781. # FIXME: this is for backwards compat, but we'll deprecate it in the future
  782. self.details = details
  783. if details:
  784. self.details_arg = 'details'
  785. else:
  786. self.details_arg = details_arg
  787. self.correlation_id = correlation_id
  788. self.correlation_uri = correlation_uri
  789. self.correlation_is_anchor = correlation_is_anchor
  790. self.correlation_is_last = correlation_is_last
  791. def message_attr(self):
  792. """
  793. Returns options dict as sent within WAMP messages.
  794. """
  795. options = {}
  796. if self.match is not None:
  797. options[u'match'] = self.match
  798. if self.invoke is not None:
  799. options[u'invoke'] = self.invoke
  800. if self.concurrency is not None:
  801. options[u'concurrency'] = self.concurrency
  802. if self.force_reregister is not None:
  803. options[u'force_reregister'] = self.force_reregister
  804. if self.forward_for is not None:
  805. options[u'forward_for'] = self.forward_for
  806. return options
  807. def __str__(self):
  808. return u"RegisterOptions(match={}, invoke={}, concurrency={}, details={}, details_arg={}, force_reregister={}, forward_for={})".format(self.match, self.invoke, self.concurrency, self.details, self.details_arg, self.force_reregister, self.forward_for)
  809. @public
  810. class CallDetails(object):
  811. """
  812. Provides details on a call when an endpoint previously
  813. registered is being called and opted to receive call details.
  814. """
  815. __slots__ = (
  816. 'registration',
  817. 'progress',
  818. 'caller',
  819. 'caller_authid',
  820. 'caller_authrole',
  821. 'procedure',
  822. 'enc_algo',
  823. 'forward_for',
  824. )
  825. def __init__(self, registration, progress=None, caller=None, caller_authid=None,
  826. caller_authrole=None, procedure=None, enc_algo=None, forward_for=None):
  827. """
  828. :param registration: The (client side) registration object this invocation is delivered on.
  829. :type registration: instance of :class:`autobahn.wamp.request.Registration`
  830. :param progress: A callable that will receive progressive call results.
  831. :type progress: callable or None
  832. :param caller: The WAMP session ID of the caller, if the latter is disclosed.
  833. Only filled when caller is disclosed.
  834. :type caller: int or None
  835. :param caller_authid: The WAMP authid of the original caller of this event.
  836. Only filled when caller is disclosed.
  837. :type caller_authid: str or None
  838. :param caller_authrole: The WAMP authrole of the original caller of this event.
  839. Only filled when caller is disclosed.
  840. :type caller_authrole: str or None
  841. :param procedure: For pattern-based registrations, the actual procedure URI being called.
  842. :type procedure: str or None
  843. :param enc_algo: Payload encryption algorithm that
  844. was in use (currently, either `None` or `"cryptobox"`).
  845. :type enc_algo: str or None
  846. :param forward_for: When this Call is forwarded for a client (or from an intermediary router).
  847. :type forward_for: list[dict]
  848. """
  849. assert(isinstance(registration, Registration))
  850. assert(progress is None or callable(progress))
  851. assert(caller is None or type(caller) in six.integer_types)
  852. assert(caller_authid is None or type(caller_authid) == six.text_type)
  853. assert(caller_authrole is None or type(caller_authrole) == six.text_type)
  854. assert(procedure is None or type(procedure) == six.text_type)
  855. assert(enc_algo is None or type(enc_algo) == six.text_type)
  856. assert(forward_for is None or type(forward_for) == list)
  857. if forward_for:
  858. for ff in forward_for:
  859. assert type(ff) == dict
  860. assert 'session' in ff and type(ff['session']) in six.integer_types
  861. assert 'authid' in ff and (ff['authid'] is None or type(ff['authid']) == six.text_type)
  862. assert 'authrole' in ff and type(ff['authrole']) == six.text_type
  863. self.registration = registration
  864. self.progress = progress
  865. self.caller = caller
  866. self.caller_authid = caller_authid
  867. self.caller_authrole = caller_authrole
  868. self.procedure = procedure
  869. self.enc_algo = enc_algo
  870. self.forward_for = forward_for
  871. def __str__(self):
  872. return u"CallDetails(registration={}, progress={}, caller={}, caller_authid={}, caller_authrole={}, procedure=<{}>, enc_algo={}, forward_for={})".format(self.registration, self.progress, self.caller, self.caller_authid, self.caller_authrole, self.procedure, self.enc_algo, self.forward_for)
  873. @public
  874. class CallOptions(object):
  875. """
  876. Used to provide options for calling with :func:`autobahn.wamp.interfaces.ICaller.call`.
  877. """
  878. __slots__ = (
  879. 'on_progress',
  880. 'timeout',
  881. 'caller',
  882. 'caller_authid',
  883. 'caller_authrole',
  884. 'forward_for',
  885. 'correlation_id',
  886. 'correlation_uri',
  887. 'correlation_is_anchor',
  888. 'correlation_is_last',
  889. 'details',
  890. )
  891. def __init__(self,
  892. on_progress=None,
  893. timeout=None,
  894. caller=None,
  895. caller_authid=None,
  896. caller_authrole=None,
  897. forward_for=None,
  898. correlation_id=None,
  899. correlation_uri=None,
  900. correlation_is_anchor=None,
  901. correlation_is_last=None,
  902. details=None):
  903. """
  904. :param on_progress: A callback that will be called when the remote endpoint
  905. called yields interim call progress results.
  906. :type on_progress: callable
  907. :param timeout: Time in seconds after which the call should be automatically canceled.
  908. :type timeout: float
  909. :param forward_for: When this Call is forwarded for a client (or from an intermediary router).
  910. :type forward_for: list[dict]
  911. """
  912. assert(on_progress is None or callable(on_progress))
  913. assert(timeout is None or (type(timeout) in list(six.integer_types) + [float] and timeout > 0))
  914. assert(details is None or type(details) == bool)
  915. assert(caller is None or type(caller) in six.integer_types)
  916. assert(caller_authid is None or type(caller_authid) == six.text_type)
  917. assert(caller_authrole is None or type(caller_authrole) == six.text_type)
  918. assert(forward_for is None or type(forward_for) == list)
  919. if forward_for:
  920. for ff in forward_for:
  921. assert type(ff) == dict
  922. assert 'session' in ff and type(ff['session']) in six.integer_types
  923. assert 'authid' in ff and (ff['authid'] is None or type(ff['authid']) == six.text_type)
  924. assert 'authrole' in ff and type(ff['authrole']) == six.text_type
  925. self.on_progress = on_progress
  926. self.timeout = timeout
  927. self.caller = caller
  928. self.caller_authid = caller_authid
  929. self.caller_authrole = caller_authrole
  930. self.forward_for = forward_for
  931. self.details = details
  932. self.correlation_id = correlation_id
  933. self.correlation_uri = correlation_uri
  934. self.correlation_is_anchor = correlation_is_anchor
  935. self.correlation_is_last = correlation_is_last
  936. def message_attr(self):
  937. """
  938. Returns options dict as sent within WAMP messages.
  939. """
  940. options = {}
  941. # note: only some attributes are actually forwarded to the WAMP CALL message, while
  942. # other attributes are for client-side/client-internal use only
  943. if self.timeout is not None:
  944. options[u'timeout'] = self.timeout
  945. if self.on_progress is not None:
  946. options[u'receive_progress'] = True
  947. if self.forward_for is not None:
  948. options[u'forward_for'] = self.forward_for
  949. if self.caller is not None:
  950. options[u'caller'] = self.caller
  951. if self.caller_authid is not None:
  952. options[u'caller_authid'] = self.caller_authid
  953. if self.caller_authrole is not None:
  954. options[u'caller_authrole'] = self.caller_authrole
  955. return options
  956. def __str__(self):
  957. return u"CallOptions(on_progress={}, timeout={}, caller={}, caller_authid={}, caller_authrole={}, forward_for={}, details={})".format(self.on_progress, self.timeout, self.caller, self.caller_authid, self.caller_authrole, self.forward_for, self.details)
  958. @public
  959. class CallResult(object):
  960. """
  961. Wrapper for remote procedure call results that contain multiple positional
  962. return values or keyword-based return values.
  963. """
  964. __slots__ = (
  965. 'results',
  966. 'kwresults',
  967. 'enc_algo',
  968. 'callee',
  969. 'callee_authid',
  970. 'callee_authrole',
  971. 'forward_for',
  972. )
  973. def __init__(self, *results, **kwresults):
  974. """
  975. :param results: The positional result values.
  976. :type results: list
  977. :param kwresults: The keyword result values.
  978. :type kwresults: dict
  979. """
  980. enc_algo = kwresults.pop('enc_algo', None)
  981. assert(enc_algo is None or type(enc_algo) == six.text_type)
  982. callee = kwresults.pop('callee', None)
  983. callee_authid = kwresults.pop('callee_authid', None)
  984. callee_authrole = kwresults.pop('callee_authrole', None)
  985. assert callee is None or type(callee) in six.integer_types
  986. assert callee_authid is None or type(callee_authid) == six.text_type
  987. assert callee_authrole is None or type(callee_authrole) == six.text_type
  988. forward_for = kwresults.pop('forward_for', None)
  989. assert(forward_for is None or type(forward_for) == list)
  990. if forward_for:
  991. for ff in forward_for:
  992. assert type(ff) == dict
  993. assert 'session' in ff and type(ff['session']) in six.integer_types
  994. assert 'authid' in ff and (ff['authid'] is None or type(ff['authid']) == six.text_type)
  995. assert 'authrole' in ff and type(ff['authrole']) == six.text_type
  996. self.enc_algo = enc_algo
  997. self.callee = callee
  998. self.callee_authid = callee_authid
  999. self.callee_authrole = callee_authrole
  1000. self.forward_for = forward_for
  1001. self.results = results
  1002. self.kwresults = kwresults
  1003. def __str__(self):
  1004. return u"CallResult(results={}, kwresults={}, enc_algo={}, callee={}, callee_authid={}, callee_authrole={}, forward_for={})".format(self.results, self.kwresults, self.enc_algo, self.callee, self.callee_authid, self.callee_authrole, self.forward_for)
  1005. @public
  1006. class EncodedPayload(object):
  1007. """
  1008. Wrapper holding an encoded application payload when using WAMP payload transparency.
  1009. """
  1010. __slots__ = (
  1011. 'payload',
  1012. 'enc_algo',
  1013. 'enc_serializer',
  1014. 'enc_key'
  1015. )
  1016. def __init__(self, payload, enc_algo, enc_serializer=None, enc_key=None):
  1017. """
  1018. :param payload: The encoded application payload.
  1019. :type payload: bytes
  1020. :param enc_algo: The payload transparency algorithm identifier to check.
  1021. :type enc_algo: str
  1022. :param enc_serializer: The payload transparency serializer identifier to check.
  1023. :type enc_serializer: str
  1024. :param enc_key: If using payload transparency with an encryption algorithm, the payload encryption key.
  1025. :type enc_key: str or None
  1026. """
  1027. assert(type(payload) == six.binary_type)
  1028. assert(type(enc_algo) == six.text_type)
  1029. assert(enc_serializer is None or type(enc_serializer) == six.text_type)
  1030. assert(enc_key is None or type(enc_key) == six.text_type)
  1031. self.payload = payload
  1032. self.enc_algo = enc_algo
  1033. self.enc_serializer = enc_serializer
  1034. self.enc_key = enc_key
  1035. class IPublication(object):
  1036. """
  1037. Represents a publication of an event. This is used with acknowledged publications.
  1038. """
  1039. def id(self):
  1040. """
  1041. The WAMP publication ID for this publication.
  1042. """
  1043. class ISubscription(object):
  1044. """
  1045. Represents a subscription to a topic.
  1046. """
  1047. def id(self):
  1048. """
  1049. The WAMP subscription ID for this subscription.
  1050. """
  1051. def active(self):
  1052. """
  1053. Flag indicating if subscription is active.
  1054. """
  1055. def unsubscribe(self):
  1056. """
  1057. Unsubscribe this subscription that was previously created from
  1058. :func:`autobahn.wamp.interfaces.ISubscriber.subscribe`.
  1059. After a subscription has been unsubscribed successfully, no events
  1060. will be routed to the event handler anymore.
  1061. Returns an instance of :tx:`twisted.internet.defer.Deferred` (when
  1062. running on **Twisted**) or an instance of :py:class:`asyncio.Future`
  1063. (when running on **asyncio**).
  1064. - If the unsubscription succeeds, the returned Deferred/Future will
  1065. *resolve* (with no return value).
  1066. - If the unsubscription fails, the returned Deferred/Future will *reject*
  1067. with an instance of :class:`autobahn.wamp.exception.ApplicationError`.
  1068. :returns: A Deferred/Future for the unsubscription
  1069. :rtype: instance(s) of :tx:`twisted.internet.defer.Deferred` / :py:class:`asyncio.Future`
  1070. """
  1071. class IRegistration(object):
  1072. """
  1073. Represents a registration of an endpoint.
  1074. """
  1075. def id(self):
  1076. """
  1077. The WAMP registration ID for this registration.
  1078. """
  1079. def active(self):
  1080. """
  1081. Flag indicating if registration is active.
  1082. """
  1083. def unregister(self):
  1084. """
  1085. Unregister this registration that was previously created from
  1086. :func:`autobahn.wamp.interfaces.ICallee.register`.
  1087. After a registration has been unregistered successfully, no calls
  1088. will be routed to the endpoint anymore.
  1089. Returns an instance of :tx:`twisted.internet.defer.Deferred` (when
  1090. running on **Twisted**) or an instance of :py:class:`asyncio.Future`
  1091. (when running on **asyncio**).
  1092. - If the unregistration succeeds, the returned Deferred/Future will
  1093. *resolve* (with no return value).
  1094. - If the unregistration fails, the returned Deferred/Future will be rejected
  1095. with an instance of :class:`autobahn.wamp.exception.ApplicationError`.
  1096. :returns: A Deferred/Future for the unregistration
  1097. :rtype: instance(s) of :tx:`twisted.internet.defer.Deferred` / :py:class:`asyncio.Future`
  1098. """