From 5b3c793dfb78cce52f7f958b81273fb4ca3ebd6a Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Mon, 5 Dec 2011 17:37:27 +0000 Subject: [PATCH] Adds utils.encoding:default_encode --- kombu/utils/encoding.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/kombu/utils/encoding.py b/kombu/utils/encoding.py index 41550b77..44195eb0 100644 --- a/kombu/utils/encoding.py +++ b/kombu/utils/encoding.py @@ -18,6 +18,14 @@ import traceback is_py3k = sys.version_info >= (3, 0) +if sys.platform.startswith("java"): + + def default_encoding(): + return "utf-8" +else: + + def default_encoding(): # noqa + return sys.getfilesystemencoding() if is_py3k: @@ -39,6 +47,9 @@ if is_py3k: return str_to_bytes(s) return s + def default_encode(obj): + return obj + str_t = str bytes_t = bytes @@ -55,21 +66,14 @@ else: def from_utf8(s, *args, **kwargs): # noqa return s.encode("utf-8", *args, **kwargs) + def default_encode(obj): # noqa + return unicode(obj, default_encoding()) + str_t = unicode bytes_t = str ensure_bytes = str_to_bytes -if sys.platform.startswith("java"): - - def default_encoding(): - return "utf-8" -else: - - def default_encoding(): # noqa - return sys.getfilesystemencoding() - - def safe_str(s, errors="replace"): s = bytes_to_str(s) if not isinstance(s, basestring):