summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python/pmt/pmt_to_python.py
diff options
context:
space:
mode:
authorAndrej Rode <mail@andrejro.de>2018-06-23 23:41:42 +0200
committerAndrej Rode <mail@andrejro.de>2018-06-24 00:03:35 +0200
commit167a6152bad060fc53dd29e0fa79ef83eff1be5b (patch)
treea01049672d9d7d1bf3d295ed96698a323941f8e8 /gnuradio-runtime/python/pmt/pmt_to_python.py
parent3c8e6008b092287246234001db7cf1a4038300da (diff)
parentfcd002b6ac82e1e0c1224e24506410ff0833e1aa (diff)
Merge branch 'python3_fix' into next
Manual merge conflict resolution has been applied to following conflicts: * Typos: * gnuradio-runtime/python/gnuradio/ctrlport/GrDataPlotter.py * gr-blocks/python/blocks/qa_wavfile.py * gr-filter/examples/gr_filtdes_api.py * grc/blocks/parameter.xml * gr-uhd/python/uhd/__init__.py * ValueError -> RuntimeError: * gr-blocks/python/blocks/qa_hier_block2.py * relative Imports & other Py3k: * gr-digital/python/digital/psk_constellations.py * gr-digital/python/digital/qam_constellations.py * gr-digital/python/digital/test_soft_decisions.py * gr-digital/python/digital/gfsk.py * SequenceCompleter: * gr-utils/python/modtool/modtool_add.py * gr-utils/python/modtool/modtool_rename.py * gr-utils/python/modtool/modtool_rm.py * Updated API on next: * gr-blocks/grc/blocks_file_source.xml * gr-blocks/python/blocks/qa_file_source_sink.py * gr-qtgui/grc/qtgui_time_sink_x.xml * GRC Py3k Updates: * grc/core/Block.py * grc/core/Constants.py * grc/core/Platform.py * grc/core/utils/odict.py * grc/gui/Actions.py * grc/gui/Block.py * grc/gui/Executor.py * grc/gui/Port.py
Diffstat (limited to 'gnuradio-runtime/python/pmt/pmt_to_python.py')
-rw-r--r--gnuradio-runtime/python/pmt/pmt_to_python.py29
1 files changed, 15 insertions, 14 deletions
diff --git a/gnuradio-runtime/python/pmt/pmt_to_python.py b/gnuradio-runtime/python/pmt/pmt_to_python.py
index 2909c93c21..270a1dd9e9 100644
--- a/gnuradio-runtime/python/pmt/pmt_to_python.py
+++ b/gnuradio-runtime/python/pmt/pmt_to_python.py
@@ -17,8 +17,9 @@
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
-try: import pmt_swig as pmt
-except: import pmt
+from __future__ import unicode_literals
+
+from . import pmt_swig as pmt
import numpy
# SWIG isn't taking in the #define PMT_NIL;
@@ -34,7 +35,7 @@ def pmt_to_tuple(p):
return tuple(elems)
def pmt_from_tuple(p):
- args = map(python_to_pmt, p)
+ args = list(map(python_to_pmt, p))
return pmt.make_tuple(*args)
def pmt_to_vector(p):
@@ -62,7 +63,7 @@ def pmt_to_dict(p):
def pmt_from_dict(p):
d = pmt.make_dict()
- for k, v in p.iteritems():
+ for k, v in list(p.items()):
#dict is immutable -> therefore pmt_dict_add returns the new dict
d = pmt.dict_add(d, python_to_pmt(k), python_to_pmt(v))
return d
@@ -88,27 +89,27 @@ uvector_mappings = dict([ (numpy_mappings[key][3], (numpy_mappings[key][2], key)
def numpy_to_uvector(numpy_array):
try:
mapping = numpy_mappings[numpy_array.dtype]
- pc = map(mapping[1], numpy.ravel(numpy_array))
+ pc = list(map(mapping[1], numpy.ravel(numpy_array)))
return mapping[0](numpy_array.size, pc)
except KeyError:
raise ValueError("unsupported numpy array dtype for conversion to pmt %s"%(numpy_array.dtype))
def uvector_to_numpy(uvector):
- match = None
- for test_func in uvector_mappings.keys():
- if test_func(uvector):
- match = uvector_mappings[test_func]
- return numpy.array(match[0](uvector), dtype = match[1])
- else:
- raise ValueError("unsupported uvector data type for conversion to numpy array %s"%(uvector))
+ match = None
+ for test_func in list(uvector_mappings.keys()):
+ if test_func(uvector):
+ match = uvector_mappings[test_func]
+ return numpy.array(match[0](uvector), dtype = match[1])
+ else:
+ raise ValueError("unsupported uvector data type for conversion to numpy array %s"%(uvector))
type_mappings = ( #python type, check pmt type, to python, from python
(None, pmt.is_null, lambda x: None, lambda x: PMT_NIL),
(bool, pmt.is_bool, pmt.to_bool, pmt.from_bool),
(str, pmt.is_symbol, pmt.symbol_to_string, pmt.string_to_symbol),
- (unicode, lambda x: False, None, lambda x: pmt.string_to_symbol(x.encode('utf-8'))),
+ (str, lambda x: False, None, lambda x: pmt.string_to_symbol(x.encode('utf-8'))),
(int, pmt.is_integer, pmt.to_long, pmt.from_long),
- (long, pmt.is_uint64, lambda x: long(pmt.to_uint64(x)), pmt.from_uint64),
+ (int, pmt.is_uint64, lambda x: int(pmt.to_uint64(x)), pmt.from_uint64),
(float, pmt.is_real, pmt.to_double, pmt.from_double),
(complex, pmt.is_complex, pmt.to_complex, pmt.from_complex),
(tuple, pmt.is_tuple, pmt_to_tuple, pmt_from_tuple),