Mercurial > libervia-pubsub
diff sat_pubsub/delegation.py @ 322:54d90c73b8b5
mam: various improvments:
- put common namespaces ton const
- VAL_RSM_MAX_DEFAULT can be None if default limit is not wanted
- ItemDate now has a 'date' attribute
- MAMService is MonkeyPatched the same way as PubSubService to handle PEP
- fixed error mapping in mam module
- PEP is handled
- properly manage date in a payload independent way
- when PEP is used, send privileged messages
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Jan 2016 23:13:13 +0100 |
parents | 5d7c3787672e |
children | 0a93d71f9503 |
line wrap: on
line diff
--- a/sat_pubsub/delegation.py Tue Jan 05 22:16:37 2016 +0100 +++ b/sat_pubsub/delegation.py Tue Jan 05 23:13:13 2016 +0100 @@ -26,6 +26,7 @@ from wokkel import data_form from wokkel import disco, iwokkel from wokkel.iwokkel import IPubSubService +from wokkel import mam from twisted.python import log from twisted.words.protocols.jabber import jid, error from twisted.words.protocols.jabber.xmlstream import toResponse @@ -40,11 +41,14 @@ DELEGATION_MAIN_SEP = "::" DELEGATION_BARE_SEP = ":bare:" +TO_HACK = ((IPubSubService, pubsub, "PubSubRequest"), + (mam.IMAMService, mam, "MAMRequest")) + + class InvalidStanza(Exception): pass - class DelegationsHandler(XMPPHandler): implements(iwokkel.IDisco) _service_hacked = False @@ -53,41 +57,42 @@ super(DelegationsHandler, self).__init__() def _service_hack(self): - """Patch the PubSubService to track delegated stanzas""" + """Patch the request classes of services to track delegated stanzas""" # XXX: we need to monkey patch to track origin of the stanza in PubSubRequest. # As PubSubRequest from sat.tmp.wokkel.pubsub use _request_class while # original wokkel.pubsub use directly pubsub.PubSubRequest, we need to # check which version is used before monkeypatching for handler in self.parent.handlers: - if IPubSubService.providedBy(handler): - if hasattr(handler, '_request_class'): - request_base_class = handler._request_class - else: - request_base_class = pubsub.PubSubRequest + for service, module, default_base_cls in TO_HACK: + if service.providedBy(handler): + if hasattr(handler, '_request_class'): + request_base_class = handler._request_class + else: + request_base_class = getattr(module, default_base_cls) - class PubSubRequestWithDelegation(request_base_class): - """A PubSubReques which put an indicator if the stanza comme from delegation""" + class RequestWithDelegation(request_base_class): + """A XxxRequest which put an indicator if the stanza comme from delegation""" - @classmethod - def fromElement(cls, element): - """Check if element comme from delegation, and set a delegated flags + @classmethod + def fromElement(cls, element): + """Check if element comme from delegation, and set a delegated flags - delegated flaf is either False, or it's a jid of the delegating server - the delegated flag must be set on element before use - """ - try: - # __getattr__ is overriden in domish.Element, so we use __getattribute__ - delegated = element.__getattribute__('delegated') - except AttributeError: - delegated = False - instance = cls.__base__.fromElement(element) - instance.delegated = delegated - return instance + delegated flag is either False, or it's a jid of the delegating server + the delegated flag must be set on element before use + """ + try: + # __getattr__ is overriden in domish.Element, so we use __getattribute__ + delegated = element.__getattribute__('delegated') + except AttributeError: + delegated = False + instance = cls.__base__.fromElement(element) + instance.delegated = delegated + return instance - if hasattr(handler, '_request_class'): - handler._request_class = PubSubRequestWithDelegation - else: - pubsub.PubSubRequest = PubSubRequestWithDelegation + if hasattr(handler, '_request_class'): + handler._request_class = RequestWithDelegation + else: + setattr(module, default_base_cls, RequestWithDelegation) DelegationsHandler._service_hacked = True def connectionInitialized(self):