Commit db7b78d5 authored by Philipp Hörist's avatar Philipp Hörist

Use namespaces module

parent 7712aa59
Pipeline #5428 passed with stages
in 54 seconds
......@@ -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)
......
......@@ -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)
......
......@@ -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'
......
......@@ -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')
......@@ -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:
......
......@@ -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):
......
......@@ -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
......@@ -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
......
......@@ -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})
......
......@@ -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):
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......@@ -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 = [