Mercurial > libervia-backend
comparison sat/tools/sat_defer.py @ 2911:cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 14 Apr 2019 08:21:51 +0200 |
parents | 003b8b4b56a7 |
children | ab2696e34d29 |
comparison
equal
deleted
inserted
replaced
2910:b2f323237fce | 2911:cd391ea847cb |
---|---|
24 log = getLogger(__name__) | 24 log = getLogger(__name__) |
25 from sat.core import exceptions | 25 from sat.core import exceptions |
26 from twisted.internet import defer | 26 from twisted.internet import defer |
27 from twisted.internet import error as internet_error | 27 from twisted.internet import error as internet_error |
28 from twisted.internet import reactor | 28 from twisted.internet import reactor |
29 from twisted.words.protocols.jabber import error as jabber_error | |
29 from twisted.python import failure | 30 from twisted.python import failure |
30 from sat.core.constants import Const as C | 31 from sat.core.constants import Const as C |
31 from sat.memory import memory | 32 from sat.memory import memory |
32 | 33 |
33 KEY_DEFERREDS = "deferreds" | 34 KEY_DEFERREDS = "deferreds" |
34 KEY_NEXT = "next_defer" | 35 KEY_NEXT = "next_defer" |
36 | |
37 | |
38 def stanza2NotFound(failure_): | |
39 """Convert item-not-found StanzaError to exceptions.NotFound""" | |
40 failure_.trap(jabber_error.StanzaError) | |
41 if failure_.value.condition == u'item-not-found': | |
42 raise exceptions.NotFound(failure_.value.text or failure_.value.condition) | |
43 return failure_ | |
35 | 44 |
36 | 45 |
37 class DelayedDeferred(object): | 46 class DelayedDeferred(object): |
38 """A Deferred-like which is launched after a delay""" | 47 """A Deferred-like which is launched after a delay""" |
39 | 48 |