diff options
Diffstat (limited to 'sleekxmpp/util/misc_ops.py')
-rw-r--r-- | sleekxmpp/util/misc_ops.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/sleekxmpp/util/misc_ops.py b/sleekxmpp/util/misc_ops.py index 3b246625..18c919a8 100644 --- a/sleekxmpp/util/misc_ops.py +++ b/sleekxmpp/util/misc_ops.py @@ -8,7 +8,10 @@ def unicode(text): text = text.decode('utf-8') import __builtin__ return __builtin__.unicode(text) - return str(text) + elif not isinstance(text, str): + return text.decode('utf-8') + else: + return text def bytes(text): @@ -126,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. @@ -148,4 +152,14 @@ def setdefaultencoding(encoding): if func is None: raise RuntimeError("Could not find setdefaultencoding") sys.setdefaultencoding = func - return func(encoding)
\ No newline at end of file + 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 |