summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-10-24 13:07:19 -0700
committerLance Stout <lancestout@gmail.com>2012-10-24 13:07:19 -0700
commit06a690a2592cba388877391935ed4168d101a231 (patch)
tree54d5f70297b425cbb47ebc13415eaccf914c2152 /sleekxmpp
parent14c9e9a9cc263a2695cb9d8e5575d60bd0a55197 (diff)
parent52feabbe7641f19a17810438d2469b2395b2819f (diff)
downloadslixmpp-06a690a2592cba388877391935ed4168d101a231.tar.gz
slixmpp-06a690a2592cba388877391935ed4168d101a231.tar.bz2
slixmpp-06a690a2592cba388877391935ed4168d101a231.tar.xz
slixmpp-06a690a2592cba388877391935ed4168d101a231.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/basexmpp.py4
-rw-r--r--sleekxmpp/util/misc_ops.py24
2 files changed, 26 insertions, 2 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py
index 4df7f11a..c3ff5ba3 100644
--- a/sleekxmpp/basexmpp.py
+++ b/sleekxmpp/basexmpp.py
@@ -43,8 +43,8 @@ log = logging.getLogger(__name__)
# In order to make sure that Unicode is handled properly
# in Python 2.x, reset the default encoding.
if sys.version_info < (3, 0):
- reload(sys)
- sys.setdefaultencoding('utf8')
+ from sleekxmpp.util.misc_ops import setdefaultencoding
+ setdefaultencoding('utf8')
class BaseXMPP(XMLStream):
diff --git a/sleekxmpp/util/misc_ops.py b/sleekxmpp/util/misc_ops.py
index 9bb1db4b..3b246625 100644
--- a/sleekxmpp/util/misc_ops.py
+++ b/sleekxmpp/util/misc_ops.py
@@ -125,3 +125,27 @@ def hashes():
t += ['MD2']
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.
+
+ Actually calls sys.setdefaultencoding under the hood - see the docs for that
+ for more details. This method exists only as a way to call find/call it
+ even after it has been 'deleted' when the site module is executed.
+
+ :param string encoding: An encoding name, compatible with sys.setdefaultencoding
+ """
+ func = getattr(sys, 'setdefaultencoding', None)
+ if func is None:
+ import gc
+ import types
+ for obj in gc.get_objects():
+ if (isinstance(obj, types.BuiltinFunctionType)
+ and obj.__name__ == 'setdefaultencoding'):
+ func = obj
+ break
+ if func is None:
+ raise RuntimeError("Could not find setdefaultencoding")
+ sys.setdefaultencoding = func
+ return func(encoding) \ No newline at end of file