Commit 768136e4 authored by Lance Stout's avatar Lance Stout

Fix things again, this time for python3

parent 753cb358
......@@ -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
# =====================================================================
......
......@@ -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
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment