From cdc9d60e73bfe5b256f57388c6ed66753af195db Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 3 Jan 2018 13:13:44 -0800 Subject: mpm: utils: Fix to_native_str for non-string types Before, you couldn't use to_native_str for objects such as integers (i.e., anything that was not a bytes-like object). --- mpm/python/usrp_mpm/mpmutils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mpm/python') diff --git a/mpm/python/usrp_mpm/mpmutils.py b/mpm/python/usrp_mpm/mpmutils.py index eca6be4c2..49d6cb39d 100644 --- a/mpm/python/usrp_mpm/mpmutils.py +++ b/mpm/python/usrp_mpm/mpmutils.py @@ -50,9 +50,12 @@ def to_native_str(str_or_bstr): """ if isinstance(str_or_bstr, str): return str_or_bstr - if sys.version_info.major >= 3: + try: + # This will either fail because we're running Python 2 (which doesn't) + # have the encoding argument) or because we're not passing in a bytes- + # like object (e.g., an integer) return str(str_or_bstr, encoding='ascii') - else: + except TypeError: return str(str_or_bstr) def to_binary_str(str_or_bstr): -- cgit v1.2.3