[pgp] Use nbxmpp.namespaces

This commit is contained in:
lovetox
2020-04-19 22:13:19 +02:00
parent 4a95f1d5bc
commit f85ea81a9b
2 changed files with 21 additions and 20 deletions

View File

@@ -19,6 +19,7 @@ import time
import threading import threading
import nbxmpp import nbxmpp
from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler from nbxmpp.structs import StanzaHandler
from gi.repository import GLib from gi.repository import GLib
@@ -41,18 +42,18 @@ from pgp.exceptions import NoKeyIdFound
name = 'PGPLegacy' name = 'PGPLegacy'
zeroconf = True zeroconf = True
ALLOWED_TAGS = [('request', nbxmpp.NS_RECEIPTS), ALLOWED_TAGS = [('request', Namespace.RECEIPTS),
('active', nbxmpp.NS_CHATSTATES), ('active', Namespace.CHATSTATES),
('gone', nbxmpp.NS_CHATSTATES), ('gone', Namespace.CHATSTATES),
('inactive', nbxmpp.NS_CHATSTATES), ('inactive', Namespace.CHATSTATES),
('paused', nbxmpp.NS_CHATSTATES), ('paused', Namespace.CHATSTATES),
('composing', nbxmpp.NS_CHATSTATES), ('composing', Namespace.CHATSTATES),
('no-store', nbxmpp.NS_MSG_HINTS), ('no-store', Namespace.HINTS),
('store', nbxmpp.NS_MSG_HINTS), ('store', Namespace.HINTS),
('no-copy', nbxmpp.NS_MSG_HINTS), ('no-copy', Namespace.HINTS),
('no-permanent-store', nbxmpp.NS_MSG_HINTS), ('no-permanent-store', Namespace.HINTS),
('replace', nbxmpp.NS_CORRECT), ('replace', Namespace.CORRECT),
('origin-id', nbxmpp.NS_SID), ('origin-id', Namespace.SID),
] ]
@@ -63,11 +64,11 @@ class PGPLegacy(BaseModule):
self.handlers = [ self.handlers = [
StanzaHandler(name='message', StanzaHandler(name='message',
callback=self._message_received, callback=self._message_received,
ns=nbxmpp.NS_ENCRYPTED, ns=Namespace.ENCRYPTED,
priority=9), priority=9),
StanzaHandler(name='presence', StanzaHandler(name='presence',
callback=self._on_presence_received, callback=self._on_presence_received,
ns=nbxmpp.NS_SIGNED, ns=Namespace.SIGNED,
priority=48), priority=48),
] ]
@@ -205,10 +206,10 @@ class PGPLegacy(BaseModule):
def _create_pgp_legacy_message(self, stanza, payload): def _create_pgp_legacy_message(self, stanza, payload):
stanza.setBody(self._get_info_message()) stanza.setBody(self._get_info_message())
stanza.setTag('x', namespace=nbxmpp.NS_ENCRYPTED).setData(payload) stanza.setTag('x', namespace=Namespace.ENCRYPTED).setData(payload)
eme_node = nbxmpp.Node('encryption', eme_node = nbxmpp.Node('encryption',
attrs={'xmlns': nbxmpp.NS_EME, attrs={'xmlns': Namespace.EME,
'namespace': nbxmpp.NS_ENCRYPTED}) 'namespace': Namespace.ENCRYPTED})
stanza.addChild(node=eme_node) stanza.addChild(node=eme_node)
def sign_presence(self, presence, status): def sign_presence(self, presence, status):
@@ -224,7 +225,7 @@ class PGPLegacy(BaseModule):
return return
# self._log.debug(self._pgp.sign.cache_info()) # self._log.debug(self._pgp.sign.cache_info())
self._log.info('Presence signed') self._log.info('Presence signed')
presence.setTag(nbxmpp.NS_SIGNED + ' x').setData(result) presence.setTag(Namespace.SIGNED + ' x').setData(result)
@staticmethod @staticmethod
def _get_info_message(): def _get_info_message():

View File

@@ -17,11 +17,11 @@
import os import os
import subprocess import subprocess
import nbxmpp from nbxmpp.namespaces import Namespace
def prepare_stanza(stanza, plaintext): def prepare_stanza(stanza, plaintext):
delete_nodes(stanza, 'encrypted', nbxmpp.NS_ENCRYPTED) delete_nodes(stanza, 'encrypted', Namespace.ENCRYPTED)
delete_nodes(stanza, 'body') delete_nodes(stanza, 'body')
stanza.setBody(plaintext) stanza.setBody(plaintext)