Compare commits

..

1 Commits

Author SHA1 Message Date
Emmanuel Gil Peyrot
f4683546d9 Manual cleanup of the remaining set([…]) and set((…)). 2016-10-22 13:35:54 +01:00
20 changed files with 13 additions and 175 deletions

View File

@@ -1,8 +0,0 @@
test:
tags:
- docker
image: ubuntu:latest
script:
- apt update
- apt install -y python3 cython3
- ./run_tests.py

View File

@@ -15,7 +15,6 @@
import asyncio import asyncio
import logging import logging
from slixmpp.jid import JID
from slixmpp.stanza import StreamFeatures from slixmpp.stanza import StreamFeatures
from slixmpp.basexmpp import BaseXMPP from slixmpp.basexmpp import BaseXMPP
from slixmpp.exceptions import XMPPError from slixmpp.exceptions import XMPPError
@@ -109,21 +108,10 @@ class ClientXMPP(BaseXMPP):
CoroutineCallback('Stream Features', CoroutineCallback('Stream Features',
MatchXPath('{%s}features' % self.stream_ns), MatchXPath('{%s}features' % self.stream_ns),
self._handle_stream_features)) self._handle_stream_features))
def roster_push_filter(iq):
from_ = iq['from']
if from_ and from_ != JID('') and from_ != self.boundjid.bare:
reply = iq.reply()
reply['type'] = 'error'
reply['error']['type'] = 'cancel'
reply['error']['code'] = 503
reply['error']['condition'] = 'service-unavailable'
reply.send()
return
self.event('roster_update', iq)
self.register_handler( self.register_handler(
Callback('Roster Update', Callback('Roster Update',
StanzaPath('iq@type=set/roster'), StanzaPath('iq@type=set/roster'),
roster_push_filter)) lambda iq: self.event('roster_update', iq)))
# Setup default stream features # Setup default stream features
self.register_plugin('feature_starttls') self.register_plugin('feature_starttls')

View File

@@ -121,7 +121,7 @@ class XEP_0009(BasePlugin):
def _recipient_unvailable(self, iq): def _recipient_unvailable(self, iq):
payload = iq.get_payload() payload = iq.get_payload()
iq = iq.reply() iq = iq.reply()
iq.error().set_payload(payload) error().set_payload(payload)
iq['error']['code'] = '404' iq['error']['code'] = '404'
iq['error']['type'] = 'wait' iq['error']['type'] = 'wait'
iq['error']['condition'] = 'recipient-unavailable' iq['error']['condition'] = 'recipient-unavailable'

View File

@@ -8,7 +8,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from slixmpp import JID
from slixmpp.xmlstream import ElementBase, register_stanza_plugin from slixmpp.xmlstream import ElementBase, register_stanza_plugin

View File

@@ -36,7 +36,7 @@ class URI(ElementBase):
self.xml.text = value self.xml.text = value
def del_value(self): def del_value(self):
self.xml.text = '' sel.xml.text = ''
register_stanza_plugin(Media, URI, iterable=True) register_stanza_plugin(Media, URI, iterable=True)

View File

@@ -28,7 +28,7 @@ class XEP_0222(BasePlugin):
profile = {'pubsub#persist_items': True, profile = {'pubsub#persist_items': True,
'pubsub#send_last_published_item': 'never'} 'pubsub#send_last_published_item': 'never'}
def configure(self, node, ifrom=None, callback=None, timeout=None): def configure(self, node):
""" """
Update a node's configuration to match the public storage profile. Update a node's configuration to match the public storage profile.
""" """

View File

@@ -28,7 +28,7 @@ class XEP_0223(BasePlugin):
profile = {'pubsub#persist_items': True, profile = {'pubsub#persist_items': True,
'pubsub#send_last_published_item': 'never'} 'pubsub#send_last_published_item': 'never'}
def configure(self, node, ifrom=None, callback=None, timeout=None): def configure(self, node):
""" """
Update a node's configuration to match the public storage profile. Update a node's configuration to match the public storage profile.
""" """

View File

@@ -8,7 +8,6 @@
from base64 import b64encode, b64decode from base64 import b64encode, b64decode
from slixmpp import JID
from slixmpp.util import bytes from slixmpp.util import bytes
from slixmpp.xmlstream import ElementBase, ET, register_stanza_plugin from slixmpp.xmlstream import ElementBase, ET, register_stanza_plugin

View File

@@ -135,5 +135,5 @@ class Archived(ElementBase):
def get_by(self): def get_by(self):
return JID(self._get_attr('by')) return JID(self._get_attr('by'))
def set_by(self, value): def set_by(self):
return self._set_attr('by', str(value)) return self._set_attr('by', str(value))

View File

@@ -10,7 +10,7 @@
from slixmpp import Iq, Message from slixmpp import Iq, Message
from slixmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID from slixmpp.xmlstream import register_stanza_plugin, ElementBase, ET, JID
import re from re import match
class Sensordata(ElementBase): class Sensordata(ElementBase):
""" Placeholder for the namespace, not used as a stanza """ """ Placeholder for the namespace, not used as a stanza """

View File

@@ -11,8 +11,6 @@ import logging
from slixmpp import Message from slixmpp import Message
from slixmpp.plugins import BasePlugin from slixmpp.plugins import BasePlugin
from slixmpp.xmlstream import register_stanza_plugin from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.plugins.xep_0333 import stanza, Markable, Received, Displayed, Acknowledged from slixmpp.plugins.xep_0333 import stanza, Markable, Received, Displayed, Acknowledged
log = logging.getLogger(__name__) log = logging.getLogger(__name__)

View File

@@ -1,15 +0,0 @@
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
from slixmpp.plugins.base import register_plugin
from slixmpp.plugins.xep_0380.stanza import Encryption
from slixmpp.plugins.xep_0380.eme import XEP_0380
register_plugin(XEP_0380)

View File

@@ -1,69 +0,0 @@
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
import logging
import slixmpp
from slixmpp.stanza import Message
from slixmpp.xmlstream.handler import Callback
from slixmpp.xmlstream.matcher import StanzaPath
from slixmpp.xmlstream import register_stanza_plugin, ElementBase, ET
from slixmpp.plugins import BasePlugin
from slixmpp.plugins.xep_0380 import stanza, Encryption
log = logging.getLogger(__name__)
class XEP_0380(BasePlugin):
"""
XEP-0380: Explicit Message Encryption
"""
name = 'xep_0380'
description = 'XEP-0380: Explicit Message Encryption'
dependencies = {'xep_0030'}
default_config = {
'template': 'This message is encrypted with {name} ({namespace})',
}
mechanisms = {
'jabber:x:encrypted': 'Legacy OpenPGP',
'urn:xmpp:ox:0': 'OpenPGP for XMPP',
'urn:xmpp:otr:0': 'OTR',
'eu.siacs.conversations.axolotl': 'Legacy OMEMO',
'urn:xmpp:omemo:0': 'OMEMO',
}
def plugin_init(self):
self.xmpp.register_handler(
Callback('Explicit Message Encryption',
StanzaPath('message/eme'),
self._handle_eme))
register_stanza_plugin(Message, Encryption)
def plugin_end(self):
self.xmpp.remove_handler('Chat State')
def session_bind(self, jid):
self.xmpp.plugin['xep_0030'].add_feature(Encryption.namespace)
def has_eme(self, msg):
return msg.xml.find('{%s}encryption' % Encryption.namespace) is not None
def replace_body_with_eme(self, msg):
eme = msg['eme']
namespace = eme['namespace']
name = self.mechanisms[namespace] if namespace in self.mechanisms else eme['name']
body = self.config['template'].format(name=name, namespace=namespace)
msg['body'] = body
def _handle_eme(self, msg):
self.xmpp.event('message_encryption', msg)

View File

@@ -1,16 +0,0 @@
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
from slixmpp.xmlstream import ElementBase
class Encryption(ElementBase):
name = 'encryption'
namespace = 'urn:xmpp:eme:0'
plugin_attrib = 'eme'
interfaces = {'namespace', 'name'}

View File

@@ -48,7 +48,7 @@ class Message(RootStanza):
namespace = 'jabber:client' namespace = 'jabber:client'
plugin_attrib = name plugin_attrib = name
interfaces = {'type', 'to', 'from', 'id', 'body', 'subject', 'thread', interfaces = {'type', 'to', 'from', 'id', 'body', 'subject', 'thread',
'parent_thread', 'mucroom', 'mucnick'} 'parent_thread', 'mucroom', 'mucnick'])
sub_interfaces = {'body', 'subject', 'thread'} sub_interfaces = {'body', 'subject', 'thread'}
lang_interfaces = sub_interfaces lang_interfaces = sub_interfaces
types = {'normal', 'chat', 'headline', 'error', 'groupchat'} types = {'normal', 'chat', 'headline', 'error', 'groupchat'}

View File

@@ -75,7 +75,7 @@ def sasl_mech(score):
MECH_SEC_SCORES[mech.name] = mech.score MECH_SEC_SCORES[mech.name] = mech.score
if mech.channel_binding: if mech.channel_binding:
MECHANISMS[mech.name + '-PLUS'] = mech MECHANISMS[mech.name + '-PLUS'] = mech
MECH_SEC_SCORES[mech.name] = mech.score + 10 MECH_SEC_SCORES[name] = mech.score + 10
return mech return mech
return register return register

View File

@@ -146,7 +146,6 @@ def create(nfkc=True, bidi=True, mappings=None,
if bidi: if bidi:
check_bidi(data) check_bidi(data)
if query and unassigned: if query and unassigned:
#check_unassigned(data, unassigned) check_unassigned(data, unassigned)
raise StringPrepError('Query profile with unassigned data is unimplemented.')
return data return data
return profile return profile

View File

@@ -9,5 +9,5 @@
# We don't want to have to import the entire library # We don't want to have to import the entire library
# just to get the version info for setup.py # just to get the version info for setup.py
__version__ = '1.2.3' __version__ = '1.2.1'
__version_info__ = (1, 2, 3) __version_info__ = (1, 2, 1)

View File

@@ -76,7 +76,7 @@ def extract_names(raw_cert):
name_type = name.getName() name_type = name.getName()
if name_type == 'dNSName': if name_type == 'dNSName':
results['DNS'].add(decode_str(name.getComponent())) results['DNS'].add(decode_str(name.getComponent()))
elif name_type == 'uniformResourceIdentifier': if name_type == 'uniformResourceIdentifier':
value = decode_str(name.getComponent()) value = decode_str(name.getComponent())
if value.startswith('xmpp:'): if value.startswith('xmpp:'):
results['URI'].add(value[5:]) results['URI'].add(value[5:])

View File

@@ -1,37 +0,0 @@
import unittest
from slixmpp import Message
from slixmpp.test import SlixTest
import slixmpp.plugins.xep_0380 as xep_0380
from slixmpp.xmlstream import register_stanza_plugin
class TestEME(SlixTest):
def setUp(self):
register_stanza_plugin(Message, xep_0380.stanza.Encryption)
def testCreateEME(self):
"""Testing creating EME."""
xmlstring = """
<message>
<encryption xmlns="urn:xmpp:eme:0" namespace="%s"%s />
</message>
"""
msg = self.Message()
self.check(msg, "<message />")
msg['eme']['namespace'] = 'urn:xmpp:otr:0'
self.check(msg, xmlstring % ('urn:xmpp:otr:0', ''))
msg['eme']['namespace'] = 'urn:xmpp:openpgp:0'
self.check(msg, xmlstring % ('urn:xmpp:openpgp:0', ''))
msg['eme']['name'] = 'OX'
self.check(msg, xmlstring % ('urn:xmpp:openpgp:0', ' name="OX"'))
del msg['eme']
self.check(msg, "<message />")
suite = unittest.TestLoader().loadTestsFromTestCase(TestEME)