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:
authorlovetox <philipp@hoerist.com>2020-04-19 21:33:55 +0300
committerlovetox <philipp@hoerist.com>2020-04-19 21:33:55 +0300
commitdb7b78d5f350017792b250e111f5e3eaabfa9d98 (patch)
treede0836071028b511c817fc86c8c1d7ab651be417
parent7712aa5914d1021a6ef4722e1fe454688bb71cb1 (diff)
Use namespaces module
-rw-r--r--nbxmpp/auth.py22
-rw-r--r--nbxmpp/client.py7
-rw-r--r--nbxmpp/dispatcher.py17
-rw-r--r--nbxmpp/modules/activity.py13
-rw-r--r--nbxmpp/modules/adhoc.py14
-rw-r--r--nbxmpp/modules/annotations.py11
-rw-r--r--nbxmpp/modules/attention.py9
-rw-r--r--nbxmpp/modules/bits_of_binary.py4
-rw-r--r--nbxmpp/modules/blocking.py10
-rw-r--r--nbxmpp/modules/bookmarks.py51
-rw-r--r--nbxmpp/modules/captcha.py9
-rw-r--r--nbxmpp/modules/chat_markers.py11
-rw-r--r--nbxmpp/modules/chatstates.py9
-rw-r--r--nbxmpp/modules/correction.py6
-rw-r--r--nbxmpp/modules/dataforms.py7
-rw-r--r--nbxmpp/modules/delay.py8
-rw-r--r--nbxmpp/modules/discovery.py12
-rw-r--r--nbxmpp/modules/eme.py6
-rw-r--r--nbxmpp/modules/entity_caps.py9
-rw-r--r--nbxmpp/modules/http_auth.py8
-rw-r--r--nbxmpp/modules/http_upload.py6
-rw-r--r--nbxmpp/modules/ibb.py16
-rw-r--r--nbxmpp/modules/idle.py6
-rw-r--r--nbxmpp/modules/location.py13
-rw-r--r--nbxmpp/modules/mam.py17
-rw-r--r--nbxmpp/modules/message.py7
-rw-r--r--nbxmpp/modules/misc.py25
-rw-r--r--nbxmpp/modules/mood.py13
-rw-r--r--nbxmpp/modules/muc.py73
-rw-r--r--nbxmpp/modules/muclumbus.py19
-rw-r--r--nbxmpp/modules/nickname.py17
-rw-r--r--nbxmpp/modules/omemo.py44
-rw-r--r--nbxmpp/modules/oob.py6
-rw-r--r--nbxmpp/modules/openpgp.py53
-rw-r--r--nbxmpp/modules/pgplegacy.py11
-rw-r--r--nbxmpp/modules/pubsub.py33
-rw-r--r--nbxmpp/modules/receipts.py13
-rw-r--r--nbxmpp/modules/register.py22
-rw-r--r--nbxmpp/modules/rsm.py5
-rw-r--r--nbxmpp/modules/security_labels.py6
-rw-r--r--nbxmpp/modules/software_version.py6
-rw-r--r--nbxmpp/modules/tune.py13
-rw-r--r--nbxmpp/modules/user_avatar.py14
-rw-r--r--nbxmpp/modules/vcard_avatar.py6
-rw-r--r--nbxmpp/old_dispatcher.py15
-rw-r--r--nbxmpp/protocol.py111
-rw-r--r--nbxmpp/smacks.py23
-rw-r--r--nbxmpp/structs.py58
-rw-r--r--nbxmpp/util.py22
-rw-r--r--test/lib/util.py1
-rw-r--r--test/unit/test_activity.py4
-rw-r--r--test/unit/test_avatar.py4
-rw-r--r--test/unit/test_bookmarks.py6
-rw-r--r--test/unit/test_location.py4
-rw-r--r--test/unit/test_mood.py4
-rw-r--r--test/unit/test_pubsub.py8
-rw-r--r--test/unit/test_tune.py4
57 files changed, 451 insertions, 500 deletions
diff --git a/nbxmpp/auth.py b/nbxmpp/auth.py
index 58ee874..65dcf2b 100644
--- a/nbxmpp/auth.py
+++ b/nbxmpp/auth.py
@@ -22,7 +22,7 @@ import logging
import hashlib
from hashlib import pbkdf2_hmac
-from nbxmpp.protocol import NS_SASL
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Node
from nbxmpp.protocol import SASL_ERROR_CONDITIONS
from nbxmpp.protocol import SASL_AUTH_MECHS
@@ -70,7 +70,7 @@ class SASL:
return self._password
def delegate(self, stanza):
- if stanza.getNamespace() != NS_SASL:
+ if stanza.getNamespace() != Namespace.SASL:
return
if stanza.getName() == 'challenge':
self._on_challenge(stanza)
@@ -201,7 +201,7 @@ class SASL:
self._abort_auth(reason, text)
def _abort_auth(self, reason='malformed-request', text=None):
- node = Node('abort', attrs={'xmlns': NS_SASL})
+ node = Node('abort', attrs={'xmlns': Namespace.SASL})
self._client.send_nonza(node)
self._on_sasl_finished(False, reason, text)
@@ -223,7 +223,7 @@ class PLAIN:
def initiate(self, username, password):
payload = b64encode('\x00%s\x00%s' % (username, password))
node = Node('auth',
- attrs={'xmlns': NS_SASL, 'mechanism': 'PLAIN'},
+ attrs={'xmlns': Namespace.SASL, 'mechanism': 'PLAIN'},
payload=[payload])
self._client.send_nonza(node)
@@ -238,7 +238,7 @@ class EXTERNAL:
def initiate(self, username, server):
payload = b64encode('%s@%s' % (username, server))
node = Node('auth',
- attrs={'xmlns': NS_SASL, 'mechanism': 'EXTERNAL'},
+ attrs={'xmlns': Namespace.SASL, 'mechanism': 'EXTERNAL'},
payload=[payload])
self._client.send_nonza(node)
@@ -251,7 +251,8 @@ class ANONYMOUS:
self._client = client
def initiate(self):
- node = Node('auth', attrs={'xmlns': NS_SASL, 'mechanism': 'ANONYMOUS'})
+ node = Node('auth', attrs={'xmlns': Namespace.SASL,
+ 'mechanism': 'ANONYMOUS'})
self._client.send_nonza(node)
@@ -269,7 +270,7 @@ class GSSAPI:
kerberos.authGSSClientStep(self._gss_vc, '')
response = kerberos.authGSSClientResponse(self._gss_vc)
node = Node('auth',
- attrs={'xmlns': NS_SASL, 'mechanism': 'GSSAPI'},
+ attrs={'xmlns': Namespace.SASL, 'mechanism': 'GSSAPI'},
payload=(response or ''))
self._client.send_nonza(node)
@@ -291,7 +292,7 @@ class GSSAPI:
response = ''
node = Node('response',
- attrs={'xmlns': NS_SASL},
+ attrs={'xmlns': Namespace.SASL},
payload=response)
self._client.send_nonza(node)
@@ -334,7 +335,8 @@ class SCRAM:
payload = b64encode(client_first_message)
node = Node('auth',
- attrs={'xmlns': NS_SASL, 'mechanism': self._mechanism},
+ attrs={'xmlns': Namespace.SASL,
+ 'mechanism': self._mechanism},
payload=[payload])
self._client.send_nonza(node)
@@ -381,7 +383,7 @@ class SCRAM:
payload = b64encode(client_finale_message)
node = Node('response',
- attrs={'xmlns': NS_SASL},
+ attrs={'xmlns': Namespace.SASL},
payload=[payload])
self._client.send_nonza(node)
diff --git a/nbxmpp/client.py b/nbxmpp/client.py
index 6b355f2..ec52363 100644
--- a/nbxmpp/client.py
+++ b/nbxmpp/client.py
@@ -19,8 +19,7 @@ import logging
from gi.repository import GLib
-from nbxmpp.protocol import NS_TLS
-from nbxmpp.protocol import NS_PING
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Features
from nbxmpp.protocol import StanzaMalformed
from nbxmpp.protocol import SessionRequest
@@ -604,7 +603,7 @@ class Client(Observable):
self._on_stream_features(Features(stanza))
elif self.state == StreamState.WAIT_FOR_TLS_PROCEED:
- if stanza.getNamespace() != NS_TLS:
+ if stanza.getNamespace() != Namespace.TLS:
self._disconnect_with_error(
StreamError.TLS,
'stanza-malformed',
@@ -782,7 +781,7 @@ class Client(Observable):
def _ping(self):
self._ping_source_id = None
iq = Iq('get', to=self.domain)
- iq.addChild(name='ping', namespace=NS_PING)
+ iq.addChild(name='ping', namespace=Namespace.PING)
self._ping_id = self.send_stanza(iq,
timeout=10,
callback=self._on_pong)
diff --git a/nbxmpp/dispatcher.py b/nbxmpp/dispatcher.py
index a44a395..5554bfa 100644
--- a/nbxmpp/dispatcher.py
+++ b/nbxmpp/dispatcher.py
@@ -24,9 +24,7 @@ from gi.repository import GLib
from nbxmpp.simplexml import NodeBuilder
from nbxmpp.simplexml import Node
-from nbxmpp.protocol import NS_STREAMS
-from nbxmpp.protocol import NS_CLIENT
-from nbxmpp.protocol import NS_XMPP_STREAMS
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import NodeProcessed
from nbxmpp.protocol import InvalidFrom
from nbxmpp.protocol import InvalidJid
@@ -127,8 +125,8 @@ class StanzaDispatcher(Observable):
self.invalid_chars_re = get_invalid_xml_regex()
self._register_namespace('unknown')
- self._register_namespace(NS_STREAMS)
- self._register_namespace(NS_CLIENT)
+ self._register_namespace(Namespace.STREAMS)
+ self._register_namespace(Namespace.CLIENT)
self._register_protocol('iq', Iq)
self._register_protocol('presence', Presence)
self._register_protocol('message', Message)
@@ -210,7 +208,8 @@ class StanzaDispatcher(Observable):
if is_websocket_stream_error(stanza):
for tag in stanza.getChildren():
name = tag.getName()
- if name != 'text' and tag.getNamespace() == NS_XMPP_STREAMS:
+ if (name != 'text' and
+ tag.getNamespace() == Namespace.XMPP_STREAMS):
self._websocket_stream_error = name
elif is_websocket_close(stanza):
@@ -249,7 +248,7 @@ class StanzaDispatcher(Observable):
Register protocol for top level tag names
"""
if xmlns is None:
- xmlns = NS_CLIENT
+ xmlns = Namespace.CLIENT
self._log.debug('Register protocol "%s (%s)" as %s',
tag_name, xmlns, protocol)
self._handlers[xmlns][tag_name] = {'type': protocol, 'default': []}
@@ -269,7 +268,7 @@ class StanzaDispatcher(Observable):
"""
if not xmlns:
- xmlns = NS_CLIENT
+ xmlns = Namespace.CLIENT
if not typ and not ns:
typ = 'default'
@@ -298,7 +297,7 @@ class StanzaDispatcher(Observable):
"""
if not xmlns:
- xmlns = NS_CLIENT
+ xmlns = Namespace.CLIENT
if not typ and not ns:
typ = 'default'
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
diff --git a/nbxmpp/old_dispatcher.py b/nbxmpp/old_dispatcher.py
index 2405dbe..5af4b7d 100644
--- a/nbxmpp/old_dispatcher.py
+++ b/nbxmpp/old_dispatcher.py
@@ -28,8 +28,7 @@ from xml.parsers.expat import ExpatError
from nbxmpp.simplexml import NodeBuilder
from nbxmpp.plugin import PlugIn
-from nbxmpp.protocol import NS_STREAMS
-from nbxmpp.protocol import NS_HTTP_BIND
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import NodeProcessed
from nbxmpp.protocol import InvalidFrom
from nbxmpp.protocol import InvalidJid
@@ -240,7 +239,7 @@ class XMPPDispatcher(PlugIn):
# FIXME: inject dependencies, do not rely that they are defined by our
# owner
self.RegisterNamespace('unknown')
- self.RegisterNamespace(NS_STREAMS)
+ self.RegisterNamespace(Namespace.STREAMS)
self.RegisterNamespace(self._owner.defaultNamespace)
self.RegisterProtocol('iq', Iq)
self.RegisterProtocol('presence', Presence)
@@ -287,14 +286,14 @@ class XMPPDispatcher(PlugIn):
self._metastream = Node('stream:stream')
self._metastream.setNamespace(self._owner.Namespace)
self._metastream.setAttr('version', '1.0')
- self._metastream.setAttr('xmlns:stream', NS_STREAMS)
+ self._metastream.setAttr('xmlns:stream', Namespace.STREAMS)
self._metastream.setAttr('to', self._owner.Server)
self._metastream.setAttr('xml:lang', self._owner.lang)
self._owner.send("%s%s>" % (XML_DECLARATION,
str(self._metastream)[:-2]))
def _check_stream_start(self, ns, tag, attrs):
- if ns != NS_STREAMS or tag != 'stream':
+ if ns != Namespace.STREAMS or tag != 'stream':
raise ValueError('Incorrect stream start: '
'(%s,%s). Terminating.' % (tag, ns))
@@ -715,7 +714,7 @@ class BOSHDispatcher(XMPPDispatcher):
self._metastream = Node('stream:stream')
self._metastream.setNamespace(self._owner.Namespace)
self._metastream.setAttr('version', '1.0')
- self._metastream.setAttr('xmlns:stream', NS_STREAMS)
+ self._metastream.setAttr('xmlns:stream', Namespace.STREAMS)
self._metastream.setAttr('to', self._owner.Server)
self._metastream.setAttr('xml:lang', self._owner.lang)
@@ -738,7 +737,7 @@ class BOSHDispatcher(XMPPDispatcher):
return XMPPDispatcher.ProcessNonBlocking(self, data)
def dispatch(self, stanza):
- if stanza.getName() == 'body' and stanza.getNamespace() == NS_HTTP_BIND:
+ if stanza.getName() == 'body' and stanza.getNamespace() == Namespace.HTTP_BIND:
stanza_attrs = stanza.getAttrs()
if 'authid' in stanza_attrs:
@@ -753,7 +752,7 @@ class BOSHDispatcher(XMPPDispatcher):
# if child doesn't have any ns specified, simplexml
# (or expat) thinks it's of parent's (BOSH body) namespace,
# so we have to rewrite it to jabber:client
- if child.getNamespace() == NS_HTTP_BIND:
+ if child.getNamespace() == Namespace.HTTP_BIND:
child.setNamespace(self._owner.defaultNamespace)
XMPPDispatcher.dispatch(self, child)
else:
diff --git a/nbxmpp/protocol.py b/nbxmpp/protocol.py
index 0e7348b..b85cae6 100644
--- a/nbxmpp/protocol.py
+++ b/nbxmpp/protocol.py
@@ -27,6 +27,7 @@ from base64 import b64encode
import idna
from precis_i18n import get_profile
from nbxmpp.simplexml import Node
+from nbxmpp.namespaces import Namespace
def ascii_upper(s):
return s.upper()
@@ -506,7 +507,7 @@ def isErrorNode(node):
return node and node.getType() == 'error'
def isMucPM(message):
- muc_user = message.getTag('x', namespace=NS_MUC_USER)
+ muc_user = message.getTag('x', namespace=Namespace.MUC_USER)
return (message.getType() in ('chat', 'error') and
muc_user is not None and
not muc_user.getChildren())
@@ -907,7 +908,7 @@ class StreamErrorNode(Node):
self._text = {}
- text_elements = self.getTags('text', namespace=NS_XMPP_STREAMS)
+ text_elements = self.getTags('text', namespace=Namespace.XMPP_STREAMS)
for element in text_elements:
lang = element.getXmlLang()
text = element.getData()
@@ -916,7 +917,7 @@ class StreamErrorNode(Node):
def get_condition(self):
for tag in self.getChildren():
if (tag.getName() != 'text' and
- tag.getNamespace() == NS_XMPP_STREAMS):
+ tag.getNamespace() == Namespace.XMPP_STREAMS):
return tag.getName()
return None
@@ -986,14 +987,14 @@ class Protocol(Node):
and 'id' in self.attrs):
del self.attrs['id']
self.timestamp = None
- for d in self.getTags('delay', namespace=NS_DELAY2):
+ for d in self.getTags('delay', namespace=Namespace.DELAY2):
try:
if d.getAttr('stamp') < self.getTimestamp2():
self.setTimestamp(d.getAttr('stamp'))
except Exception:
pass
if not self.timestamp:
- for x in self.getTags('x', namespace=NS_DELAY):
+ for x in self.getTags('x', namespace=Namespace.DELAY):
try:
if x.getAttr('stamp') < self.getTimestamp():
self.setTimestamp(x.getAttr('stamp'))
@@ -1092,7 +1093,8 @@ class Protocol(Node):
if errtag is None:
return None
for tag in errtag.getChildren():
- if tag.getName() != 'text' and tag.getNamespace() == NS_STANZAS:
+ if (tag.getName() != 'text' and
+ tag.getNamespace() == Namespace.STANZAS):
return tag.getName()
return None
@@ -1101,7 +1103,8 @@ class Protocol(Node):
if errtag is None:
return None
for tag in errtag.getChildren():
- if tag.getName() != 'text' and tag.getNamespace() != NS_STANZAS:
+ if (tag.getName() != 'text' and
+ tag.getNamespace() != Namespace.STANZAS):
return tag.getName()
return None
@@ -1110,7 +1113,8 @@ class Protocol(Node):
if errtag is None:
return None
for tag in errtag.getChildren():
- if tag.getName() != 'text' and tag.getNamespace() != NS_STANZAS:
+ if (tag.getName() != 'text' and
+ tag.getNamespace() != Namespace.STANZAS):
return tag.getNamespace()
return None
@@ -1177,7 +1181,7 @@ class Protocol(Node):
if not val:
val = time.strftime('%Y%m%dT%H:%M:%S', time.gmtime())
self.timestamp=val
- self.setTag('x', {'stamp': self.timestamp}, namespace=NS_DELAY)
+ self.setTag('x', {'stamp': self.timestamp}, namespace=Namespace.DELAY)
def getProperties(self):
"""
@@ -1227,7 +1231,7 @@ class Message(Protocol):
frm=None,
payload=None,
timestamp=None,
- xmlns=NS_CLIENT,
+ xmlns=Namespace.CLIENT,
node=None):
"""
You can specify recipient, text of message, type of message any
@@ -1261,7 +1265,7 @@ class Message(Protocol):
return self.getTagData('body')
def getXHTML(self):
- return self.getTag('html', namespace=NS_XHTML_IM)
+ return self.getTag('html', namespace=Namespace.XHTML_IM)
def getSubject(self):
"""
@@ -1279,14 +1283,14 @@ class Message(Protocol):
"""
Return origin-id of the message
"""
- return self.getTagAttr('origin-id', namespace=NS_SID, attr='id')
+ return self.getTagAttr('origin-id', namespace=Namespace.SID, attr='id')
def getStanzaIDAttrs(self):
"""
Return the stanza-id attributes of the message
"""
try:
- attrs = self.getTag('stanza-id', namespace=NS_SID).getAttrs()
+ attrs = self.getTag('stanza-id', namespace=Namespace.SID).getAttrs()
except Exception:
return None, None
return attrs['id'], attrs['by']
@@ -1300,16 +1304,18 @@ class Message(Protocol):
if isinstance(body, str):
body = Node(node=body)
if add:
- xhtml = self.getTag('html', namespace=NS_XHTML_IM)
+ xhtml = self.getTag('html', namespace=Namespace.XHTML_IM)
if xhtml is not None:
xhtml.addChild(node=body)
else:
- self.addChild('html', namespace=NS_XHTML_IM, payload=body)
+ self.addChild('html',
+ namespace=Namespace.XHTML_IM,
+ payload=body)
else:
- xhtml_nodes = self.getTags('html', namespace=NS_XHTML_IM)
+ xhtml_nodes = self.getTags('html', namespace=Namespace.XHTML_IM)
for xhtml in xhtml_nodes:
self.delChild(xhtml)
- self.addChild('html', namespace=NS_XHTML_IM, payload=body)
+ self.addChild('html', namespace=Namespace.XHTML_IM, payload=body)
def setSubject(self, val):
"""
@@ -1327,7 +1333,7 @@ class Message(Protocol):
"""
Sets the origin-id of the message
"""
- self.setTag('origin-id', namespace=NS_SID, attrs={'id': val})
+ self.setTag('origin-id', namespace=Namespace.SID, attrs={'id': val})
def buildReply(self, text=None):
"""
@@ -1355,31 +1361,31 @@ class Message(Protocol):
return attrs
def setMarker(self, type_, id_):
- self.setTag(type_, namespace=NS_CHATMARKERS, attrs={'id': id_})
+ self.setTag(type_, namespace=Namespace.CHATMARKERS, attrs={'id': id_})
def setMarkable(self):
- self.setTag('markable', namespace=NS_CHATMARKERS)
+ self.setTag('markable', namespace=Namespace.CHATMARKERS)
def setReceiptRequest(self):
- self.setTag('request', namespace=NS_RECEIPTS)
+ self.setTag('request', namespace=Namespace.RECEIPTS)
def setReceiptReceived(self, id_):
- self.setTag('received', namespace=NS_RECEIPTS, attrs={'id': id_})
+ self.setTag('received', namespace=Namespace.RECEIPTS, attrs={'id': id_})
def setOOB(self, url, desc=None):
- oob = self.setTag('x', namespace=NS_X_OOB)
+ oob = self.setTag('x', namespace=Namespace.X_OOB)
oob.setTagData('url', url)
if desc is not None:
oob.setTagData('desc', desc)
def setCorrection(self, id_):
- self.setTag('replace', namespace=NS_CORRECT, attrs={'id': id_})
+ self.setTag('replace', namespace=Namespace.CORRECT, attrs={'id': id_})
def setAttention(self):
- self.setTag('attention', namespace=NS_ATTENTION)
+ self.setTag('attention', namespace=Namespace.ATTENTION)
def setHint(self, hint):
- self.setTag(hint, namespace=NS_HINTS)
+ self.setTag(hint, namespace=Namespace.HINTS)
class Presence(Protocol):
@@ -1394,7 +1400,7 @@ class Presence(Protocol):
frm=None,
timestamp=None,
payload=None,
- xmlns=NS_CLIENT,
+ xmlns=Namespace.CLIENT,
node=None):
"""
You can specify recipient, type of message, priority, show and status
@@ -1460,14 +1466,16 @@ class Presence(Protocol):
def _muc_getItemAttr(self, tag, attr):
for xtag in self.getTags('x'):
- if xtag.getNamespace() not in (NS_MUC_USER, NS_MUC_ADMIN):
+ if xtag.getNamespace() not in (Namespace.MUC_USER,
+ Namespace.MUC_ADMIN):
continue
for child in xtag.getTags(tag):
return child.getAttr(attr)
def _muc_getSubTagDataAttr(self, tag, attr):
for xtag in self.getTags('x'):
- if xtag.getNamespace() not in (NS_MUC_USER, NS_MUC_ADMIN):
+ if xtag.getNamespace() not in (Namespace.MUC_USER,
+ Namespace.MUC_ADMIN):
continue
for child in xtag.getTags('item'):
for cchild in child.getTags(tag):
@@ -1532,7 +1540,7 @@ class Iq(Protocol):
to=None,
frm=None,
payload=None,
- xmlns=NS_CLIENT,
+ xmlns=Namespace.CLIENT,
node=None):
"""
You can specify type, query namespace any additional attributes,
@@ -1677,7 +1685,7 @@ class Hashes(Node):
supported = ('md5', 'sha-1', 'sha-256', 'sha-512')
- def __init__(self, nsp=NS_HASHES):
+ def __init__(self, nsp=Namespace.HASHES):
Node.__init__(self, None, {}, [], None, None, False, None)
self.setNamespace(nsp)
self.setName('hash')
@@ -1742,7 +1750,7 @@ class Hashes2(Node):
supported = ('sha-256', 'sha-512', 'sha3-256',
'sha3-512', 'blake2b-256', 'blake2b-512')
- def __init__(self, nsp=NS_HASHES_2):
+ def __init__(self, nsp=Namespace.HASHES_2):
Node.__init__(self, None, {}, [], None, None, False, None)
self.setNamespace(nsp)
self.setName('hash')
@@ -1786,18 +1794,20 @@ class BindRequest(Iq):
if resource is not None:
resource = Node('resource', payload=resource)
Iq.__init__(self, typ='set')
- self.addChild(node=Node('bind', {'xmlns': NS_BIND}, payload=resource))
+ self.addChild(node=Node('bind',
+ {'xmlns': Namespace.BIND},
+ payload=resource))
class TLSRequest(Node):
def __init__(self):
- Node.__init__(self, tag='starttls', attrs={'xmlns': NS_TLS})
+ Node.__init__(self, tag='starttls', attrs={'xmlns': Namespace.TLS})
class SessionRequest(Iq):
def __init__(self):
Iq.__init__(self, typ='set')
- self.addChild(node=Node('session', attrs={'xmlns': NS_SESSION}))
+ self.addChild(node=Node('session', attrs={'xmlns': Namespace.SESSION}))
class StreamHeader(Node):
@@ -1806,9 +1816,9 @@ class StreamHeader(Node):
lang = 'en'
Node.__init__(self,
tag='stream:stream',
- attrs={'xmlns': NS_CLIENT,
+ attrs={'xmlns': Namespace.CLIENT,
'version': '1.0',
- 'xmlns:stream': NS_STREAMS,
+ 'xmlns:stream': Namespace.STREAMS,
'to': domain,
'xml:lang': lang})
@@ -1819,14 +1829,14 @@ class WebsocketOpenHeader(Node):
lang = 'en'
Node.__init__(self,
tag='open',
- attrs={'xmlns': NS_FRAMING,
+ attrs={'xmlns': Namespace.FRAMING,
'version': '1.0',
'to': domain,
'xml:lang': lang})
class WebsocketCloseHeader(Node):
def __init__(self):
- Node.__init__(self, tag='close', attrs={'xmlns': NS_FRAMING})
+ Node.__init__(self, tag='close', attrs={'xmlns': Namespace.FRAMING})
class Features(Node):
@@ -1834,47 +1844,48 @@ class Features(Node):
Node.__init__(self, node=node)
def has_starttls(self):
- tls = self.getTag('starttls', namespace=NS_TLS)
+ tls = self.getTag('starttls', namespace=Namespace.TLS)
if tls is not None:
required = tls.getTag('required') is not None
return True, required
return False, False
def has_sasl(self):
- return self.getTag('mechanisms', namespace=NS_SASL) is not None
+ return self.getTag('mechanisms', namespace=Namespace.SASL) is not None
def get_mechs(self):
- mechanisms = self.getTag('mechanisms', namespace=NS_SASL)
+ mechanisms = self.getTag('mechanisms', namespace=Namespace.SASL)
if mechanisms is None:
return set()
mechanisms = mechanisms.getTags('mechanism')
return set(mech.getData() for mech in mechanisms)
def get_domain_based_name(self):
- hostname = self.getTag('hostname', namespace=NS_DOMAIN_BASED_NAME)
+ hostname = self.getTag('hostname',
+ namespace=Namespace.DOMAIN_BASED_NAME)
if hostname is not None:
return hostname.getData()
return None
def has_bind(self):
- return self.getTag('bind', namespace=NS_BIND) is not None
+ return self.getTag('bind', namespace=Namespace.BIND) is not None
def session_required(self):
- session = self.getTag('session', namespace=NS_SESSION)
+ session = self.getTag('session', namespace=Namespace.SESSION)
if session is not None:
optional = session.getTag('optional') is not None
return not optional
return False
def has_sm(self):
- return self.getTag('sm', namespace=NS_STREAM_MGMT) is not None
+ return self.getTag('sm', namespace=Namespace.STREAM_MGMT) is not None
def has_roster_version(self):
- return self.getTag('ver', namespace=NS_ROSTER_VER) is not None
+ return self.getTag('ver', namespace=Namespace.ROSTER_VER) is not None
def has_register(self):
return self.getTag(
- 'register', namespace=NS_REGISTER_FEATURE) is not None
+ 'register', namespace=Namespace.REGISTER_FEATURE) is not None
def has_anonymous(self):
return 'ANONYMOUS' in self.get_mechs()
@@ -1898,7 +1909,7 @@ class ErrorNode(Node):
cod, type_, txt = ERRORS[name]
ns = name.split()[0]
else:
- cod, ns, type_, txt = '500', NS_STANZAS, 'cancel', ''
+ cod, ns, type_, txt = '500', Namespace.STANZAS, 'cancel', ''
if typ:
type_ = typ
if code:
@@ -2138,7 +2149,7 @@ class DataForm(Node):
self.kids = newkids
if typ:
self.setType(typ)
- self.setNamespace(NS_DATA)
+ self.setNamespace(Namespace.DATA)
if title:
self.setTitle(title)
if data is not None:
diff --git a/nbxmpp/smacks.py b/nbxmpp/smacks.py
index 563b993..58c0788 100644
--- a/nbxmpp/smacks.py
+++ b/nbxmpp/smacks.py
@@ -18,8 +18,7 @@
import time
import logging
-from nbxmpp.protocol import NS_STREAM_MGMT
-from nbxmpp.protocol import NS_DELAY2
+from nbxmpp.namespaces import Namespace
from nbxmpp.simplexml import Node
from nbxmpp.const import StreamState
from nbxmpp.util import LogAdapter
@@ -73,7 +72,7 @@ class Smacks:
self._sm_supported = value
def delegate(self, stanza):
- if stanza.getNamespace() != NS_STREAM_MGMT:
+ if stanza.getNamespace() != Namespace.STREAM_MGMT:
return
if stanza.getName() == 'resumed':
self._on_resumed(stanza)
@@ -82,18 +81,18 @@ class Smacks:
def register_handlers(self):
self._client.register_handler(
- 'enabled', self._on_enabled, xmlns=NS_STREAM_MGMT)
+ 'enabled', self._on_enabled, xmlns=Namespace.STREAM_MGMT)
self._client.register_handler(
- 'failed', self._on_failed, xmlns=NS_STREAM_MGMT)
+ 'failed', self._on_failed, xmlns=Namespace.STREAM_MGMT)
self._client.register_handler(
- 'r', self._send_ack, xmlns=NS_STREAM_MGMT)
+ 'r', self._send_ack, xmlns=Namespace.STREAM_MGMT)
self._client.register_handler(
- 'a', self._on_ack, xmlns=NS_STREAM_MGMT)
+ 'a', self._on_ack, xmlns=Namespace.STREAM_MGMT)
def send_enable(self):
if not self.sm_supported:
return
- enable = Node(NS_STREAM_MGMT + ' enable', attrs={'resume': 'true'})
+ enable = Node(Namespace.STREAM_MGMT + ' enable', attrs={'resume': 'true'})
self._client.send_nonza(enable, now=False)
self._log.debug('Send enable')
self._enable_sent = True
@@ -158,7 +157,7 @@ class Smacks:
# Dont leak our JID to Groupchats
attrs['from'] = str(self._client.get_bound_jid())
- stanza.addChild('delay', namespace=NS_DELAY2, attrs=attrs)
+ stanza.addChild('delay', namespace=Namespace.DELAY2, attrs=attrs)
def _resend_queue(self):
"""
@@ -187,7 +186,7 @@ class Smacks:
self._old_uqueue += self._uqueue
self._uqueue = []
- resume = Node(NS_STREAM_MGMT + ' resume',
+ resume = Node(Namespace.STREAM_MGMT + ' resume',
attrs={'h': self._in_h, 'previd': self._session_id})
self._acked_h = self._in_h
@@ -212,7 +211,7 @@ class Smacks:
self._resend_queue()
def _send_ack(self, *args):
- ack = Node(NS_STREAM_MGMT + ' a', attrs={'h': self._in_h})
+ ack = Node(Namespace.STREAM_MGMT + ' a', attrs={'h': self._in_h})
self._acked_h = self._in_h
self._log.debug('Send ack, h: %s', self._in_h)
self._client.send_nonza(ack, now=False)
@@ -224,7 +223,7 @@ class Smacks:
self._reset_state()
def _request_ack(self):
- request = Node(NS_STREAM_MGMT + ' r')
+ request = Node(Namespace.STREAM_MGMT + ' r')
self._log.debug('Request ack')
self._client.send_nonza(request, now=False)
diff --git a/nbxmpp/structs.py b/nbxmpp/structs.py
index 64ce391..2b6674b 100644
--- a/nbxmpp/structs.py
+++ b/nbxmpp/structs.py
@@ -23,15 +23,7 @@ from gi.repository import Soup
from gi.repository import Gio
from nbxmpp.protocol import JID
-from nbxmpp.protocol import NS_STANZAS
-from nbxmpp.protocol import NS_STREAMS
-from nbxmpp.protocol import NS_MAM_1
-from nbxmpp.protocol import NS_MAM_2
-from nbxmpp.protocol import NS_MUC
-from nbxmpp.protocol import NS_MUC_INFO
-from nbxmpp.protocol import NS_CLIENT
-from nbxmpp.protocol import NS_XHTML
-from nbxmpp.protocol import NS_HTTPUPLOAD_0
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Protocol
from nbxmpp.protocol import Node
from nbxmpp.const import MessageType
@@ -219,19 +211,19 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti
@property
def mam_namespace(self):
- if NS_MAM_2 in self.features:
- return NS_MAM_2
- if NS_MAM_1 in self.features:
- return NS_MAM_1
+ if Namespace.MAM_2 in self.features:
+ return Namespace.MAM_2
+ if Namespace.MAM_1 in self.features:
+ return Namespace.MAM_1
return None
@property
def has_mam_2(self):
- return NS_MAM_2 in self.features
+ return Namespace.MAM_2 in self.features
@property
def has_mam_1(self):
- return NS_MAM_1 in self.features
+ return Namespace.MAM_1 in self.features
@property
def has_mam(self):
@@ -239,13 +231,13 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti
@property
def has_httpupload(self):
- return NS_HTTPUPLOAD_0 in self.features
+ return Namespace.HTTPUPLOAD_0 in self.features
@property
def is_muc(self):
for identity in self.identities:
if identity.category == 'conference':
- if NS_MUC in self.features:
+ if Namespace.MUC in self.features:
return True
return False
@@ -270,38 +262,38 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti
@property
def muc_room_name(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roomconfig_roomname')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roomconfig_roomname')
@property
def muc_description(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roominfo_description')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_description')
@property
def muc_log_uri(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roominfo_logs')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_logs')
@property
def muc_users(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roominfo_occupants')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_occupants')
@property
def muc_contacts(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roominfo_contactjid')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_contactjid')
@property
def muc_subject(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roominfo_subject')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_subject')
@property
def muc_subjectmod(self):
# muc#roominfo_changesubject stems from a wrong example in the MUC XEP
# Ejabberd and Prosody use this value
- return (self.get_field_value(NS_MUC_INFO, 'muc#roominfo_subjectmod') or
- self.get_field_value(NS_MUC_INFO, 'muc#roominfo_changesubject'))
+ return (self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_subjectmod') or
+ self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_changesubject'))
@property
def muc_lang(self):
- return self.get_field_value(NS_MUC_INFO, 'muc#roominfo_lang')
+ return self.get_field_value(Namespace.MUC_INFO, 'muc#roominfo_lang')
@property
def muc_is_persistent(self):
@@ -380,7 +372,7 @@ class DiscoInfo(namedtuple('DiscoInfo', 'stanza identities features dataforms ti
@property
def httpupload_max_file_size(self):
- size = self.get_field_value(NS_HTTPUPLOAD_0, 'max-file-size')
+ size = self.get_field_value(Namespace.HTTPUPLOAD_0, 'max-file-size')
try:
return float(size)
except Exception:
@@ -488,7 +480,7 @@ class CommonError:
self.id = stanza.getID()
self._text = {}
- text_elements = self._error_node.getTags('text', namespace=NS_STANZAS)
+ text_elements = self._error_node.getTags('text', namespace=Namespace.STANZAS)
for element in text_elements:
lang = element.getXmlLang()
text = element.getData()
@@ -530,7 +522,7 @@ class CommonError:
def serialize(self):
return str(Protocol(name=self._stanza_name,
frm=self.jid,
- xmlns=NS_CLIENT,
+ xmlns=Namespace.CLIENT,
attrs={'id': self.id},
payload=self._error_node))
@@ -607,7 +599,7 @@ class StreamError(CommonError):
self.id = stanza.getID()
self._text = {}
- text_elements = self._error_node.getTags('text', namespace=NS_STREAMS)
+ text_elements = self._error_node.getTags('text', namespace=Namespace.STREAMS)
for element in text_elements:
lang = element.getXmlLang()
text = element.getData()
@@ -649,11 +641,11 @@ class MAMData(namedtuple('MAMData', 'id query_id archive namespace timestamp')):
@property
def is_ver_1(self):
- return self.namespace == NS_MAM_1
+ return self.namespace == Namespace.MAM_1
@property
def is_ver_2(self):
- return self.namespace == NS_MAM_2
+ return self.namespace == Namespace.MAM_2
class CarbonData(namedtuple('MAMData', 'type')):
@@ -992,7 +984,7 @@ class PresenceProperties:
class XHTMLData:
def __init__(self, xhtml):
self._bodys = {}
- for body in xhtml.getTags('body', namespace=NS_XHTML):
+ for body in xhtml.getTags('body', namespace=Namespace.XHTML):
lang = body.getXmlLang()
self._bodys[lang] = body
diff --git a/nbxmpp/util.py b/nbxmpp/util.py
index 10b0566..1884df4 100644
--- a/nbxmpp/util.py
+++ b/nbxmpp/util.py
@@ -33,12 +33,8 @@ from gi.repository import Gio
from nbxmpp.protocol import DiscoInfoMalformed
from nbxmpp.protocol import isErrorNode
-from nbxmpp.protocol import NS_DATA
-from nbxmpp.protocol import NS_HTTPUPLOAD_0
from nbxmpp.const import GIO_TLS_ERRORS
-from nbxmpp.protocol import NS_STREAMS
-from nbxmpp.protocol import NS_CLIENT
-from nbxmpp.protocol import NS_FRAMING
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import StanzaMalformed
from nbxmpp.protocol import StreamHeader
from nbxmpp.protocol import WebsocketOpenHeader
@@ -155,7 +151,7 @@ def to_xs_boolean(value):
error_classes = {
- NS_HTTPUPLOAD_0: HTTPUploadError
+ Namespace.HTTPUPLOAD_0: HTTPUploadError
}
def error_factory(stanza, condition=None, text=None):
@@ -343,7 +339,7 @@ def generate_id():
def get_form(stanza, form_type):
- forms = stanza.getTags('x', namespace=NS_DATA)
+ forms = stanza.getTags('x', namespace=Namespace.DATA)
if not forms:
return None
@@ -364,12 +360,12 @@ def validate_stream_header(stanza, domain, is_websocket):
raise StanzaMalformed('Invalid from attr in stream header')
if is_websocket:
- if attrs.get('xmlns') != NS_FRAMING:
+ if attrs.get('xmlns') != Namespace.FRAMING:
raise StanzaMalformed('Invalid namespace in stream header')
else:
- if attrs.get('xmlns:stream') != NS_STREAMS:
+ if attrs.get('xmlns:stream') != Namespace.STREAMS:
raise StanzaMalformed('Invalid stream namespace in stream header')
- if attrs.get('xmlns') != NS_CLIENT:
+ if attrs.get('xmlns') != Namespace.CLIENT:
raise StanzaMalformed('Invalid namespace in stream header')
if attrs.get('version') != '1.0':
@@ -463,11 +459,13 @@ def get_websocket_close_string(websocket):
def is_websocket_close(stanza):
- return stanza.getName() == 'close' and stanza.getNamespace() == NS_FRAMING
+ return (stanza.getName() == 'close' and
+ stanza.getNamespace() == Namespace.FRAMING)
def is_websocket_stream_error(stanza):
- return stanza.getName() == 'error' and stanza.getNamespace() == NS_STREAMS
+ return (stanza.getName() == 'error' and
+ stanza.getNamespace() == Namespace.STREAMS)
class Observable:
diff --git a/test/lib/util.py b/test/lib/util.py
index 9caeddf..1fbe634 100644
--- a/test/lib/util.py
+++ b/test/lib/util.py
@@ -4,7 +4,6 @@ from unittest.mock import Mock
from test.lib.const import STREAM_START
from nbxmpp.dispatcher import StanzaDispatcher
-from nbxmpp.protocol import NS_CLIENT
from nbxmpp.protocol import JID
diff --git a/test/unit/test_activity.py b/test/unit/test_activity.py
index 3cf0af3..95052bb 100644
--- a/test/unit/test_activity.py
+++ b/test/unit/test_activity.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import ActivityData
from nbxmpp.structs import PubSubEventData
@@ -48,6 +48,6 @@ class ActivityTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)
diff --git a/test/unit/test_avatar.py b/test/unit/test_avatar.py
index 70de7f3..be12185 100644
--- a/test/unit/test_avatar.py
+++ b/test/unit/test_avatar.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import AvatarMetaData
from nbxmpp.structs import PubSubEventData
@@ -53,6 +53,6 @@ class AvatarTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)
diff --git a/test/unit/test_bookmarks.py b/test/unit/test_bookmarks.py
index d581dc1..edfa6f4 100644
--- a/test/unit/test_bookmarks.py
+++ b/test/unit/test_bookmarks.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import JID
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import BookmarkData
@@ -64,7 +64,7 @@ class BookmarkTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)
@@ -109,6 +109,6 @@ class BookmarkTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)
diff --git a/test/unit/test_location.py b/test/unit/test_location.py
index fe1cd5d..cb9de94 100644
--- a/test/unit/test_location.py
+++ b/test/unit/test_location.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import LocationData
from nbxmpp.structs import PubSubEventData
@@ -89,6 +89,6 @@ class LocationTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)
diff --git a/test/unit/test_mood.py b/test/unit/test_mood.py
index af184a8..065bddb 100644
--- a/test/unit/test_mood.py
+++ b/test/unit/test_mood.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import MoodData
from nbxmpp.structs import PubSubEventData
@@ -44,6 +44,6 @@ class MoodTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)
diff --git a/test/unit/test_pubsub.py b/test/unit/test_pubsub.py
index 281383d..6cdca53 100644
--- a/test/unit/test_pubsub.py
+++ b/test/unit/test_pubsub.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import PubSubEventData
@@ -32,7 +32,7 @@ class PubsubTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT,
+ ns=Namespace.PUBSUB_EVENT,
priority=16))
self.dispatcher.process_data(event)
@@ -62,7 +62,7 @@ class PubsubTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT,
+ ns=Namespace.PUBSUB_EVENT,
priority=16))
self.dispatcher.process_data(event)
@@ -93,7 +93,7 @@ class PubsubTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT,
+ ns=Namespace.PUBSUB_EVENT,
priority=16))
self.dispatcher.process_data(event)
diff --git a/test/unit/test_tune.py b/test/unit/test_tune.py
index fcb0f45..da573c2 100644
--- a/test/unit/test_tune.py
+++ b/test/unit/test_tune.py
@@ -1,6 +1,6 @@
from test.lib.util import StanzaHandlerTest
-from nbxmpp.protocol import NS_PUBSUB_EVENT
+from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import TuneData
from nbxmpp.structs import PubSubEventData
@@ -55,6 +55,6 @@ class TuneTest(StanzaHandlerTest):
self.dispatcher.register_handler(
*StanzaHandler(name='message',
callback=_on_message,
- ns=NS_PUBSUB_EVENT))
+ ns=Namespace.PUBSUB_EVENT))
self.dispatcher.process_data(event)