summaryrefslogtreecommitdiff
path: root/sleekxmpp/util
diff options
context:
space:
mode:
authorPaul Molodowitch <elrond79@gmail.com>2012-10-24 11:27:52 -0700
committerLance Stout <lancestout@gmail.com>2012-10-24 13:06:36 -0700
commit52feabbe7641f19a17810438d2469b2395b2819f (patch)
treea54ad92b80775233aafc05acdf27adf3942973df /sleekxmpp/util
parenta22ca228cc3a121da8bad4268c39bff5190db969 (diff)
downloadslixmpp-52feabbe7641f19a17810438d2469b2395b2819f.tar.gz
slixmpp-52feabbe7641f19a17810438d2469b2395b2819f.tar.bz2
slixmpp-52feabbe7641f19a17810438d2469b2395b2819f.tar.xz
slixmpp-52feabbe7641f19a17810438d2469b2395b2819f.zip
added setdefaultencoding method so reload(sys) not needed
reload(sys) could cause problem in user code - ie, sys.stdout, excepthook, and displayhook would be reset, etc
Diffstat (limited to 'sleekxmpp/util')
-rw-r--r--sleekxmpp/util/misc_ops.py24
1 files changed, 24 insertions, 0 deletions
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