]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: create a utf-8 string decoder for py3 compat
authorAlfredo Deza <adeza@redhat.com>
Thu, 10 Aug 2017 13:11:27 +0000 (09:11 -0400)
committerAndrew Schoen <aschoen@redhat.com>
Thu, 10 Aug 2017 15:35:08 +0000 (10:35 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit b50f1fb5527447c323fa51fb5c0ba260655dfb0d)

src/ceph-volume/ceph_volume/util/__init__.py

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..3b8c30906129db18092d951dbcdd8f16f92cb0f1 100644 (file)
@@ -0,0 +1,10 @@
+
+def as_string(string):
+    """
+    Ensure that whatever type of string is incoming, it is returned as an
+    actual string, versus 'bytes' which Python 3 likes to use.
+    """
+    if isinstance(string, bytes):
+        # we really ignore here if we can't properly decode with utf-8
+        return string.decode('utf-8', 'ignore')
+    return string