Adds utils.encoding:default_encode

This commit is contained in:
Ask Solem 2011-12-05 17:37:27 +00:00
parent 3b4629c726
commit 5b3c793dfb
1 changed files with 14 additions and 10 deletions

View File

@ -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):