diff options
author | lovetox <philipp@hoerist.com> | 2020-04-19 21:33:55 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-04-19 21:33:55 +0300 |
commit | db7b78d5f350017792b250e111f5e3eaabfa9d98 (patch) | |
tree | de0836071028b511c817fc86c8c1d7ab651be417 /nbxmpp/modules | |
parent | 7712aa5914d1021a6ef4722e1fe454688bb71cb1 (diff) |
Use namespaces module
Diffstat (limited to 'nbxmpp/modules')
41 files changed, 297 insertions, 344 deletions
diff --git a/nbxmpp/modules/activity.py b/nbxmpp/modules/activity.py index f8411d5..6474399 100644 --- a/nbxmpp/modules/activity.py +++ b/nbxmpp/modules/activity.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_ACTIVITY -from nbxmpp.protocol import NS_PUBSUB_EVENT +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.protocol import NodeProcessed from nbxmpp.structs import StanzaHandler @@ -33,7 +32,7 @@ class Activity(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_activity, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), ] @@ -41,7 +40,7 @@ class Activity(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_ACTIVITY: + if properties.pubsub_event.node != Namespace.ACTIVITY: return item = properties.pubsub_event.item @@ -49,7 +48,7 @@ class Activity(BaseModule): # Retract, Deleted or Purged return - activity_node = item.getTag('activity', namespace=NS_ACTIVITY) + activity_node = item.getTag('activity', namespace=Namespace.ACTIVITY) if not activity_node.getChildren(): self._log.info('Received activity: %s - no activity set', properties.jid) @@ -84,7 +83,7 @@ class Activity(BaseModule): return None def set_activity(self, data): - item = Node('activity', {'xmlns': NS_ACTIVITY}) + item = Node('activity', {'xmlns': Namespace.ACTIVITY}) if data is not None and data.activity: activity_node = item.addChild(data.activity) if data.subactivity: @@ -94,4 +93,4 @@ class Activity(BaseModule): jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_ACTIVITY, item, id_='current') + jid, Namespace.ACTIVITY, item, id_='current') diff --git a/nbxmpp/modules/adhoc.py b/nbxmpp/modules/adhoc.py index a5b9490..4cce5ac 100644 --- a/nbxmpp/modules/adhoc.py +++ b/nbxmpp/modules/adhoc.py @@ -15,9 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_COMMANDS -from nbxmpp.protocol import NS_DISCO_ITEMS -from nbxmpp.protocol import NS_DATA +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode from nbxmpp.protocol import Node @@ -44,7 +42,9 @@ class AdHoc(BaseModule): def request_command_list(self, jid=None): if jid is None: jid = self._client.get_bound_jid().getBare() - return get_disco_request(NS_DISCO_ITEMS, jid, node=NS_COMMANDS) + return get_disco_request(Namespace.DISCO_ITEMS, + jid, + node=Namespace.COMMANDS) @callback def _command_list_received(self, stanza): @@ -74,7 +74,7 @@ class AdHoc(BaseModule): if action is None: action = AdHocAction.EXECUTE attrs = {'node': command.node, - 'xmlns': NS_COMMANDS, + 'xmlns': Namespace.COMMANDS, 'action': action.value} if command.sessionid is not None: attrs['sessionid'] = command.sessionid @@ -91,7 +91,7 @@ class AdHoc(BaseModule): if not isResultNode(stanza): return raise_error(self._log.info, stanza) - command = stanza.getTag('command', namespace=NS_COMMANDS) + command = stanza.getTag('command', namespace=Namespace.COMMANDS) if command is None: return raise_error(self._log.warning, stanza, 'stanza-malformed') @@ -117,7 +117,7 @@ class AdHoc(BaseModule): node=attrs['node'], sessionid=attrs.get('sessionid'), status=AdHocStatus(attrs['status']), - data=command.getTag('x', namespace=NS_DATA), + data=command.getTag('x', namespace=Namespace.DATA), actions=actions, notes=notes) except Exception as error: diff --git a/nbxmpp/modules/annotations.py b/nbxmpp/modules/annotations.py index 894e759..2a03524 100644 --- a/nbxmpp/modules/annotations.py +++ b/nbxmpp/modules/annotations.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_PRIVATE -from nbxmpp.protocol import NS_ROSTERNOTES +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Iq from nbxmpp.protocol import Node from nbxmpp.protocol import isResultNode @@ -44,8 +43,8 @@ class Annotations(BaseModule): @call_on_response('_annotations_received') def request_annotations(self): self._log.info('Request annotations for %s', self.domain) - payload = Node('storage', attrs={'xmlns': NS_ROSTERNOTES}) - return Iq(typ='get', queryNS=NS_PRIVATE, payload=payload) + payload = Node('storage', attrs={'xmlns': Namespace.ROSTERNOTES}) + return Iq(typ='get', queryNS=Namespace.PRIVATE, payload=payload) @callback def _annotations_received(self, stanza): @@ -88,7 +87,7 @@ class Annotations(BaseModule): self._log.info('Set annotations for %s:', self.domain) for note in notes: self._log.info(note) - storage = Node('storage', attrs={'xmlns': NS_ROSTERNOTES}) + storage = Node('storage', attrs={'xmlns': Namespace.ROSTERNOTES}) for note in notes: node = Node('note', attrs={'jid': note.jid}) node.setData(note.data) @@ -97,7 +96,7 @@ class Annotations(BaseModule): if note.mdate is not None: node.setAttr('mdate', note.mdate) storage.addChild(node=node) - return Iq(typ='set', queryNS=NS_PRIVATE, payload=storage) + return Iq(typ='set', queryNS=Namespace.PRIVATE, payload=storage) @callback def _default_response(self, stanza): diff --git a/nbxmpp/modules/attention.py b/nbxmpp/modules/attention.py index efdc3fe..62310f1 100644 --- a/nbxmpp/modules/attention.py +++ b/nbxmpp/modules/attention.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_ATTENTION -from nbxmpp.protocol import NS_DELAY2 +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.modules.base import BaseModule @@ -29,12 +28,12 @@ class Attention(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_attention, - ns=NS_ATTENTION, + ns=Namespace.ATTENTION, priority=15), ] def _process_message_attention(self, _client, stanza, properties): - attention = stanza.getTag('attention', namespace=NS_ATTENTION) + attention = stanza.getTag('attention', namespace=Namespace.ATTENTION) if attention is None: return @@ -44,7 +43,7 @@ class Attention(BaseModule): if properties.is_carbon_message and properties.carbon.is_sent: return - if stanza.getTag('delay', namespace=NS_DELAY2) is not None: + if stanza.getTag('delay', namespace=Namespace.DELAY2) is not None: return properties.attention = True diff --git a/nbxmpp/modules/bits_of_binary.py b/nbxmpp/modules/bits_of_binary.py index 0eb1ac0..22d21df 100644 --- a/nbxmpp/modules/bits_of_binary.py +++ b/nbxmpp/modules/bits_of_binary.py @@ -18,7 +18,7 @@ import logging import hashlib -from nbxmpp.protocol import NS_BOB +from nbxmpp.namespaces import Namespace from nbxmpp.structs import BobData from nbxmpp.util import b64decode @@ -26,7 +26,7 @@ log = logging.getLogger('nbxmpp.m.bob') def parse_bob_data(stanza): - data_node = stanza.getTag('data', namespace=NS_BOB) + data_node = stanza.getTag('data', namespace=Namespace.BOB) if data_node is None: return None diff --git a/nbxmpp/modules/blocking.py b/nbxmpp/modules/blocking.py index 2615c1c..1f55e4f 100644 --- a/nbxmpp/modules/blocking.py +++ b/nbxmpp/modules/blocking.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_BLOCKING +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode from nbxmpp.structs import BlockingListResult @@ -35,7 +35,7 @@ class Blocking(BaseModule): @call_on_response('_blocking_list_received') def get_blocking_list(self): - iq = Iq('get', NS_BLOCKING) + iq = Iq('get', Namespace.BLOCKING) iq.setQuery('blocklist') return iq @@ -45,7 +45,7 @@ class Blocking(BaseModule): if not isResultNode(stanza): return raise_error(self._log.info, stanza) - blocklist = stanza.getTag('blocklist', namespace=NS_BLOCKING) + blocklist = stanza.getTag('blocklist', namespace=Namespace.BLOCKING) if blocklist is None: return raise_error(self._log.warning, stanza, 'stanza-malformed') @@ -58,7 +58,7 @@ class Blocking(BaseModule): @call_on_response('_default_response') def block(self, jids): self._log.info('Block: %s', jids) - iq = Iq('set', NS_BLOCKING) + iq = Iq('set', Namespace.BLOCKING) query = iq.setQuery(name='block') for jid in jids: query.addChild(name='item', attrs={'jid': jid}) @@ -67,7 +67,7 @@ class Blocking(BaseModule): @call_on_response('_default_response') def unblock(self, jids): self._log.info('Unblock: %s', jids) - iq = Iq('set', NS_BLOCKING) + iq = Iq('set', Namespace.BLOCKING) query = iq.setQuery(name='unblock') for jid in jids: query.addChild(name='item', attrs={'jid': jid}) diff --git a/nbxmpp/modules/bookmarks.py b/nbxmpp/modules/bookmarks.py index 3e61981..143748a 100644 --- a/nbxmpp/modules/bookmarks.py +++ b/nbxmpp/modules/bookmarks.py @@ -15,10 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_BOOKMARKS -from nbxmpp.protocol import NS_BOOKMARKS_2 -from nbxmpp.protocol import NS_PUBSUB_EVENT -from nbxmpp.protocol import NS_PRIVATE +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import isResultNode from nbxmpp.protocol import Node from nbxmpp.protocol import Iq @@ -63,11 +60,11 @@ class Bookmarks(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_bookmarks, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), StanzaHandler(name='message', callback=self._process_pubsub_bookmarks2, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), ] @@ -80,7 +77,7 @@ class Bookmarks(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_BOOKMARKS: + if properties.pubsub_event.node != Namespace.BOOKMARKS: return item = properties.pubsub_event.item @@ -88,7 +85,7 @@ class Bookmarks(BaseModule): # Retract, Deleted or Purged return - storage_node = item.getTag('storage', namespace=NS_BOOKMARKS) + storage_node = item.getTag('storage', namespace=Namespace.BOOKMARKS) if storage_node is None: self._log.warning('No storage node found') self._log.warning(stanza) @@ -110,7 +107,7 @@ class Bookmarks(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_BOOKMARKS_2: + if properties.pubsub_event.node != Namespace.BOOKMARKS_2: return item = properties.pubsub_event.item @@ -173,7 +170,7 @@ class Bookmarks(BaseModule): self._log.warning(item) return None - conference = item.getTag('conference', namespace=NS_BOOKMARKS_2) + conference = item.getTag('conference', namespace=Namespace.BOOKMARKS_2) if conference is None: self._log.warning('No conference node found') self._log.warning(item) @@ -191,8 +188,8 @@ class Bookmarks(BaseModule): @staticmethod def get_private_request(): iq = Iq(typ='get') - query = iq.addChild(name='query', namespace=NS_PRIVATE) - query.addChild(name='storage', namespace=NS_BOOKMARKS) + query = iq.addChild(name='query', namespace=Namespace.PRIVATE) + query.addChild(name='storage', namespace=Namespace.BOOKMARKS) return iq @call_on_response('_bookmarks_received') @@ -200,12 +197,12 @@ class Bookmarks(BaseModule): jid = self._client.get_bound_jid().getBare() if type_ == BookmarkStoreType.PUBSUB_BOOKMARK_2: self._log.info('Request bookmarks 2 (PubSub)') - request = get_pubsub_request(jid, NS_BOOKMARKS_2) + request = get_pubsub_request(jid, Namespace.BOOKMARKS_2) return request, {'type_': type_} if type_ == BookmarkStoreType.PUBSUB_BOOKMARK_1: self._log.info('Request bookmarks (PubSub)') - request = get_pubsub_request(jid, NS_BOOKMARKS, max_items=1) + request = get_pubsub_request(jid, Namespace.BOOKMARKS, max_items=1) return request, {'type_': type_} if type_ == BookmarkStoreType.PRIVATE: @@ -220,7 +217,7 @@ class Bookmarks(BaseModule): bookmarks = [] if type_ == BookmarkStoreType.PUBSUB_BOOKMARK_2: - items = get_pubsub_items(stanza, NS_BOOKMARKS_2) + items = get_pubsub_items(stanza, Namespace.BOOKMARKS_2) if items is None: return raise_error(self._log.warning, stanza, @@ -234,7 +231,8 @@ class Bookmarks(BaseModule): elif type_ == BookmarkStoreType.PUBSUB_BOOKMARK_1: item = get_pubsub_item(stanza) if item is not None: - storage_node = item.getTag('storage', namespace=NS_BOOKMARKS) + storage_node = item.getTag('storage', + namespace=Namespace.BOOKMARKS) if storage_node is None: return raise_error(self._log.warning, stanza, @@ -246,7 +244,8 @@ class Bookmarks(BaseModule): elif type_ == BookmarkStoreType.PRIVATE: query = stanza.getQuery() - storage_node = query.getTag('storage', namespace=NS_BOOKMARKS) + storage_node = query.getTag('storage', + namespace=Namespace.BOOKMARKS) if storage_node is None: return raise_error(self._log.warning, stanza, @@ -266,7 +265,7 @@ class Bookmarks(BaseModule): @staticmethod def _build_storage_node(bookmarks): - storage_node = Node(tag='storage', attrs={'xmlns': NS_BOOKMARKS}) + storage_node = Node(tag='storage', attrs={'xmlns': Namespace.BOOKMARKS}) for bookmark in bookmarks: conf_node = storage_node.addChild(name="conference") conf_node.setAttr('jid', bookmark.jid) @@ -281,7 +280,7 @@ class Bookmarks(BaseModule): @staticmethod def _build_conference_node(bookmark): - attrs = {'xmlns': NS_BOOKMARKS_2} + attrs = {'xmlns': Namespace.BOOKMARKS_2} if bookmark.autojoin: attrs['autojoin'] = 'true' if bookmark.name: @@ -303,7 +302,7 @@ class Bookmarks(BaseModule): self._log.info('Retract Bookmark: %s', bookmark_jid) jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').retract(jid, - NS_BOOKMARKS_2, + Namespace.BOOKMARKS_2, str(bookmark_jid)) def _store_bookmark_1(self, bookmarks): @@ -314,12 +313,12 @@ class Bookmarks(BaseModule): options = get_publish_options(BOOKMARK_1_OPTIONS) self._client.get_module('PubSub').publish( jid, - NS_BOOKMARKS, + Namespace.BOOKMARKS, item, id_='current', options=options, callback=self._on_store_bookmark_result, - user_data=NS_BOOKMARKS) + user_data=Namespace.BOOKMARKS) def _store_bookmark_2(self, bookmarks): if self._node_configuration_not_possible: @@ -334,12 +333,12 @@ class Bookmarks(BaseModule): options = get_publish_options(BOOKMARK_2_OPTIONS) self._client.get_module('PubSub').publish( jid, - NS_BOOKMARKS_2, + Namespace.BOOKMARKS_2, item, id_=str(bookmark.jid), options=options, callback=self._on_store_bookmark_result, - user_data=NS_BOOKMARKS_2) + user_data=Namespace.BOOKMARKS_2) def _on_store_bookmark_result(self, result, node): if not is_error_result(result): @@ -371,7 +370,7 @@ class Bookmarks(BaseModule): self._bookmark_2_queue.clear() return - if result.node == NS_BOOKMARKS: + if result.node == Namespace.BOOKMARKS: config = BOOKMARK_1_OPTIONS else: config = BOOKMARK_2_OPTIONS @@ -415,7 +414,7 @@ class Bookmarks(BaseModule): def _store_with_private(self, bookmarks): self._log.info('Store Bookmarks (Private Storage)') storage_node = self._build_storage_node(bookmarks) - return Iq('set', NS_PRIVATE, payload=storage_node) + return Iq('set', Namespace.PRIVATE, payload=storage_node) def _on_private_store_result(self, _client, stanza): if not isResultNode(stanza): diff --git a/nbxmpp/modules/captcha.py b/nbxmpp/modules/captcha.py index 08a00e9..2d6621d 100644 --- a/nbxmpp/modules/captcha.py +++ b/nbxmpp/modules/captcha.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_CAPTCHA -from nbxmpp.protocol import NS_DATA +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import CaptchaData from nbxmpp.modules.dataforms import extend_form @@ -32,16 +31,16 @@ class Captcha(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_captcha, - ns=NS_CAPTCHA, + ns=Namespace.CAPTCHA, priority=40), ] def _process_captcha(self, _client, stanza, properties): - captcha = stanza.getTag('captcha', namespace=NS_CAPTCHA) + captcha = stanza.getTag('captcha', namespace=Namespace.CAPTCHA) if captcha is None: return - data_form = captcha.getTag('x', namespace=NS_DATA) + data_form = captcha.getTag('x', namespace=Namespace.DATA) if data_form is None: self._log.warning('Invalid captcha form') self._log.warning(stanza) diff --git a/nbxmpp/modules/chat_markers.py b/nbxmpp/modules/chat_markers.py index a086f63..d1b8334 100644 --- a/nbxmpp/modules/chat_markers.py +++ b/nbxmpp/modules/chat_markers.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_CHATMARKERS +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import ChatMarker from nbxmpp.modules.base import BaseModule @@ -29,16 +29,17 @@ class ChatMarkers(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_marker, - ns=NS_CHATMARKERS, + ns=Namespace.CHATMARKERS, priority=15), ] def _process_message_marker(self, _client, stanza, properties): - type_ = stanza.getTag('received', namespace=NS_CHATMARKERS) + type_ = stanza.getTag('received', namespace=Namespace.CHATMARKERS) if type_ is None: - type_ = stanza.getTag('displayed', namespace=NS_CHATMARKERS) + type_ = stanza.getTag('displayed', namespace=Namespace.CHATMARKERS) if type_ is None: - type_ = stanza.getTag('acknowledged', namespace=NS_CHATMARKERS) + type_ = stanza.getTag('acknowledged', + namespace=Namespace.CHATMARKERS) if type_ is None: return diff --git a/nbxmpp/modules/chatstates.py b/nbxmpp/modules/chatstates.py index 2fc13d3..047defe 100644 --- a/nbxmpp/modules/chatstates.py +++ b/nbxmpp/modules/chatstates.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_CHATSTATES -from nbxmpp.protocol import NS_DELAY2 +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.const import CHATSTATES from nbxmpp.modules.base import BaseModule @@ -30,7 +29,7 @@ class Chatstates(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_chatstate, - ns=NS_CHATSTATES, + ns=Namespace.CHATSTATES, priority=15), ] @@ -42,7 +41,7 @@ class Chatstates(BaseModule): if properties.is_mam_message: return - if stanza.getTag('delay', namespace=NS_DELAY2) is not None: + if stanza.getTag('delay', namespace=Namespace.DELAY2) is not None: return if chatstate not in CHATSTATES: @@ -56,6 +55,6 @@ class Chatstates(BaseModule): def parse_chatstate(stanza): children = stanza.getChildren() for child in children: - if child.getNamespace() == NS_CHATSTATES: + if child.getNamespace() == Namespace.CHATSTATES: return child.getName() return None diff --git a/nbxmpp/modules/correction.py b/nbxmpp/modules/correction.py index e4a3858..664307b 100644 --- a/nbxmpp/modules/correction.py +++ b/nbxmpp/modules/correction.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_CORRECT +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import CorrectionData from nbxmpp.modules.base import BaseModule @@ -29,12 +29,12 @@ class Correction(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_correction, - ns=NS_CORRECT, + ns=Namespace.CORRECT, priority=15), ] def _process_message_correction(self, _client, stanza, properties): - replace = stanza.getTag('replace', namespace=NS_CORRECT) + replace = stanza.getTag('replace', namespace=Namespace.CORRECT) if replace is None: return diff --git a/nbxmpp/modules/dataforms.py b/nbxmpp/modules/dataforms.py index f0fb408..4eda96a 100644 --- a/nbxmpp/modules/dataforms.py +++ b/nbxmpp/modules/dataforms.py @@ -19,8 +19,7 @@ # XEP-0004: Data Forms -from nbxmpp.protocol import NS_DATA -from nbxmpp.protocol import NS_DATA_MEDIA +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import JID from nbxmpp.simplexml import Node @@ -224,7 +223,7 @@ class DataField(ExtendedNode): """ Media data """ - media = self.getTag('media', namespace=NS_DATA_MEDIA) + media = self.getTag('media', namespace=Namespace.DATA_MEDIA) if media: return Media(media) return None @@ -600,7 +599,7 @@ class DataForm(ExtendedNode): def __init__(self, type_=None, title=None, instructions=None, extend=None): if extend is None: # we have to build form from scratch - Node.__init__(self, 'x', attrs={'xmlns': NS_DATA}) + Node.__init__(self, 'x', attrs={'xmlns': Namespace.DATA}) if type_ is not None: self.type_ = type_ diff --git a/nbxmpp/modules/delay.py b/nbxmpp/modules/delay.py index dbf42b3..83be2a2 100644 --- a/nbxmpp/modules/delay.py +++ b/nbxmpp/modules/delay.py @@ -17,7 +17,7 @@ import logging -from nbxmpp.protocol import NS_DELAY2 +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.modules.date_and_time import parse_datetime from nbxmpp.modules.base import BaseModule @@ -33,11 +33,11 @@ class Delay(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_delay, - ns=NS_DELAY2, + ns=Namespace.DELAY2, priority=15), StanzaHandler(name='presence', callback=self._process_presence_delay, - ns=NS_DELAY2, + ns=Namespace.DELAY2, priority=15) ] @@ -86,7 +86,7 @@ def parse_delay(stanza, epoch=True, convert='utc', from_=None, not_from=None): :param not_from: Matches only delays that have the according from attr not set ''' - delays = stanza.getTags('delay', namespace=NS_DELAY2) + delays = stanza.getTags('delay', namespace=Namespace.DELAY2) for delay in delays: stamp = delay.getAttr('stamp') diff --git a/nbxmpp/modules/discovery.py b/nbxmpp/modules/discovery.py index 696d2e3..b03a75b 100644 --- a/nbxmpp/modules/discovery.py +++ b/nbxmpp/modules/discovery.py @@ -19,9 +19,7 @@ import time import logging from nbxmpp.protocol import Iq -from nbxmpp.protocol import NS_DISCO_INFO -from nbxmpp.protocol import NS_DISCO_ITEMS -from nbxmpp.protocol import NS_DATA +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import isResultNode from nbxmpp.protocol import ErrorNode from nbxmpp.protocol import ERR_ITEM_NOT_FOUND @@ -49,7 +47,7 @@ class Discovery(BaseModule): self.handlers = [ StanzaHandler(name='iq', callback=self._process_disco_info, - ns=NS_DISCO_INFO, + ns=Namespace.DISCO_INFO, priority=90), ] @@ -63,7 +61,7 @@ class Discovery(BaseModule): @call_on_response('_disco_info_received') def disco_info(self, jid, node=None): self._log.info('Disco info: %s, node: %s', jid, node) - return get_disco_request(NS_DISCO_INFO, jid, node) + return get_disco_request(Namespace.DISCO_INFO, jid, node) @callback def _disco_info_received(self, stanza): @@ -74,7 +72,7 @@ class Discovery(BaseModule): @call_on_response('_disco_items_received') def disco_items(self, jid, node=None): self._log.info('Disco items: %s, node: %s', jid, node) - return get_disco_request(NS_DISCO_ITEMS, jid, node) + return get_disco_request(Namespace.DISCO_ITEMS, jid, node) @callback def _disco_items_received(self, stanza): @@ -109,7 +107,7 @@ def parse_disco_info(stanza, timestamp=None): except Exception: return raise_error(log.warning, stanza, 'stanza-malformed') - for node in query.getTags('x', namespace=NS_DATA): + for node in query.getTags('x', namespace=Namespace.DATA): dataforms.append(extend_form(node)) return DiscoInfo(stanza=stanza, diff --git a/nbxmpp/modules/eme.py b/nbxmpp/modules/eme.py index 10643d5..5367088 100644 --- a/nbxmpp/modules/eme.py +++ b/nbxmpp/modules/eme.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_EME +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import EMEData from nbxmpp.modules.base import BaseModule @@ -29,12 +29,12 @@ class EME(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_eme, - ns=NS_EME, + ns=Namespace.EME, priority=40) ] def _process_eme(self, _client, stanza, properties): - encryption = stanza.getTag('encryption', namespace=NS_EME) + encryption = stanza.getTag('encryption', namespace=Namespace.EME) if encryption is None: return diff --git a/nbxmpp/modules/entity_caps.py b/nbxmpp/modules/entity_caps.py index 05479b2..17fd2df 100644 --- a/nbxmpp/modules/entity_caps.py +++ b/nbxmpp/modules/entity_caps.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_CAPS -from nbxmpp.protocol import NS_DISCO_INFO +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import NodeProcessed from nbxmpp.structs import StanzaHandler from nbxmpp.structs import EntityCapsData @@ -33,11 +32,11 @@ class EntityCaps(BaseModule): self.handlers = [ StanzaHandler(name='presence', callback=self._process_entity_caps, - ns=NS_CAPS, + ns=Namespace.CAPS, priority=15), StanzaHandler(name='iq', callback=self._process_disco_info, - ns=NS_DISCO_INFO, + ns=Namespace.DISCO_INFO, priority=20), ] @@ -71,7 +70,7 @@ class EntityCaps(BaseModule): raise NodeProcessed def _process_entity_caps(self, _client, stanza, properties): - caps = stanza.getTag('c', namespace=NS_CAPS) + caps = stanza.getTag('c', namespace=Namespace.CAPS) if caps is None: return diff --git a/nbxmpp/modules/http_auth.py b/nbxmpp/modules/http_auth.py index ab2a45f..2a73fec 100644 --- a/nbxmpp/modules/http_auth.py +++ b/nbxmpp/modules/http_auth.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_HTTP_AUTH +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import HTTPAuthData from nbxmpp.modules.base import BaseModule @@ -28,17 +28,17 @@ class HTTPAuth(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_http_auth, - ns=NS_HTTP_AUTH, + ns=Namespace.HTTP_AUTH, priority=40), StanzaHandler(name='iq', callback=self._process_http_auth, typ='get', - ns=NS_HTTP_AUTH, + ns=Namespace.HTTP_AUTH, priority=40) ] def _process_http_auth(self, _client, stanza, properties): - confirm = stanza.getTag('confirm', namespace=NS_HTTP_AUTH) + confirm = stanza.getTag('confirm', namespace=Namespace.HTTP_AUTH) if confirm is None: return diff --git a/nbxmpp/modules/http_upload.py b/nbxmpp/modules/http_upload.py index 93ef094..8df172b 100644 --- a/nbxmpp/modules/http_upload.py +++ b/nbxmpp/modules/http_upload.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_HTTPUPLOAD_0 +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode from nbxmpp.structs import HTTPUploadData @@ -42,7 +42,7 @@ class HTTPUpload(BaseModule): 'size': size, 'content-type': content_type} iq.setTag(name="request", - namespace=NS_HTTPUPLOAD_0, + namespace=Namespace.HTTPUPLOAD_0, attrs=attr) return iq @@ -51,7 +51,7 @@ class HTTPUpload(BaseModule): if not isResultNode(stanza): return raise_error(self._log.info, stanza) - slot = stanza.getTag('slot', namespace=NS_HTTPUPLOAD_0) + slot = stanza.getTag('slot', namespace=Namespace.HTTPUPLOAD_0) if slot is None: return raise_error(self._log.warning, stanza, 'stanza-malformed', 'No slot node found') diff --git a/nbxmpp/modules/ibb.py b/nbxmpp/modules/ibb.py index 2773965..977a9b8 100644 --- a/nbxmpp/modules/ibb.py +++ b/nbxmpp/modules/ibb.py @@ -20,7 +20,7 @@ from nbxmpp.protocol import ERR_BAD_REQUEST from nbxmpp.protocol import ERR_FEATURE_NOT_IMPLEMENTED from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import Iq -from nbxmpp.protocol import NS_IBB +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import isResultNode from nbxmpp.structs import CommonResult from nbxmpp.structs import StanzaHandler @@ -41,23 +41,23 @@ class IBB(BaseModule): self.handlers = [ StanzaHandler(name='iq', callback=self._process_ibb, - ns=NS_IBB, + ns=Namespace.IBB, priority=20), ] def _process_ibb(self, _client, stanza, properties): if properties.type.is_set: - open_ = stanza.getTag('open', namespace=NS_IBB) + open_ = stanza.getTag('open', namespace=Namespace.IBB) if open_ is not None: properties.ibb = self._parse_open(stanza, open_) return - close = stanza.getTag('close', namespace=NS_IBB) + close = stanza.getTag('close', namespace=Namespace.IBB) if close is not None: properties.ibb = self._parse_close(stanza, close) return - data = stanza.getTag('data', namespace=NS_IBB) + data = stanza.getTag('data', namespace=Namespace.IBB) if data is not None: properties.ibb = self._parse_data(stanza, data) return @@ -137,13 +137,13 @@ class IBB(BaseModule): iq = Iq('set', to=jid) iq.addChild('open', {'block-size': block_size, 'sid': sid, 'stanza': 'iq'}, - namespace=NS_IBB) + namespace=Namespace.IBB) return iq @call_on_response('_default_response') def send_close(self, jid, sid): iq = Iq('set', to=jid) - iq.addChild('close', {'sid': sid}, namespace=NS_IBB) + iq.addChild('close', {'sid': sid}, namespace=Namespace.IBB) return iq @call_on_response('_default_response') @@ -151,7 +151,7 @@ class IBB(BaseModule): iq = Iq('set', to=jid) ibb_data = iq.addChild('data', {'sid': sid, 'seq': seq}, - namespace=NS_IBB) + namespace=Namespace.IBB) ibb_data.setData(b64encode(data)) return iq diff --git a/nbxmpp/modules/idle.py b/nbxmpp/modules/idle.py index a2b6c03..ad822c5 100644 --- a/nbxmpp/modules/idle.py +++ b/nbxmpp/modules/idle.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_IDLE +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.modules.date_and_time import parse_datetime from nbxmpp.modules.base import BaseModule @@ -29,12 +29,12 @@ class Idle(BaseModule): self.handlers = [ StanzaHandler(name='presence', callback=self._process_idle, - ns=NS_IDLE, + ns=Namespace.IDLE, priority=15) ] def _process_idle(self, _client, stanza, properties): - idle_tag = stanza.getTag('idle', namespace=NS_IDLE) + idle_tag = stanza.getTag('idle', namespace=Namespace.IDLE) if idle_tag is None: return diff --git a/nbxmpp/modules/location.py b/nbxmpp/modules/location.py index 6c3e7d3..debcf2d 100644 --- a/nbxmpp/modules/location.py +++ b/nbxmpp/modules/location.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_LOCATION -from nbxmpp.protocol import NS_PUBSUB_EVENT +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.structs import StanzaHandler from nbxmpp.structs import LocationData @@ -32,7 +31,7 @@ class Location(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_location, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), ] @@ -40,7 +39,7 @@ class Location(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_LOCATION: + if properties.pubsub_event.node != Namespace.LOCATION: return item = properties.pubsub_event.item @@ -48,7 +47,7 @@ class Location(BaseModule): # Retract, Deleted or Purged return - location_node = item.getTag('geoloc', namespace=NS_LOCATION) + location_node = item.getTag('geoloc', namespace=Namespace.LOCATION) if not location_node.getChildren(): self._log.info('Received location: %s - no location set', properties.jid) @@ -64,7 +63,7 @@ class Location(BaseModule): properties.pubsub_event = pubsub_event def set_location(self, data): - item = Node('geoloc', {'xmlns': NS_LOCATION}) + item = Node('geoloc', {'xmlns': Namespace.LOCATION}) if data is None: return @@ -75,4 +74,4 @@ class Location(BaseModule): jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_LOCATION, item, id_='current') + jid, Namespace.LOCATION, item, id_='current') diff --git a/nbxmpp/modules/mam.py b/nbxmpp/modules/mam.py index b65c82c..90851e1 100644 --- a/nbxmpp/modules/mam.py +++ b/nbxmpp/modules/mam.py @@ -20,8 +20,7 @@ from nbxmpp.protocol import JID from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode from nbxmpp.protocol import Node -from nbxmpp.protocol import NS_MAM_2 -from nbxmpp.protocol import NS_RSM +from nbxmpp.namespaces import Namespace from nbxmpp.structs import MAMQueryData from nbxmpp.structs import MAMPreferencesData from nbxmpp.structs import CommonResult @@ -51,7 +50,7 @@ class MAM(BaseModule): after=None, max_=70): - iq = Iq(typ='set', to=jid, queryNS=NS_MAM_2) + iq = Iq(typ='set', to=jid, queryNS=Namespace.MAM_2) if queryid is not None: iq.getQuery().setAttr('queryid', queryid) @@ -66,7 +65,7 @@ class MAM(BaseModule): @staticmethod def _make_query_form(start, end, with_): fields = [ - create_field(typ='hidden', var='FORM_TYPE', value=NS_MAM_2) + create_field(typ='hidden', var='FORM_TYPE', value=Namespace.MAM_2) ] if start: @@ -91,7 +90,7 @@ class MAM(BaseModule): @staticmethod def _make_rsm_query(max_, after): - rsm_set = Node('set', attrs={'xmlns': NS_RSM}) + rsm_set = Node('set', attrs={'xmlns': Namespace.RSM}) if max_ is not None: rsm_set.setTagData('max', max_) if after is not None: @@ -104,7 +103,7 @@ class MAM(BaseModule): return raise_error(self._log.info, stanza) jid = stanza.getFrom() - fin = stanza.getTag('fin', namespace=NS_MAM_2) + fin = stanza.getTag('fin', namespace=Namespace.MAM_2) if fin is None: return raise_error(self._log.warning, stanza, @@ -132,7 +131,7 @@ class MAM(BaseModule): @call_on_response('_preferences_result') def request_preferences(self): - iq = Iq('get', queryNS=NS_MAM_2) + iq = Iq('get', queryNS=Namespace.MAM_2) iq.setQuery('prefs') return iq @@ -141,7 +140,7 @@ class MAM(BaseModule): if not isResultNode(stanza): return raise_error(self._log.info, stanza) - prefs = stanza.getTag('prefs', namespace=NS_MAM_2) + prefs = stanza.getTag('prefs', namespace=Namespace.MAM_2) if prefs is None: return raise_error(self._log.warning, stanza, @@ -198,7 +197,7 @@ class MAM(BaseModule): iq = Iq(typ='set') prefs = iq.addChild(name='prefs', - namespace=NS_MAM_2, + namespace=Namespace.MAM_2, attrs={'default': default}) always_node = prefs.addChild(name='always') never_node = prefs.addChild(name='never') diff --git a/nbxmpp/modules/message.py b/nbxmpp/modules/message.py index a30369d..51787b7 100644 --- a/nbxmpp/modules/message.py +++ b/nbxmpp/modules/message.py @@ -16,8 +16,7 @@ # along with this program; If not, see <http://www.gnu.org/licenses/>. from nbxmpp.protocol import NodeProcessed -from nbxmpp.protocol import NS_DATA -from nbxmpp.protocol import NS_XHTML +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import StanzaIDData from nbxmpp.structs import XHTMLData @@ -76,7 +75,7 @@ class BaseMessage(BaseModule): properties.body = stanza.getBody() properties.thread = stanza.getThread() properties.subject = stanza.getSubject() - forms = stanza.getTags('x', namespace=NS_DATA) + forms = stanza.getTags('x', namespace=Namespace.DATA) if forms: properties.forms = forms @@ -84,7 +83,7 @@ class BaseMessage(BaseModule): if xhtml is None: return - if xhtml.getTag('body', namespace=NS_XHTML) is None: + if xhtml.getTag('body', namespace=Namespace.XHTML) is None: self._log.warning('xhtml without body found') self._log.warning(stanza) return diff --git a/nbxmpp/modules/misc.py b/nbxmpp/modules/misc.py index 02efa8c..afa346b 100644 --- a/nbxmpp/modules/misc.py +++ b/nbxmpp/modules/misc.py @@ -17,12 +17,7 @@ import logging -from nbxmpp.protocol import NS_CARBONS -from nbxmpp.protocol import NS_FORWARD -from nbxmpp.protocol import NS_MUC_USER -from nbxmpp.protocol import NS_MAM_1 -from nbxmpp.protocol import NS_MAM_2 -from nbxmpp.protocol import NS_XHTML +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import InvalidFrom from nbxmpp.protocol import InvalidStanza @@ -36,9 +31,9 @@ log = logging.getLogger('nbxmpp.m.misc') def unwrap_carbon(stanza, own_jid): - carbon = stanza.getTag('received', namespace=NS_CARBONS) + carbon = stanza.getTag('received', namespace=Namespace.CARBONS) if carbon is None: - carbon = stanza.getTag('sent', namespace=NS_CARBONS) + carbon = stanza.getTag('sent', namespace=Namespace.CARBONS) if carbon is None: return stanza, None @@ -46,7 +41,7 @@ def unwrap_carbon(stanza, own_jid): if not stanza.getFrom() == own_jid.getBare(): raise InvalidFrom('Invalid from: %s' % stanza.getAttr('from')) - forwarded = carbon.getTag('forwarded', namespace=NS_FORWARD) + forwarded = carbon.getTag('forwarded', namespace=Namespace.FORWARD) message = Message(node=forwarded.getTag('message')) type_ = carbon.getName() @@ -67,7 +62,7 @@ def unwrap_carbon(stanza, own_jid): # message itself raise NodeProcessed('Drop "received"-Carbon from ourself') - if message.getTag('x', namespace=NS_MUC_USER) is not None: + if message.getTag('x', namespace=Namespace.MUC_USER) is not None: # A MUC broadcasts messages sent to us to all resources # there is no need to process the received carbon raise NodeProcessed('Drop MUC-PM "received"-Carbon') @@ -76,9 +71,9 @@ def unwrap_carbon(stanza, own_jid): def unwrap_mam(stanza, own_jid): - result = stanza.getTag('result', namespace=NS_MAM_2) + result = stanza.getTag('result', namespace=Namespace.MAM_2) if result is None: - result = stanza.getTag('result', namespace=NS_MAM_1) + result = stanza.getTag('result', namespace=Namespace.MAM_1) if result is None: return stanza, None @@ -94,7 +89,7 @@ def unwrap_mam(stanza, own_jid): log.warning(stanza) raise InvalidStanza - forwarded = result.getTag('forwarded', namespace=NS_FORWARD) + forwarded = result.getTag('forwarded', namespace=Namespace.FORWARD) message = Message(node=forwarded.getTag('message')) # Fill missing to/from @@ -125,9 +120,9 @@ def build_xhtml_body(xhtml, xmllang=None): try: if xmllang is not None: body = '<body xmlns="%s" xml:lang="%s">%s</body>' % ( - NS_XHTML, xmllang, xhtml) + Namespace.XHTML, xmllang, xhtml) else: - body = '<body xmlns="%s">%s</body>' % (NS_XHTML, xhtml) + body = '<body xmlns="%s">%s</body>' % (Namespace.XHTML, xhtml) except Exception as error: log.error('Error while building xhtml node: %s', error) return None diff --git a/nbxmpp/modules/mood.py b/nbxmpp/modules/mood.py index 41e863e..1db24c6 100644 --- a/nbxmpp/modules/mood.py +++ b/nbxmpp/modules/mood.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_MOOD -from nbxmpp.protocol import NS_PUBSUB_EVENT +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.protocol import NodeProcessed from nbxmpp.structs import StanzaHandler @@ -33,7 +32,7 @@ class Mood(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_mood, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), ] @@ -41,7 +40,7 @@ class Mood(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_MOOD: + if properties.pubsub_event.node != Namespace.MOOD: return item = properties.pubsub_event.item @@ -49,7 +48,7 @@ class Mood(BaseModule): # Retract, Deleted or Purged return - mood_node = item.getTag('mood', namespace=NS_MOOD) + mood_node = item.getTag('mood', namespace=Namespace.MOOD) if not mood_node.getChildren(): self._log.info('Received mood: %s - removed mood', properties.jid) return @@ -74,7 +73,7 @@ class Mood(BaseModule): properties.pubsub_event = pubsub_event def set_mood(self, data): - item = Node('mood', {'xmlns': NS_MOOD}) + item = Node('mood', {'xmlns': Namespace.MOOD}) if data is not None and data.mood: item.addChild(data.mood) @@ -83,4 +82,4 @@ class Mood(BaseModule): jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_MOOD, item, id_='current') + jid, Namespace.MOOD, item, id_='current') diff --git a/nbxmpp/modules/muc.py b/nbxmpp/modules/muc.py index 2a3d473..0b02904 100644 --- a/nbxmpp/modules/muc.py +++ b/nbxmpp/modules/muc.py @@ -15,15 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_MUC_USER -from nbxmpp.protocol import NS_MUC -from nbxmpp.protocol import NS_CONFERENCE -from nbxmpp.protocol import NS_DATA -from nbxmpp.protocol import NS_MUC_REQUEST -from nbxmpp.protocol import NS_MUC_ADMIN -from nbxmpp.protocol import NS_MUC_OWNER -from nbxmpp.protocol import NS_CAPTCHA -from nbxmpp.protocol import NS_ADDRESS +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import ERR_NOT_ACCEPTABLE from nbxmpp.protocol import JID from nbxmpp.protocol import Iq @@ -64,11 +56,11 @@ class MUC(BaseModule): self.handlers = [ StanzaHandler(name='presence', callback=self._process_muc_presence, - ns=NS_MUC, + ns=Namespace.MUC, priority=11), StanzaHandler(name='presence', callback=self._process_muc_user_presence, - ns=NS_MUC_USER, + ns=Namespace.MUC_USER, priority=11), StanzaHandler(name='message', callback=self._process_groupchat_message, @@ -77,26 +69,26 @@ class MUC(BaseModule): StanzaHandler(name='message', callback=self._process_mediated_invite, typ='normal', - ns=NS_MUC_USER, + ns=Namespace.MUC_USER, priority=11), StanzaHandler(name='message', callback=self._process_direct_invite, typ='normal', - ns=NS_CONFERENCE, + ns=Namespace.CONFERENCE, priority=12), StanzaHandler(name='message', callback=self._process_voice_request, - ns=NS_DATA, + ns=Namespace.DATA, priority=11), StanzaHandler(name='message', callback=self._process_message, - ns=NS_MUC_USER, + ns=Namespace.MUC_USER, priority=13), ] @staticmethod def _process_muc_presence(_client, stanza, properties): - muc = stanza.getTag('x', namespace=NS_MUC) + muc = stanza.getTag('x', namespace=Namespace.MUC) if muc is None: return properties.from_muc = True @@ -105,7 +97,7 @@ class MUC(BaseModule): properties.muc_nickname = properties.jid.getResource() def _process_muc_user_presence(self, _client, stanza, properties): - muc_user = stanza.getTag('x', namespace=NS_MUC_USER) + muc_user = stanza.getTag('x', namespace=Namespace.MUC_USER) if muc_user is None: return properties.from_muc = True @@ -175,7 +167,7 @@ class MUC(BaseModule): properties.muc_jid.setBare() properties.muc_nickname = properties.jid.getResource() or None - muc_user = stanza.getTag('x', namespace=NS_MUC_USER) + muc_user = stanza.getTag('x', namespace=Namespace.MUC_USER) if muc_user is not None: try: properties.muc_user = self._parse_muc_user(muc_user, @@ -185,14 +177,14 @@ class MUC(BaseModule): self._log.warning(stanza) raise NodeProcessed - addresses = stanza.getTag('addresses', namespace=NS_ADDRESS) + addresses = stanza.getTag('addresses', namespace=Namespace.ADDRESS) if addresses is not None: address = addresses.getTag('address', attrs={'type': 'ofrom'}) if address is not None: properties.muc_ofrom = JID(address.getAttr('jid')) def _process_message(self, _client, stanza, properties): - muc_user = stanza.getTag('x', namespace=NS_MUC_USER) + muc_user = stanza.getTag('x', namespace=Namespace.MUC_USER) if muc_user is None: return @@ -243,11 +235,11 @@ class MUC(BaseModule): @staticmethod def _process_direct_invite(_client, stanza, properties): - direct = stanza.getTag('x', namespace=NS_CONFERENCE) + direct = stanza.getTag('x', namespace=Namespace.CONFERENCE) if direct is None: return - if stanza.getTag('x', namespace=NS_MUC_USER) is not None: + if stanza.getTag('x', namespace=Namespace.MUC_USER) is not None: # not a direct invite # See https://xmpp.org/extensions/xep-0045.html#example-57 # read implementation notes @@ -265,7 +257,7 @@ class MUC(BaseModule): @staticmethod def _process_mediated_invite(_client, stanza, properties): - muc_user = stanza.getTag('x', namespace=NS_MUC_USER) + muc_user = stanza.getTag('x', namespace=Namespace.MUC_USER) if muc_user is None: return @@ -304,13 +296,13 @@ class MUC(BaseModule): return def _process_voice_request(self, _client, stanza, properties): - data_form = stanza.getTag('x', namespace=NS_DATA) + data_form = stanza.getTag('x', namespace=Namespace.DATA) if data_form is None: return data_form = extend_form(data_form) try: - if data_form['FORM_TYPE'].value != NS_MUC_REQUEST: + if data_form['FORM_TYPE'].value != Namespace.MUC_REQUEST: return except KeyError: return @@ -339,7 +331,7 @@ class MUC(BaseModule): @call_on_response('_affiliation_received') def get_affiliation(self, jid, affiliation): - iq = Iq(typ='get', to=jid, queryNS=NS_MUC_ADMIN) + iq = Iq(typ='get', to=jid, queryNS=Namespace.MUC_ADMIN) item = iq.setQuery().setTag('item') item.setAttr('affiliation', affiliation) return iq @@ -350,7 +342,7 @@ class MUC(BaseModule): return raise_error(self._log.info, stanza) room_jid = stanza.getFrom() - query = stanza.getTag('query', namespace=NS_MUC_ADMIN) + query = stanza.getTag('query', namespace=Namespace.MUC_ADMIN) items = query.getTags('item') users_dict = {} for item in items: @@ -377,7 +369,7 @@ class MUC(BaseModule): @call_on_response('_default_response') def destroy(self, room_jid, reason='', jid=''): - iq = Iq(typ='set', queryNS=NS_MUC_OWNER, to=room_jid) + iq = Iq(typ='set', queryNS=Namespace.MUC_OWNER, to=room_jid) destroy = iq.setQuery().setTag('destroy') if reason: destroy.setTagData('reason', reason) @@ -389,7 +381,7 @@ class MUC(BaseModule): @call_on_response('_default_response') def set_config(self, room_jid, form): - iq = Iq(typ='set', to=room_jid, queryNS=NS_MUC_OWNER) + iq = Iq(typ='set', to=room_jid, queryNS=Namespace.MUC_OWNER) query = iq.setQuery() form.setAttr('type', 'submit') query.addChild(node=form) @@ -399,7 +391,7 @@ class MUC(BaseModule): @call_on_response('_config_received') def request_config(self, room_jid): iq = Iq(typ='get', - queryNS=NS_MUC_OWNER, + queryNS=Namespace.MUC_OWNER, to=room_jid) self._log.info('Request config for %s', room_jid) return iq @@ -413,7 +405,7 @@ class MUC(BaseModule): payload = stanza.getQueryPayload() for form in payload: - if form.getNamespace() == NS_DATA: + if form.getNamespace() == Namespace.DATA: dataform = extend_form(node=form) self._log.info('Config form received for %s', jid) return MucConfigResult(jid=jid, @@ -422,9 +414,10 @@ class MUC(BaseModule): @call_on_response('_default_response') def cancel_config(self, room_jid): - cancel = Node(tag='x', attrs={'xmlns': NS_DATA, 'type': 'cancel'}) + cancel = Node(tag='x', attrs={'xmlns': Namespace.DATA, + 'type': 'cancel'}) iq = Iq(typ='set', - queryNS=NS_MUC_OWNER, + queryNS=Namespace.MUC_OWNER, payload=cancel, to=room_jid) self._log.info('Cancel config for %s', room_jid) @@ -432,7 +425,7 @@ class MUC(BaseModule): @call_on_response('_default_response') def set_affiliation(self, room_jid, users_dict): - iq = Iq(typ='set', to=room_jid, queryNS=NS_MUC_ADMIN) + iq = Iq(typ='set', to=room_jid, queryNS=Namespace.MUC_ADMIN) item = iq.setQuery() for jid in users_dict: affiliation = users_dict[jid].get('affiliation') @@ -450,7 +443,7 @@ class MUC(BaseModule): @call_on_response('_default_response') def set_role(self, room_jid, nick, role, reason=''): - iq = Iq(typ='set', to=room_jid, queryNS=NS_MUC_ADMIN) + iq = Iq(typ='set', to=room_jid, queryNS=Namespace.MUC_ADMIN) item = iq.setQuery().setTag('item') item.setAttr('nick', nick) item.setAttr('role', role) @@ -467,7 +460,7 @@ class MUC(BaseModule): def decline(self, room, to, reason=None): message = Message(to=room) - muc_user = message.addChild('x', namespace=NS_MUC_USER) + muc_user = message.addChild('x', namespace=Namespace.MUC_USER) decline = muc_user.addChild('decline', attrs={'to': to}) if reason: decline.setTagData('reason', reason) @@ -477,7 +470,7 @@ class MUC(BaseModule): message = Message(to=room) xdata = DataForm(typ='submit') xdata.addChild(node=DataField(name='FORM_TYPE', - value=NS_MUC_REQUEST)) + value=Namespace.MUC_REQUEST)) xdata.addChild(node=DataField(name='muc#role', value='participant', typ='text-single')) @@ -505,13 +498,13 @@ class MUC(BaseModule): if password: attrs['password'] = password message.addChild(name='x', attrs=attrs, - namespace=NS_CONFERENCE) + namespace=Namespace.CONFERENCE) return message @staticmethod def _build_mediated_invite(room, to, reason, password, continue_): message = Message(to=room) - muc_user = message.addChild('x', namespace=NS_MUC_USER) + muc_user = message.addChild('x', namespace=Namespace.MUC_USER) invite = muc_user.addChild('invite', attrs={'to': to}) if continue_: invite.addChild(name='continue') @@ -524,7 +517,7 @@ class MUC(BaseModule): @call_on_response('_default_response') def send_captcha(self, room_jid, form_node): iq = Iq(typ='set', to=room_jid) - captcha = iq.addChild(name='captcha', namespace=NS_CAPTCHA) + captcha = iq.addChild(name='captcha', namespace=Namespace.CAPTCHA) captcha.addChild(node=form_node) return iq diff --git a/nbxmpp/modules/muclumbus.py b/nbxmpp/modules/muclumbus.py index 039f974..b5b2e85 100644 --- a/nbxmpp/modules/muclumbus.py +++ b/nbxmpp/modules/muclumbus.py @@ -19,9 +19,7 @@ import json from gi.repository import Soup -from nbxmpp.protocol import NS_MUCLUMBUS -from nbxmpp.protocol import NS_DATA -from nbxmpp.protocol import NS_RSM +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode @@ -57,7 +55,8 @@ class Muclumbus(BaseModule): @call_on_response('_parameters_received') def request_parameters(self, jid): query = Iq(to=jid, typ='get') - query.addChild(node=Node('search', attrs={'xmlns': NS_MUCLUMBUS})) + query.addChild(node=Node('search', + attrs={'xmlns': Namespace.MUCLUMBUS})) return query @callback @@ -65,11 +64,11 @@ class Muclumbus(BaseModule): if not isResultNode(stanza): return raise_error(self._log.info, stanza) - search = stanza.getTag('search', namespace=NS_MUCLUMBUS) + search = stanza.getTag('search', namespace=Namespace.MUCLUMBUS) if search is None: return raise_error(self._log.warning, stanza, 'stanza-malformed') - dataform = search.getTag('x', namespace=NS_DATA) + dataform = search.getTag('x', namespace=Namespace.DATA) if dataform is None: return raise_error(self._log.warning, stanza, 'stanza-malformed') @@ -78,9 +77,9 @@ class Muclumbus(BaseModule): @call_on_response('_search_received') def set_search(self, jid, dataform, items_per_page=50, after=None): - search = Node('search', attrs={'xmlns': NS_MUCLUMBUS}) + search = Node('search', attrs={'xmlns': Namespace.MUCLUMBUS}) search.addChild(node=dataform) - rsm = search.addChild('set', namespace=NS_RSM) + rsm = search.addChild('set', namespace=Namespace.RSM) rsm.addChild('max').setData(items_per_page) if after is not None: rsm.addChild('after').setData(after) @@ -109,7 +108,7 @@ class Muclumbus(BaseModule): if not isResultNode(stanza): return raise_error(self._log.info, stanza) - result = stanza.getTag('result', namespace=NS_MUCLUMBUS) + result = stanza.getTag('result', namespace=Namespace.MUCLUMBUS) if result is None: return raise_error(self._log.warning, stanza, 'stanza-malformed') @@ -121,7 +120,7 @@ class Muclumbus(BaseModule): end=True, items=[]) - set_ = result.getTag('set', namespace=NS_RSM) + set_ = result.getTag('set', namespace=Namespace.RSM) if set_ is None: return raise_error(self._log.warning, stanza, 'stanza-malformed') diff --git a/nbxmpp/modules/nickname.py b/nbxmpp/modules/nickname.py index 4093d8d..54fede4 100644 --- a/nbxmpp/modules/nickname.py +++ b/nbxmpp/modules/nickname.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_NICK -from nbxmpp.protocol import NS_PUBSUB_EVENT +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.structs import StanzaHandler from nbxmpp.const import PresenceType @@ -31,15 +30,15 @@ class Nickname(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_nickname, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), StanzaHandler(name='message', callback=self._process_nickname, - ns=NS_NICK, + ns=Namespace.NICK, priority=40), StanzaHandler(name='presence', callback=self._process_nickname, - ns=NS_NICK, + ns=Namespace.NICK, priority=40), ] @@ -60,7 +59,7 @@ class Nickname(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_NICK: + if properties.pubsub_event.node != Namespace.NICK: return item = properties.pubsub_event.item @@ -79,15 +78,15 @@ class Nickname(BaseModule): @staticmethod def _parse_nickname(stanza): - nickname = stanza.getTag('nick', namespace=NS_NICK) + nickname = stanza.getTag('nick', namespace=Namespace.NICK) if nickname is None: return None return nickname.getData() or None def set_nickname(self, nickname): - item = Node('nick', {'xmlns': NS_NICK}) + item = Node('nick', {'xmlns': Namespace.NICK}) if nickname is not None: item.addData(nickname) jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_NICK, item, id_='current') + jid, Namespace.NICK, item, id_='current') diff --git a/nbxmpp/modules/omemo.py b/nbxmpp/modules/omemo.py index 97c244a..91ec267 100644 --- a/nbxmpp/modules/omemo.py +++ b/nbxmpp/modules/omemo.py @@ -15,12 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_OMEMO_TEMP -from nbxmpp.protocol import NS_OMEMO_TEMP_DL -from nbxmpp.protocol import NS_OMEMO_TEMP_BUNDLE -from nbxmpp.protocol import NS_PUBSUB_EVENT -from nbxmpp.protocol import NS_EME -from nbxmpp.protocol import NS_HINTS +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import Node from nbxmpp.protocol import Message @@ -46,11 +41,11 @@ class OMEMO(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_omemo_devicelist, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), StanzaHandler(name='message', callback=self._process_omemo_message, - ns=NS_OMEMO_TEMP, + ns=Namespace.OMEMO_TEMP, priority=7), ] @@ -79,7 +74,7 @@ class OMEMO(BaseModule): <store xmlns='urn:xmpp:hints'/> </message> ''' - encrypted = stanza.getTag('encrypted', namespace=NS_OMEMO_TEMP) + encrypted = stanza.getTag('encrypted', namespace=Namespace.OMEMO_TEMP) if encrypted is None: raise StanzaMalformed('No encrypted node found') @@ -129,7 +124,7 @@ class OMEMO(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_OMEMO_TEMP_DL: + if properties.pubsub_event.node != Namespace.OMEMO_TEMP_DL: return item = properties.pubsub_event.item @@ -167,7 +162,7 @@ class OMEMO(BaseModule): </item> </items> ''' - list_node = item.getTag('list', namespace=NS_OMEMO_TEMP) + list_node = item.getTag('list', namespace=Namespace.OMEMO_TEMP) if list_node is None: raise StanzaMalformed('No list node found') @@ -184,21 +179,21 @@ class OMEMO(BaseModule): return result def set_devicelist(self, devicelist=None): - item = Node('list', attrs={'xmlns': NS_OMEMO_TEMP}) + item = Node('list', attrs={'xmlns': Namespace.OMEMO_TEMP}) for device in devicelist: item.addChild('device').setAttr('id', device) self._log.info('Set devicelist: %s', devicelist) jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_OMEMO_TEMP_DL, item, id_='current') + jid, Namespace.OMEMO_TEMP_DL, item, id_='current') @call_on_response('_devicelist_received') def request_devicelist(self, jid=None): if jid is None: jid = self._client.get_bound_jid().getBare() self._log.info('Request devicelist from: %s', jid) - return get_pubsub_request(jid, NS_OMEMO_TEMP_DL, max_items=1) + return get_pubsub_request(jid, Namespace.OMEMO_TEMP_DL, max_items=1) @callback def _devicelist_received(self, stanza): @@ -221,7 +216,7 @@ class OMEMO(BaseModule): item = self._create_bundle(bundle) self._log.info('Set bundle') - node = '%s:%s' % (NS_OMEMO_TEMP_BUNDLE, device_id) + node = '%s:%s' % (Namespace.OMEMO_TEMP_BUNDLE, device_id) jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( jid, node, item, id_='current') @@ -257,7 +252,7 @@ class OMEMO(BaseModule): </item> </publish> ''' - bundle_node = Node('bundle', attrs={'xmlns': NS_OMEMO_TEMP}) + bundle_node = Node('bundle', attrs={'xmlns': Namespace.OMEMO_TEMP}) prekey_pub_node = bundle_node.addChild( 'signedPreKeyPublic', attrs={'signedPreKeyId': bundle.spk['id']}) @@ -279,7 +274,7 @@ class OMEMO(BaseModule): @call_on_response('_bundle_received') def request_bundle(self, jid, device_id): self._log.info('Request bundle from: %s %s', jid, device_id) - node = '%s:%s' % (NS_OMEMO_TEMP_BUNDLE, device_id) + node = '%s:%s' % (Namespace.OMEMO_TEMP_BUNDLE, device_id) return get_pubsub_request(jid, node, max_items=1) @callback @@ -329,7 +324,7 @@ class OMEMO(BaseModule): if item is None: raise StanzaMalformed('No item in node found') - bundle = item.getTag('bundle', namespace=NS_OMEMO_TEMP) + bundle = item.getTag('bundle', namespace=Namespace.OMEMO_TEMP) if bundle is None: raise StanzaMalformed('No bundle node found') @@ -405,7 +400,7 @@ def create_omemo_message(stanza, omemo_message, store_hint=True, if node_whitelist is not None: cleanup_stanza(stanza, node_whitelist) - encrypted = Node('encrypted', attrs={'xmlns': NS_OMEMO_TEMP}) + encrypted = Node('encrypted', attrs={'xmlns': Namespace.OMEMO_TEMP}) header = Node('header', attrs={'sid': omemo_message.sid}) for rid, (key, prekey) in omemo_message.keys.items(): attrs = {'rid': rid} @@ -422,21 +417,22 @@ def create_omemo_message(stanza, omemo_message, store_hint=True, stanza.addChild(node=encrypted) - stanza.addChild(node=Node('encryption', attrs={'xmlns': NS_EME, - 'name': 'OMEMO', - 'namespace': NS_OMEMO_TEMP})) + stanza.addChild(node=Node('encryption', + attrs={'xmlns': Namespace.EME, + 'name': 'OMEMO', + 'namespace': Namespace.OMEMO_TEMP})) stanza.setBody("You received a message encrypted with " "OMEMO but your client doesn't support OMEMO.") if store_hint: - stanza.addChild(node=Node('store', attrs={'xmlns': NS_HINTS})) + stanza.addChild(node=Node('store', attrs={'xmlns': Namespace.HINTS})) def get_key_transport_message(typ, jid, omemo_message): message = Message(typ=typ, to=jid) - encrypted = Node('encrypted', attrs={'xmlns': NS_OMEMO_TEMP}) + encrypted = Node('encrypted', attrs={'xmlns': Namespace.OMEMO_TEMP}) header = Node('header', attrs={'sid': omemo_message.sid}) for rid, (key, prekey) in omemo_message.keys.items(): attrs = {'rid': rid} diff --git a/nbxmpp/modules/oob.py b/nbxmpp/modules/oob.py index e7e4833..2242e65 100644 --- a/nbxmpp/modules/oob.py +++ b/nbxmpp/modules/oob.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_X_OOB +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import OOBData from nbxmpp.modules.base import BaseModule @@ -29,12 +29,12 @@ class OOB(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_oob, - ns=NS_X_OOB, + ns=Namespace.X_OOB, priority=15), ] def _process_message_oob(self, _client, stanza, properties): - oob = stanza.getTag('x', namespace=NS_X_OOB) + oob = stanza.getTag('x', namespace=Namespace.X_OOB) if oob is None: return diff --git a/nbxmpp/modules/openpgp.py b/nbxmpp/modules/openpgp.py index 5611f32..2128882 100644 --- a/nbxmpp/modules/openpgp.py +++ b/nbxmpp/modules/openpgp.py @@ -19,12 +19,7 @@ import time import random import string -from nbxmpp.protocol import NS_OPENPGP -from nbxmpp.protocol import NS_OPENPGP_PK -from nbxmpp.protocol import NS_OPENPGP_SK -from nbxmpp.protocol import NS_PUBSUB_EVENT -from nbxmpp.protocol import NS_CLIENT -from nbxmpp.protocol import NS_EME +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import Node from nbxmpp.protocol import isResultNode @@ -51,16 +46,16 @@ class OpenPGP(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_openpgp, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), StanzaHandler(name='message', callback=self._process_openpgp_message, - ns=NS_OPENPGP, + ns=Namespace.OPENPGP, priority=7), ] def _process_openpgp_message(self, _client, stanza, properties): - openpgp = stanza.getTag('openpgp', namespace=NS_OPENPGP) + openpgp = stanza.getTag('openpgp', namespace=Namespace.OPENPGP) if openpgp is None: self._log.warning('No openpgp node found') self._log.warning(stanza) @@ -99,7 +94,7 @@ class OpenPGP(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_OPENPGP_PK: + if properties.pubsub_event.node != Namespace.OPENPGP_PK: return item = properties.pubsub_event.item @@ -126,7 +121,8 @@ class OpenPGP(BaseModule): @staticmethod def _parse_keylist(jid, item): - keylist_node = item.getTag('public-keys-list', namespace=NS_OPENPGP) + keylist_node = item.getTag('public-keys-list', + namespace=Namespace.OPENPGP) if keylist_node is None: raise StanzaMalformed('No public-keys-list node found') @@ -149,7 +145,7 @@ class OpenPGP(BaseModule): return data def set_keylist(self, keylist): - item = Node('public-keys-list', {'xmlns': NS_OPENPGP}) + item = Node('public-keys-list', {'xmlns': Namespace.OPENPGP}) if keylist is not None: for key in keylist: date = time.strftime('%Y-%m-%dT%H:%M:%SZ', @@ -161,16 +157,16 @@ class OpenPGP(BaseModule): self._log.info('Set keylist: %s', keylist) jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_OPENPGP_PK, item, id_='current') + jid, Namespace.OPENPGP_PK, item, id_='current') def set_public_key(self, key, fingerprint, date): date = time.strftime( '%Y-%m-%dT%H:%M:%SZ', time.gmtime(date)) - item = Node('pubkey', attrs={'xmlns': NS_OPENPGP, + item = Node('pubkey', attrs={'xmlns': Namespace.OPENPGP, 'date': date}) data = item.addChild('data') data.addData(b64encode(key)) - node = '%s:%s' % (NS_OPENPGP_PK, fingerprint) + node = '%s:%s' % (Namespace.OPENPGP_PK, fingerprint) self._log.info('Set public key') jid = self._client.get_bound_jid().getBare() @@ -180,7 +176,7 @@ class OpenPGP(BaseModule): @call_on_response('_public_key_received') def request_public_key(self, jid, fingerprint): self._log.info('Request public key from: %s %s', jid, fingerprint) - node = '%s:%s' % (NS_OPENPGP_PK, fingerprint) + node = '%s:%s' % (Namespace.OPENPGP_PK, fingerprint) return get_pubsub_request(jid, node, max_items=1) @callback @@ -194,7 +190,7 @@ class OpenPGP(BaseModule): items_node = pubsub_node.getTag('items') item = items_node.getTag('item') - pub_key = item.getTag('pubkey', namespace=NS_OPENPGP) + pub_key = item.getTag('pubkey', namespace=Namespace.OPENPGP) if pub_key is None: return raise_error(self._log.warning, stanza, 'stanza-malformed', 'PGP public key has no pubkey node') @@ -219,7 +215,7 @@ class OpenPGP(BaseModule): @call_on_response('_keylist_received') def request_keylist(self, jid): self._log.info('Request keylist from: %s', jid) - return get_pubsub_request(jid, NS_OPENPGP_PK, max_items=1) + return get_pubsub_request(jid, Namespace.OPENPGP_PK, max_items=1) @callback def _keylist_received(self, stanza): @@ -244,7 +240,7 @@ class OpenPGP(BaseModule): def request_secret_key(self): self._log.info('Request secret key') jid = self._client.get_bound_jid().getBare() - return get_pubsub_request(jid, NS_OPENPGP_SK, max_items=1) + return get_pubsub_request(jid, Namespace.OPENPGP_SK, max_items=1) @callback def _secret_key_received(self, stanza): @@ -255,7 +251,7 @@ class OpenPGP(BaseModule): items_node = pubsub_node.getTag('items') item = items_node.getTag('item') - sec_key = item.getTag('secretkey', namespace=NS_OPENPGP) + sec_key = item.getTag('secretkey', namespace=Namespace.OPENPGP) if sec_key is None: return raise_error(self._log.warning, stanza, 'stanza-malformed', 'PGP secretkey node not found') @@ -274,14 +270,14 @@ class OpenPGP(BaseModule): return key def set_secret_key(self, secret_key): - item = Node('secretkey', {'xmlns': NS_OPENPGP}) + item = Node('secretkey', {'xmlns': Namespace.OPENPGP}) if secret_key is not None: item.setData(b64encode(secret_key)) self._log.info('Set secret key') jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_OPENPGP_SK, item, id_='current') + jid, Namespace.OPENPGP_SK, item, id_='current') def parse_signcrypt(stanza): @@ -299,7 +295,8 @@ def parse_signcrypt(stanza): </payload> </signcrypt> ''' - if stanza.getName() != 'signcrypt' or stanza.getNamespace() != NS_OPENPGP: + if (stanza.getName() != 'signcrypt' or + stanza.getNamespace() != Namespace.OPENPGP): raise StanzaMalformed('Invalid signcrypt node') to = stanza.getTagAttr('to', 'jid') @@ -336,11 +333,11 @@ def create_signcrypt_node(stanza, not_encrypted_nodes): for node in child_nodes: if (node.getName(), node.getNamespace()) not in not_encrypted_nodes: if not node.getNamespace(): - node.setNamespace(NS_CLIENT) + node.setNamespace(Namespace.CLIENT) encrypted_nodes.append(node) stanza.delChild(node) - signcrypt = Node('signcrypt', attrs={'xmlns': NS_OPENPGP}) + signcrypt = Node('signcrypt', attrs={'xmlns': Namespace.OPENPGP}) signcrypt.addChild('to', attrs={'jid': stanza.getTo().getBare()}) timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()) @@ -365,12 +362,12 @@ def get_rpad(): def create_message_stanza(stanza, encrypted_payload, with_fallback_text): b64encoded_payload = b64encode(encrypted_payload) - openpgp_node = Node('openpgp', attrs={'xmlns': NS_OPENPGP}) + openpgp_node = Node('openpgp', attrs={'xmlns': Namespace.OPENPGP}) openpgp_node.addData(b64encoded_payload) stanza.addChild(node=openpgp_node) - eme_node = Node('encryption', attrs={'xmlns': NS_EME, - 'namespace': NS_OPENPGP}) + eme_node = Node('encryption', attrs={'xmlns': Namespace.EME, + 'namespace': Namespace.OPENPGP}) stanza.addChild(node=eme_node) if with_fallback_text: diff --git a/nbxmpp/modules/pgplegacy.py b/nbxmpp/modules/pgplegacy.py index 4ed2cb8..1b8c4c1 100644 --- a/nbxmpp/modules/pgplegacy.py +++ b/nbxmpp/modules/pgplegacy.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_SIGNED -from nbxmpp.protocol import NS_ENCRYPTED +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.modules.base import BaseModule @@ -29,24 +28,24 @@ class PGPLegacy(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pgplegacy_message, - ns=NS_ENCRYPTED, + ns=Namespace.ENCRYPTED, priority=7), StanzaHandler(name='presence', callback=self._process_signed, - ns=NS_SIGNED, + ns=Namespace.SIGNED, priority=15) ] @staticmethod def _process_signed(_client, stanza, properties): - signed = stanza.getTag('x', namespace=NS_SIGNED) + signed = stanza.getTag('x', namespace=Namespace.SIGNED) if signed is None: return properties.signed = signed.getData() def _process_pgplegacy_message(self, _client, stanza, properties): - pgplegacy = stanza.getTag('x', namespace=NS_ENCRYPTED) + pgplegacy = stanza.getTag('x', namespace=Namespace.ENCRYPTED) if pgplegacy is None: self._log.warning('No x node found') self._log.warning(stanza) diff --git a/nbxmpp/modules/pubsub.py b/nbxmpp/modules/pubsub.py index fa91eb9..4c40ee0 100644 --- a/nbxmpp/modules/pubsub.py +++ b/nbxmpp/modules/pubsub.py @@ -15,12 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_PUBSUB -from nbxmpp.protocol import NS_PUBSUB_EVENT -from nbxmpp.protocol import NS_PUBSUB_PUBLISH_OPTIONS -from nbxmpp.protocol import NS_PUBSUB_OWNER -from nbxmpp.protocol import NS_PUBSUB_CONFIG -from nbxmpp.protocol import NS_DATA +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode @@ -44,13 +39,13 @@ class PubSub(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_base, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=15), ] def _process_pubsub_base(self, _client, stanza, properties): properties.pubsub = True - event = stanza.getTag('event', namespace=NS_PUBSUB_EVENT) + event = stanza.getTag('event', namespace=Namespace.PUBSUB_EVENT) delete = event.getTag('delete') if delete is not None: @@ -92,7 +87,7 @@ class PubSub(BaseModule): @call_on_response('_publish_result_received') def publish(self, jid, node, item, id_=None, options=None): query = Iq('set', to=jid) - pubsub = query.addChild('pubsub', namespace=NS_PUBSUB) + pubsub = query.addChild('pubsub', namespace=Namespace.PUBSUB) publish = pubsub.addChild('publish', {'node': node}) attrs = {} if id_ is not None: @@ -109,7 +104,7 @@ class PubSub(BaseModule): return raise_error(self._log.warning, stanza) jid = stanza.getFrom() - pubsub = stanza.getTag('pubsub', namespace=NS_PUBSUB) + pubsub = stanza.getTag('pubsub', namespace=Namespace.PUBSUB) if pubsub is None: # XEP-0060: IQ payload is not mandatory on result return PubSubPublishResult(jid, None, None) @@ -129,7 +124,7 @@ class PubSub(BaseModule): @call_on_response('_default_response') def retract(self, jid, node, id_, notify=True): query = Iq('set', to=jid) - pubsub = query.addChild('pubsub', namespace=NS_PUBSUB) + pubsub = query.addChild('pubsub', namespace=Namespace.PUBSUB) attrs = {'node': node} if notify: attrs['notify'] = 'true' @@ -141,7 +136,7 @@ class PubSub(BaseModule): def set_node_configuration(self, jid, node, form): self._log.info('Set configuration for %s %s', node, jid) query = Iq('set', to=jid) - pubsub = query.addChild('pubsub', namespace=NS_PUBSUB_OWNER) + pubsub = query.addChild('pubsub', namespace=Namespace.PUBSUB_OWNER) configure = pubsub.addChild('configure', {'node': node}) form.setAttr('type', 'submit') configure.addChild(node=form) @@ -151,7 +146,7 @@ class PubSub(BaseModule): def get_node_configuration(self, jid, node): self._log.info('Request node configuration') query = Iq('get', to=jid) - pubsub = query.addChild('pubsub', namespace=NS_PUBSUB_OWNER) + pubsub = query.addChild('pubsub', namespace=Namespace.PUBSUB_OWNER) pubsub.addChild('configure', {'node': node}) return query @@ -161,7 +156,7 @@ class PubSub(BaseModule): return raise_error(self._log.warning, stanza) jid = stanza.getFrom() - pubsub = stanza.getTag('pubsub', namespace=NS_PUBSUB_OWNER) + pubsub = stanza.getTag('pubsub', namespace=Namespace.PUBSUB_OWNER) if pubsub is None: return raise_error(self._log.warning, stanza, 'stanza-malformed', 'No pubsub node found') @@ -173,11 +168,11 @@ class PubSub(BaseModule): node = configure.getAttr('node') - forms = configure.getTags('x', namespace=NS_DATA) + forms = configure.getTags('x', namespace=Namespace.DATA) for form in forms: dataform = extend_form(node=form) form_type = dataform.vars.get('FORM_TYPE') - if form_type is None or form_type.value != NS_PUBSUB_CONFIG: + if form_type is None or form_type.value != Namespace.PUBSUB_CONFIG: continue self._log.info('Node configuration received from: %s', jid) return PubSubConfigResult(jid=jid, node=node, form=dataform) @@ -194,7 +189,7 @@ class PubSub(BaseModule): def get_pubsub_request(jid, node, id_=None, max_items=None): query = Iq('get', to=jid) - pubsub = query.addChild('pubsub', namespace=NS_PUBSUB) + pubsub = query.addChild('pubsub', namespace=Namespace.PUBSUB) items = pubsub.addChild('items', {'node': node}) if max_items is not None: items.setAttr('max_items', max_items) @@ -221,10 +216,10 @@ def get_pubsub_items(stanza, node=None): def get_publish_options(config): - options = Node(NS_DATA + ' x', attrs={'type': 'submit'}) + options = Node(Namespace.DATA + ' x', attrs={'type': 'submit'}) field = options.addChild('field', attrs={'var': 'FORM_TYPE', 'type': 'hidden'}) - field.setTagData('value', NS_PUBSUB_PUBLISH_OPTIONS) + field.setTagData('value', Namespace.PUBSUB_PUBLISH_OPTIONS) for var, value in config.items(): field = options.addChild('field', attrs={'var': var}) diff --git a/nbxmpp/modules/receipts.py b/nbxmpp/modules/receipts.py index 676e9ad..e8fb649 100644 --- a/nbxmpp/modules/receipts.py +++ b/nbxmpp/modules/receipts.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_RECEIPTS -from nbxmpp.protocol import NS_MUC_USER +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import isMucPM from nbxmpp.protocol import Message from nbxmpp.structs import StanzaHandler @@ -33,17 +32,17 @@ class Receipts(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_receipt, - ns=NS_RECEIPTS, + ns=Namespace.RECEIPTS, priority=15), ] def _process_message_receipt(self, _client, stanza, properties): - request = stanza.getTag('request', namespace=NS_RECEIPTS) + request = stanza.getTag('request', namespace=Namespace.RECEIPTS) if request is not None: properties.receipt = ReceiptData(request.getName()) return - received = stanza.getTag('received', namespace=NS_RECEIPTS) + received = stanza.getTag('received', namespace=Namespace.RECEIPTS) if received is not None: id_ = received.getAttr('id') if id_ is None: @@ -64,7 +63,7 @@ def build_receipt(stanza): if stanza.getID() is None: raise ValueError('Receipt can not be generated for messages without id') - if stanza.getTag('received', namespace=NS_RECEIPTS) is not None: + if stanza.getTag('received', namespace=Namespace.RECEIPTS) is not None: raise ValueError('Receipt can not be generated for receipts') is_muc_pm = isMucPM(stanza) @@ -76,7 +75,7 @@ def build_receipt(stanza): message = Message(to=jid, typ=typ) if is_muc_pm: - message.setTag('x', namespace=NS_MUC_USER) + message.setTag('x', namespace=Namespace.MUC_USER) message_id = generate_id() message.setID(message_id) message.setReceiptReceived(stanza.getID()) diff --git a/nbxmpp/modules/register.py b/nbxmpp/modules/register.py index 710246a..45104c8 100644 --- a/nbxmpp/modules/register.py +++ b/nbxmpp/modules/register.py @@ -15,9 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_X_OOB -from nbxmpp.protocol import NS_DATA -from nbxmpp.protocol import NS_REGISTER +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode from nbxmpp.structs import CommonResult @@ -47,7 +45,7 @@ class Register(BaseModule): def unregister(self, jid=None): iq = Iq('set', to=jid) query = iq.setQuery() - query.setNamespace(NS_REGISTER) + query.setNamespace(Namespace.REGISTER) query.addChild('remove') return iq @@ -55,7 +53,7 @@ class Register(BaseModule): def request_register_form(self, jid=None): if jid is None: jid = self._client.domain - return Iq('get', NS_REGISTER, to=jid) + return Iq('get', Namespace.REGISTER, to=jid) @callback def _on_register_form(self, stanza): @@ -82,7 +80,7 @@ class Register(BaseModule): if jid is None: jid = self._client.domain - iq = Iq('set', NS_REGISTER, to=jid) + iq = Iq('set', Namespace.REGISTER, to=jid) if form.is_fake_form(): query = iq.getTag('query') @@ -100,7 +98,7 @@ class Register(BaseModule): if isResultNode(stanza): return CommonResult(jid=stanza.getFrom()) - query = stanza.getTag('query', namespace=NS_REGISTER) + query = stanza.getTag('query', namespace=Namespace.REGISTER) if query is None: return RegisterError(stanza, None) @@ -122,14 +120,14 @@ class Register(BaseModule): @staticmethod def _parse_oob_url(query): - oob = query.getTag('x', namespace=NS_X_OOB) + oob = query.getTag('x', namespace=Namespace.X_OOB) if oob is not None: return oob.getTagData('url') or None return None def _parse_form(self, stanza): - query = stanza.getTag('query', namespace=NS_REGISTER) - form = query.getTag('x', namespace=NS_DATA) + query = stanza.getTag('query', namespace=Namespace.REGISTER) + form = query.getTag('x', namespace=Namespace.DATA) if form is None: return None @@ -172,7 +170,7 @@ class Register(BaseModule): def change_password(self, password): domain = self._client.get_bound_jid().getDomain() username = self._client.get_bound_jid().getNode() - iq = Iq('set', NS_REGISTER, to=domain) + iq = Iq('set', Namespace.REGISTER, to=domain) query = iq.getQuery() query.setTagData('username', username) query.setTagData('password', password) @@ -195,7 +193,7 @@ class Register(BaseModule): @call_on_response('_default_response') def change_password_with_form(self, form): domain = self._client.get_bound_jid().getDomain() - iq = Iq('set', NS_REGISTER, to=domain) + iq = Iq('set', Namespace.REGISTER, to=domain) iq.setQueryPayload(form) return iq diff --git a/nbxmpp/modules/rsm.py b/nbxmpp/modules/rsm.py index 89cb094..554467d 100644 --- a/nbxmpp/modules/rsm.py +++ b/nbxmpp/modules/rsm.py @@ -15,13 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_RSM - +from nbxmpp.namespaces import Namespace from nbxmpp.structs import RSMData def parse_rsm(stanza): - stanza = stanza.getTag('set', namespace=NS_RSM) + stanza = stanza.getTag('set', namespace=Namespace.RSM) if stanza is None: return None diff --git a/nbxmpp/modules/security_labels.py b/nbxmpp/modules/security_labels.py index b1e812c..76c55e9 100644 --- a/nbxmpp/modules/security_labels.py +++ b/nbxmpp/modules/security_labels.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_SECLABEL +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.structs import SecurityLabel from nbxmpp.structs import DisplayMarking @@ -30,12 +30,12 @@ class SecurityLabels(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_message_security_label, - ns=NS_SECLABEL, + ns=Namespace.SECLABEL, priority=15), ] def _process_message_security_label(self, _client, stanza, properties): - security = stanza.getTag('securitylabel', namespace=NS_SECLABEL) + security = stanza.getTag('securitylabel', namespace=Namespace.SECLABEL) if security is None: return diff --git a/nbxmpp/modules/software_version.py b/nbxmpp/modules/software_version.py index aa817c6..bfaedc9 100644 --- a/nbxmpp/modules/software_version.py +++ b/nbxmpp/modules/software_version.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_VERSION +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Iq from nbxmpp.protocol import isResultNode from nbxmpp.protocol import ErrorNode @@ -38,7 +38,7 @@ class SoftwareVersion(BaseModule): StanzaHandler(name='iq', callback=self._answer_request, typ='get', - ns=NS_VERSION), + ns=Namespace.VERSION), ] self._name = None @@ -53,7 +53,7 @@ class SoftwareVersion(BaseModule): @call_on_response('_software_version_received') def request_software_version(self, jid): self._log.info('Request software version for %s', jid) - return Iq(typ='get', to=jid, queryNS=NS_VERSION) + return Iq(typ='get', to=jid, queryNS=Namespace.VERSION) @callback def _software_version_received(self, stanza): diff --git a/nbxmpp/modules/tune.py b/nbxmpp/modules/tune.py index 9df7398..92acc38 100644 --- a/nbxmpp/modules/tune.py +++ b/nbxmpp/modules/tune.py @@ -15,8 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_TUNE -from nbxmpp.protocol import NS_PUBSUB_EVENT +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import Node from nbxmpp.structs import StanzaHandler from nbxmpp.structs import TuneData @@ -32,7 +31,7 @@ class Tune(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_tune, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), ] @@ -40,7 +39,7 @@ class Tune(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_TUNE: + if properties.pubsub_event.node != Namespace.TUNE: return item = properties.pubsub_event.item @@ -48,7 +47,7 @@ class Tune(BaseModule): # Retract, Deleted or Purged return - tune_node = item.getTag('tune', namespace=NS_TUNE) + tune_node = item.getTag('tune', namespace=Namespace.TUNE) if not tune_node.getChildren(): self._log.info('Received tune: %s - no tune set', properties.jid) return @@ -64,7 +63,7 @@ class Tune(BaseModule): properties.pubsub_event = pubsub_event def set_tune(self, data): - item = Node('tune', {'xmlns': NS_TUNE}) + item = Node('tune', {'xmlns': Namespace.TUNE}) if data is None: return @@ -75,4 +74,4 @@ class Tune(BaseModule): jid = self._client.get_bound_jid().getBare() self._client.get_module('PubSub').publish( - jid, NS_TUNE, item, id_='current') + jid, Namespace.TUNE, item, id_='current') diff --git a/nbxmpp/modules/user_avatar.py b/nbxmpp/modules/user_avatar.py index 0421a44..0039681 100644 --- a/nbxmpp/modules/user_avatar.py +++ b/nbxmpp/modules/user_avatar.py @@ -17,9 +17,7 @@ import base64 -from nbxmpp.protocol import NS_AVATAR_DATA -from nbxmpp.protocol import NS_AVATAR_METADATA -from nbxmpp.protocol import NS_PUBSUB_EVENT +from nbxmpp.namespaces import Namespace from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import isResultNode from nbxmpp.protocol import JID @@ -41,7 +39,7 @@ class UserAvatar(BaseModule): self.handlers = [ StanzaHandler(name='message', callback=self._process_pubsub_avatar, - ns=NS_PUBSUB_EVENT, + ns=Namespace.PUBSUB_EVENT, priority=16), ] @@ -49,7 +47,7 @@ class UserAvatar(BaseModule): if not properties.is_pubsub_event: return - if properties.pubsub_event.node != NS_AVATAR_METADATA: + if properties.pubsub_event.node != Namespace.AVATAR_METADATA: return item = properties.pubsub_event.item @@ -57,7 +55,7 @@ class UserAvatar(BaseModule): # Retract, Deleted or Purged return - metadata = item.getTag('metadata', namespace=NS_AVATAR_METADATA) + metadata = item.getTag('metadata', namespace=Namespace.AVATAR_METADATA) if metadata is None: self._log.warning('No metadata node found') self._log.warning(stanza) @@ -84,7 +82,7 @@ class UserAvatar(BaseModule): @call_on_response('_avatar_data_received') def request_avatar(self, jid, id_): - return get_pubsub_request(jid, NS_AVATAR_DATA, id_=id_) + return get_pubsub_request(jid, Namespace.AVATAR_DATA, id_=id_) @callback def _avatar_data_received(self, stanza): @@ -103,7 +101,7 @@ class UserAvatar(BaseModule): 'No item in node found') sha = item.getAttr('id') - data_node = item.getTag('data', namespace=NS_AVATAR_DATA) + data_node = item.getTag('data', namespace=Namespace.AVATAR_DATA) if data_node is None: return raise_error(self._log.warning, stanza, 'stanza-malformed', 'No data node found') diff --git a/nbxmpp/modules/vcard_avatar.py b/nbxmpp/modules/vcard_avatar.py index d535ff0..01a7ca2 100644 --- a/nbxmpp/modules/vcard_avatar.py +++ b/nbxmpp/modules/vcard_avatar.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. -from nbxmpp.protocol import NS_VCARD_UPDATE +from nbxmpp.namespaces import Namespace from nbxmpp.structs import StanzaHandler from nbxmpp.const import PresenceType from nbxmpp.const import AvatarState @@ -30,7 +30,7 @@ class VCardAvatar(BaseModule): self.handlers = [ StanzaHandler(name='presence', callback=self._process_avatar, - ns=NS_VCARD_UPDATE, + ns=Namespace.VCARD_UPDATE, priority=15) ] @@ -38,7 +38,7 @@ class VCardAvatar(BaseModule): if properties.type != PresenceType.AVAILABLE: return - update = stanza.getTag('x', namespace=NS_VCARD_UPDATE) + update = stanza.getTag('x', namespace=Namespace.VCARD_UPDATE) if update is None: return |