summaryrefslogtreecommitdiffstats
path: root/litecli/encodingutils.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2020-08-14 16:58:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-02-07 10:11:48 +0000
commit4edd467b28c895483cd5468d51d1c6824a21715a (patch)
tree04a4f32d617905acfc23653025b6e8d3899f51c6 /litecli/encodingutils.py
parentInitial commit. (diff)
downloadlitecli-4edd467b28c895483cd5468d51d1c6824a21715a.tar.xz
litecli-4edd467b28c895483cd5468d51d1c6824a21715a.zip
Adding upstream version 1.5.0.upstream/1.5.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'litecli/encodingutils.py')
-rw-r--r--litecli/encodingutils.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/litecli/encodingutils.py b/litecli/encodingutils.py
new file mode 100644
index 0000000..6caf14d
--- /dev/null
+++ b/litecli/encodingutils.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from litecli.compat import PY2
+
+
+if PY2:
+ binary_type = str
+ string_types = basestring
+ text_type = unicode
+else:
+ binary_type = bytes
+ string_types = str
+ text_type = str
+
+
+def unicode2utf8(arg):
+ """Convert strings to UTF8-encoded bytes.
+
+ Only in Python 2. In Python 3 the args are expected as unicode.
+
+ """
+
+ if PY2 and isinstance(arg, text_type):
+ return arg.encode("utf-8")
+ return arg
+
+
+def utf8tounicode(arg):
+ """Convert UTF8-encoded bytes to strings.
+
+ Only in Python 2. In Python 3 the errors are returned as strings.
+
+ """
+
+ if PY2 and isinstance(arg, binary_type):
+ return arg.decode("utf-8")
+ return arg