summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2014-06-09 08:28:57 -0700
committerLance Stout <lancestout@gmail.com>2014-06-09 08:29:48 -0700
commit768136e493916826187db9a7dbc4a3502b26c1bc (patch)
treead7fa6606aa2178dd756673b8967fd52ce940d5b
parent753cb3580e98d8230b7dc4f12cbf2fd0b47acf8a (diff)
downloadslixmpp-768136e493916826187db9a7dbc4a3502b26c1bc.tar.gz
slixmpp-768136e493916826187db9a7dbc4a3502b26c1bc.tar.bz2
slixmpp-768136e493916826187db9a7dbc4a3502b26c1bc.tar.xz
slixmpp-768136e493916826187db9a7dbc4a3502b26c1bc.zip
Fix things again, this time for python3
-rw-r--r--sleekxmpp/util/__init__.py3
-rw-r--r--sleekxmpp/util/misc_ops.py11
-rw-r--r--sleekxmpp/xmlstream/xmlstream.py30
3 files changed, 28 insertions, 16 deletions
diff --git a/sleekxmpp/util/__init__.py b/sleekxmpp/util/__init__.py
index 957a9335..05286d33 100644
--- a/sleekxmpp/util/__init__.py
+++ b/sleekxmpp/util/__init__.py
@@ -11,7 +11,8 @@
from sleekxmpp.util.misc_ops import bytes, unicode, hashes, hash, \
- num_to_bytes, bytes_to_num, quote, XOR
+ num_to_bytes, bytes_to_num, quote, \
+ XOR, safedict
# =====================================================================
diff --git a/sleekxmpp/util/misc_ops.py b/sleekxmpp/util/misc_ops.py
index c2533eec..18c919a8 100644
--- a/sleekxmpp/util/misc_ops.py
+++ b/sleekxmpp/util/misc_ops.py
@@ -129,6 +129,7 @@ def hashes():
hashes = ['SHA-' + h[3:] for h in dir(hashlib) if h.startswith('sha')]
return t + hashes
+
def setdefaultencoding(encoding):
"""
Set the current default string encoding used by the Unicode implementation.
@@ -152,3 +153,13 @@ def setdefaultencoding(encoding):
raise RuntimeError("Could not find setdefaultencoding")
sys.setdefaultencoding = func
return func(encoding)
+
+
+def safedict(data):
+ if sys.version_info < (2, 7):
+ safe = {}
+ for key in data:
+ safe[key.encode('utf8')] = data[key]
+ return safe
+ else:
+ return data
diff --git a/sleekxmpp/xmlstream/xmlstream.py b/sleekxmpp/xmlstream/xmlstream.py
index c5c9fe38..66985f3d 100644
--- a/sleekxmpp/xmlstream/xmlstream.py
+++ b/sleekxmpp/xmlstream/xmlstream.py
@@ -31,7 +31,7 @@ import errno
from xml.parsers.expat import ExpatError
import sleekxmpp
-from sleekxmpp.util import Queue, QueueEmpty
+from sleekxmpp.util import Queue, QueueEmpty, safedict
from sleekxmpp.thirdparty.statemachine import StateMachine
from sleekxmpp.xmlstream import Scheduler, tostring, cert
from sleekxmpp.xmlstream.stanzabase import StanzaBase, ET, ElementBase
@@ -518,13 +518,13 @@ class XMLStream(object):
else:
cert_policy = ssl.CERT_REQUIRED
- ssl_args = {
- b'certfile': self.certfile,
- b'keyfile': self.keyfile,
- b'ca_certs': self.ca_certs,
- b'cert_reqs': cert_policy,
- b'do_handshake_on_connect': False,
- }
+ ssl_args = safedict({
+ 'certfile': self.certfile,
+ 'keyfile': self.keyfile,
+ 'ca_certs': self.ca_certs,
+ 'cert_reqs': cert_policy,
+ 'do_handshake_on_connect': False
+ })
if sys.version_info >= (2, 7):
ssl_args['ciphers'] = self.ciphers
@@ -842,13 +842,13 @@ class XMLStream(object):
else:
cert_policy = ssl.CERT_REQUIRED
- ssl_args = {
- b'certfile': self.certfile,
- b'keyfile': self.keyfile,
- b'ca_certs': self.ca_certs,
- b'cert_reqs': cert_policy,
- b'do_handshake_on_connect': False,
- }
+ ssl_args = safedict({
+ 'certfile': self.certfile,
+ 'keyfile': self.keyfile,
+ 'ca_certs': self.ca_certs,
+ 'cert_reqs': cert_policy,
+ 'do_handshake_on_connect': False
+ })
if sys.version_info >= (2, 7):
ssl_args['ciphers'] = self.ciphers