From 1053aac7b0230e92032f8e035348687dd7982f74 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Fri, 27 Jul 2018 11:13:19 -0400 Subject: [PATCH] ceph-volume util create a helper for converting to bytes Signed-off-by: Alfredo Deza (cherry picked from commit fb518165445479cf08eefc8a2755ad78dcafd07f) --- 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 0222d56a0791f..dfa83fc46d35f 100644 --- a/src/ceph-volume/ceph_volume/util/__init__.py +++ b/src/ceph-volume/ceph_volume/util/__init__.py @@ -16,6 +16,16 @@ def as_string(string): return string +def as_bytes(string): + """ + Ensure that whatever type of string is incoming, it is returned as bytes, + encoding to utf-8 otherwise + """ + if isinstance(string, bytes): + return string + return string.encode('utf-8', errors='ignore') + + def str_to_int(string, round_down=True): """ Parses a string number into an integer, optionally converting to a float -- 2.39.5