From: Alfredo Deza Date: Fri, 27 Jul 2018 15:13:19 +0000 (-0400) Subject: ceph-volume util create a helper for converting to bytes X-Git-Tag: v12.2.8~106^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1053aac7b0230e92032f8e035348687dd7982f74;p=ceph.git ceph-volume util create a helper for converting to bytes Signed-off-by: Alfredo Deza (cherry picked from commit fb518165445479cf08eefc8a2755ad78dcafd07f) --- 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