aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2018-01-03 13:13:44 -0800
committerMartin Braun <martin.braun@ettus.com>2018-01-11 14:50:12 -0800
commitcdc9d60e73bfe5b256f57388c6ed66753af195db (patch)
tree20c32898f73c3098c1b6a672e68d7c214c166903
parentdd29b7be30c0e9a1bac24b25e71d39a8beb97de5 (diff)
downloaduhd-cdc9d60e73bfe5b256f57388c6ed66753af195db.tar.gz
uhd-cdc9d60e73bfe5b256f57388c6ed66753af195db.tar.bz2
uhd-cdc9d60e73bfe5b256f57388c6ed66753af195db.zip
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).
-rw-r--r--mpm/python/usrp_mpm/mpmutils.py7
1 files changed, 5 insertions, 2 deletions
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):