summaryrefslogtreecommitdiff
path: root/sleekxmpp/util
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/util')
-rw-r--r--sleekxmpp/util/__init__.py3
-rw-r--r--sleekxmpp/util/misc_ops.py11
2 files changed, 13 insertions, 1 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