Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2019-02-10 01:58:51 +0300
committerPhilipp Hörist <philipp@hoerist.com>2019-02-10 01:58:51 +0300
commit988398bbd01453a314bbe47e2c6f65dbb0a84e46 (patch)
tree0eefa52121fc2babcdd8d37726b08b31f91181fa /nbxmpp/modules
parentee45ce4a91240aab898c0151b1094e7bb99f108c (diff)
Return consistent error results
Diffstat (limited to 'nbxmpp/modules')
-rw-r--r--nbxmpp/modules/blocking.py9
-rw-r--r--nbxmpp/modules/bookmarks.py6
-rw-r--r--nbxmpp/modules/muc.py5
-rw-r--r--nbxmpp/modules/pubsub.py5
-rw-r--r--nbxmpp/modules/user_avatar.py25
5 files changed, 26 insertions, 24 deletions
diff --git a/nbxmpp/modules/blocking.py b/nbxmpp/modules/blocking.py
index 5326fd9..fe54c4c 100644
--- a/nbxmpp/modules/blocking.py
+++ b/nbxmpp/modules/blocking.py
@@ -24,6 +24,7 @@ from nbxmpp.structs import BlockingListResult
from nbxmpp.structs import CommonResult
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
+from nbxmpp.util import raise_error
log = logging.getLogger('nbxmpp.m.blocking')
@@ -43,9 +44,7 @@ class Blocking:
def _blocking_list_received(self, stanza):
blocked = []
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getErrorMsg())
- return BlockingListResult(blocking_list=blocked,
- error=stanza.getErrorMsg())
+ return raise_error(log.info, stanza)
blocklist = stanza.getTag('blocklist', namespace=NS_BLOCKING)
for item in blocklist.getTags('item'):
@@ -75,7 +74,5 @@ class Blocking:
@callback
def _default_response(self, stanza):
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getErrorMsg())
- return CommonResult(jid=stanza.getFrom(),
- error=stanza.getErrorMsg())
+ return raise_error(log.info, stanza)
return CommonResult(jid=stanza.getFrom())
diff --git a/nbxmpp/modules/bookmarks.py b/nbxmpp/modules/bookmarks.py
index df2ae96..ccc9f9f 100644
--- a/nbxmpp/modules/bookmarks.py
+++ b/nbxmpp/modules/bookmarks.py
@@ -31,6 +31,7 @@ from nbxmpp.util import to_xs_boolean
from nbxmpp.util import validate_jid
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
+from nbxmpp.util import raise_error
from nbxmpp.modules.pubsub import get_pubsub_item
from nbxmpp.modules.pubsub import get_pubsub_request
from nbxmpp.modules.pubsub import get_bookmark_publish_options
@@ -123,8 +124,7 @@ class Bookmarks:
@callback
def _bookmarks_received(self, stanza, type_):
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getError())
- return []
+ return raise_error(log.info, stanza)
bookmarks = []
if type_ == BookmarkStoreType.PUBSUB:
@@ -187,4 +187,4 @@ class Bookmarks:
@staticmethod
def _on_private_store_result(_con, stanza):
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getError())
+ return raise_error(log.info, stanza)
diff --git a/nbxmpp/modules/muc.py b/nbxmpp/modules/muc.py
index 302cc45..7c291b8 100644
--- a/nbxmpp/modules/muc.py
+++ b/nbxmpp/modules/muc.py
@@ -50,6 +50,7 @@ from nbxmpp.structs import MucDestroyed
from nbxmpp.util import validate_jid
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
+from nbxmpp.util import raise_error
from nbxmpp.modules.dataforms import extend_form
log = logging.getLogger('nbxmpp.m.muc')
@@ -488,9 +489,7 @@ class MUC:
@callback
def _default_response(self, stanza):
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getError())
- return CommonResult(jid=stanza.getFrom(),
- error=stanza.getError())
+ return raise_error(log.info, stanza)
return CommonResult(jid=stanza.getFrom())
@staticmethod
diff --git a/nbxmpp/modules/pubsub.py b/nbxmpp/modules/pubsub.py
index 4a52090..8a5a3e2 100644
--- a/nbxmpp/modules/pubsub.py
+++ b/nbxmpp/modules/pubsub.py
@@ -29,6 +29,7 @@ from nbxmpp.structs import PubSubEventData
from nbxmpp.structs import CommonResult
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
+from nbxmpp.util import raise_error
log = logging.getLogger('nbxmpp.m.pubsub')
@@ -93,9 +94,7 @@ class PubSub:
@callback
def _default_response(self, stanza):
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getError())
- return CommonResult(jid=stanza.getFrom(),
- error=stanza.getError())
+ return raise_error(log.info, stanza)
return CommonResult(jid=stanza.getFrom())
diff --git a/nbxmpp/modules/user_avatar.py b/nbxmpp/modules/user_avatar.py
index ecb23a8..22ebf06 100644
--- a/nbxmpp/modules/user_avatar.py
+++ b/nbxmpp/modules/user_avatar.py
@@ -29,6 +29,7 @@ from nbxmpp.structs import AvatarMetaData
from nbxmpp.structs import AvatarData
from nbxmpp.util import call_on_response
from nbxmpp.util import callback
+from nbxmpp.util import raise_error
from nbxmpp.modules.pubsub import get_pubsub_request
log = logging.getLogger('nbxmpp.m.user_avatar')
@@ -54,6 +55,11 @@ class UserAvatar:
item = properties.pubsub_event.item
metadata = item.getTag('metadata', namespace=NS_AVATAR_METADATA)
+ if metadata is None:
+ log.warning('No metadata node found')
+ log.warning(stanza)
+ raise NodeProcessed
+
if not metadata.getChildren():
pubsub_event = properties.pubsub_event._replace(empty=True)
log.info('Received avatar metadata: %s - no avatar set',
@@ -83,8 +89,7 @@ class UserAvatar:
jid = JID(self._client.get_bound_jid().getBare())
if not isResultNode(stanza):
- log.info('Error: %s', stanza.getError())
- raise NodeProcessed
+ return raise_error(log.warning, stanza)
pubsub_node = stanza.getTag('pubsub')
items_node = pubsub_node.getTag('items')
@@ -93,16 +98,18 @@ class UserAvatar:
sha = item.getAttr('id')
data_node = item.getTag('data', namespace=NS_AVATAR_DATA)
if data_node is None:
- log.warning('No data node found')
- log.warning(stanza)
- raise NodeProcessed
+ return raise_error(log.warning, stanza, 'stanza-malformed',
+ 'No data node found')
data = data_node.getData()
if data is None:
- log.warning('Data node empty')
- log.warning(stanza)
- raise NodeProcessed
+ return raise_error(log.warning, stanza, 'stanza-malformed',
+ 'Data node empty')
+
+ try:
+ data = base64.b64decode(data.encode('utf-8'))
+ except Exception as error:
+ return raise_error(log.warning, stanza, 'stanza-malformed', error)
- data = base64.b64decode(data.encode('utf-8'))
log.info('Received avatar data: %s %s', jid, sha)
return AvatarData(jid, sha, data)