From b50f1fb5527447c323fa51fb5c0ba260655dfb0d Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Thu, 10 Aug 2017 09:11:27 -0400 Subject: [PATCH] ceph-volume: create a utf-8 string decoder for py3 compat Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/util/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ceph-volume/ceph_volume/util/__init__.py b/src/ceph-volume/ceph_volume/util/__init__.py index e69de29bb2d..3b8c3090612 100644 --- a/src/ceph-volume/ceph_volume/util/__init__.py +++ b/src/ceph-volume/ceph_volume/util/__init__.py @@ -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 -- 2.47.3