From 8c22a63a24bcf0516897dbeb01251272921767b2 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Mon, 6 May 2019 11:33:40 -0400 Subject: [PATCH] util: add helper to convert to string Signed-off-by: Alfredo Deza Resolves: rm#39489 --- ceph_deploy/util/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ceph_deploy/util/__init__.py b/ceph_deploy/util/__init__.py index e69de29..a7d0838 100644 --- a/ceph_deploy/util/__init__.py +++ b/ceph_deploy/util/__init__.py @@ -0,0 +1,11 @@ + + +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