commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 11/101: grc: py3k compat using python-moder


From: git
Subject: [Commit-gnuradio] [gnuradio] 11/101: grc: py3k compat using python-modernize
Date: Thu, 16 Mar 2017 14:57:57 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit 94c4606edd30dc8b1278580782f2809b69f04641
Author: Sebastian Koslowski <address@hidden>
Date:   Fri Jun 3 10:02:36 2016 +0200

    grc: py3k compat using python-modernize
---
 grc/checks.py                        |  1 +
 grc/core/Block.py                    | 33 +++++++++--------
 grc/core/Config.py                   |  1 +
 grc/core/Connection.py               |  8 +++--
 grc/core/Constants.py                | 10 ++++--
 grc/core/Element.py                  |  6 ++--
 grc/core/FlowGraph.py                | 57 +++++++++++++++--------------
 grc/core/Messages.py                 |  3 +-
 grc/core/Param.py                    | 69 ++++++++++++++++++------------------
 grc/core/ParseXML.py                 | 21 +++++++----
 grc/core/Platform.py                 | 34 ++++++++++--------
 grc/core/Port.py                     | 41 +++++++++++----------
 grc/core/generator/FlowGraphProxy.py | 16 +++++----
 grc/core/generator/Generator.py      | 30 +++++++++-------
 grc/core/generator/__init__.py       |  3 +-
 grc/core/utils/__init__.py           | 10 +++---
 grc/core/utils/complexity.py         | 13 +++----
 grc/core/utils/epy_block_io.py       | 11 ++++--
 grc/core/utils/expr_utils.py         | 21 ++++++-----
 grc/core/utils/extract_docs.py       | 28 ++++++++-------
 grc/core/utils/odict.py              |  2 ++
 grc/gui/ActionHandler.py             |  8 +++--
 grc/gui/Actions.py                   | 14 +++++---
 grc/gui/Bars.py                      |  3 +-
 grc/gui/Block.py                     |  3 +-
 grc/gui/BlockTreeWindow.py           | 14 +++++---
 grc/gui/Colors.py                    |  1 +
 grc/gui/Config.py                    |  7 ++--
 grc/gui/Connection.py                | 16 ++++-----
 grc/gui/Constants.py                 |  1 +
 grc/gui/Dialogs.py                   |  1 +
 grc/gui/DrawingArea.py               |  1 +
 grc/gui/Element.py                   |  6 ++--
 grc/gui/Executor.py                  |  1 +
 grc/gui/FileDialogs.py               |  9 ++---
 grc/gui/FlowGraph.py                 | 14 +++++---
 grc/gui/MainWindow.py                |  6 ++--
 grc/gui/NotebookPage.py              |  1 +
 grc/gui/Param.py                     |  1 +
 grc/gui/ParamWidgets.py              |  1 +
 grc/gui/ParserErrorsDialog.py        |  8 +++--
 grc/gui/Platform.py                  |  4 ++-
 grc/gui/Port.py                      |  8 ++---
 grc/gui/Preferences.py               | 21 ++++++-----
 grc/gui/PropsDialog.py               |  6 ++--
 grc/gui/StateCache.py                |  5 +--
 grc/gui/Utils.py                     |  8 +++--
 grc/gui/VariableEditor.py            |  6 ++--
 grc/gui/external_editor.py           |  6 ++--
 grc/main.py                          |  1 +
 50 files changed, 356 insertions(+), 243 deletions(-)

diff --git a/grc/checks.py b/grc/checks.py
index 66c114d..40a0b2b 100755
--- a/grc/checks.py
+++ b/grc/checks.py
@@ -15,6 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
+from __future__ import absolute_import
 import os
 import warnings
 
diff --git a/grc/core/Block.py b/grc/core/Block.py
index aafc5db..062598e 100644
--- a/grc/core/Block.py
+++ b/grc/core/Block.py
@@ -17,9 +17,13 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 import collections
 import itertools
 
+from six.moves import map, range
+
 from Cheetah.Template import Template
 
 from .utils import epy_block_io, odict
@@ -70,7 +74,7 @@ class Block(Element):
             self._flags += BLOCK_FLAG_THROTTLE
 
         self._doc = (n.find('doc') or '').strip('\n').replace('\\\n', '')
-        self._imports = map(lambda i: i.strip(), n.findall('import'))
+        self._imports = [i.strip() for i in n.findall('import')]
         self._make = n.find('make')
         self._var_make = n.find('var_make')
         self._var_value = n.find('var_value') or '$value'
@@ -250,7 +254,7 @@ class Block(Element):
             self.back_ofthe_bus(ports)
             # Renumber non-message/message ports
             domain_specific_port_index = collections.defaultdict(int)
-            for port in filter(lambda p: p.get_key().isdigit(), ports):
+            for port in [p for p in ports if p.get_key().isdigit()]:
                 domain = port.get_domain()
                 port._key = str(domain_specific_port_index[domain])
                 domain_specific_port_index[domain] += 1
@@ -275,7 +279,8 @@ class Block(Element):
         """
         if raw:
             return self._imports
-        return filter(lambda i: i, sum(map(lambda i: 
self.resolve_dependencies(i).split('\n'), self._imports), []))
+        return [i for i in sum([self.resolve_dependencies(i).split('\n')
+                                for i in self._imports], []) if i]
 
     def get_make(self, raw=False):
         if raw:
@@ -300,7 +305,7 @@ class Block(Element):
             if 'self.' in callback:
                 return callback
             return 'self.{}.{}'.format(self.get_id(), callback)
-        return map(make_callback, self._callbacks)
+        return [make_callback(c) for c in self._callbacks]
 
     def is_virtual_sink(self):
         return self.get_key() == 'virtual_sink'
@@ -622,10 +627,10 @@ class Block(Element):
         """
         changed = False
         type_param = None
-        for param in filter(lambda p: p.is_enum(), self.get_params()):
+        for param in [p for p in self.get_params() if p.is_enum()]:
             children = self.get_ports() + self.get_params()
             # Priority to the type controller
-            if param.get_key() in ' '.join(map(lambda p: p._type, children)): 
type_param = param
+            if param.get_key() in ' '.join([p._type for p in children]): 
type_param = param
             # Use param if type param is unset
             if not type_param:
                 type_param = param
@@ -681,10 +686,10 @@ class Block(Element):
         """
         n = odict()
         n['key'] = self.get_key()
-        n['param'] = map(lambda p: p.export_data(), sorted(self.get_params(), 
key=str))
-        if 'bus' in map(lambda a: a.get_type(), self.get_sinks()):
+        n['param'] = [p.export_data() for p in sorted(self.get_params(), 
key=str)]
+        if 'bus' in [a.get_type() for a in self.get_sinks()]:
             n['bus_sink'] = str(1)
-        if 'bus' in map(lambda a: a.get_type(), self.get_sources()):
+        if 'bus' in [a.get_type() for a in self.get_sources()]:
             n['bus_source'] = str(1)
         return n
 
@@ -773,12 +778,12 @@ class Block(Element):
             get_p_gui = self.get_sinks_gui
             bus_structure = self.get_bus_structure('sink')
 
-        struct = [range(len(get_p()))]
-        if True in map(lambda a: isinstance(a.get_nports(), int), get_p()):
+        struct = [list(range(len(get_p())))]
+        if True in [isinstance(a.get_nports(), int) for a in get_p()]:
             structlet = []
             last = 0
             for j in [i.get_nports() for i in get_p() if 
isinstance(i.get_nports(), int)]:
-                structlet.extend(map(lambda a: a+last, range(j)))
+                structlet.extend([a+last for a in range(j)])
                 last = structlet[-1] + 1
                 struct = [structlet]
         if bus_structure:
@@ -802,7 +807,7 @@ class Block(Element):
             for connect in elt.get_connections():
                 self.get_parent().remove_element(connect)
 
-        if ('bus' not in map(lambda a: a.get_type(), get_p())) and 
len(get_p()) > 0:
+        if ('bus' not in [a.get_type() for a in get_p()]) and len(get_p()) > 0:
             struct = self.form_bus_structure(direc)
             self.current_bus_structure[direc] = struct
             if get_p()[0].get_nports():
@@ -813,7 +818,7 @@ class Block(Element):
                 n = odict(n)
                 port = self.get_parent().get_parent().Port(block=self, n=n, 
dir=direc)
                 get_p().append(port)
-        elif 'bus' in map(lambda a: a.get_type(), get_p()):
+        elif 'bus' in [a.get_type() for a in get_p()]:
             for elt in get_p_gui():
                 get_p().remove(elt)
             self.current_bus_structure[direc] = ''
diff --git a/grc/core/Config.py b/grc/core/Config.py
index ac38d99..400d5d3 100644
--- a/grc/core/Config.py
+++ b/grc/core/Config.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import os
 from os.path import expanduser, normpath, expandvars, exists
 
diff --git a/grc/core/Connection.py b/grc/core/Connection.py
index 3aa32ef..ddc6c02 100644
--- a/grc/core/Connection.py
+++ b/grc/core/Connection.py
@@ -17,6 +17,10 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
+from six.moves import range
+
 from . import Constants
 from .Element import Element
 from .utils import odict
@@ -51,8 +55,8 @@ class Connection(Element):
             raise ValueError('Connection could not isolate source')
         if not sink:
             raise ValueError('Connection could not isolate sink')
-        busses = len(filter(lambda a: a.get_type() == 'bus', [source, sink])) 
% 2
-        if not busses == 0:
+
+        if (source.get_type() == 'bus') != (sink.get_type() == 'bus'):
             raise ValueError('busses must get with busses')
 
         if not len(source.get_associated_ports()) == 
len(sink.get_associated_ports()):
diff --git a/grc/core/Constants.py b/grc/core/Constants.py
index 4f278bb..8a99f8b 100644
--- a/grc/core/Constants.py
+++ b/grc/core/Constants.py
@@ -17,10 +17,14 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 import os
-import numpy
 import stat
 
+import numpy
+import six
+
 # Data files
 DATA_DIR = os.path.dirname(__file__)
 FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
@@ -63,7 +67,7 @@ HIER_BLOCK_FILE_MODE = stat.S_IRUSR | stat.S_IWUSR | 
stat.S_IRGRP | stat.S_IWGRP
 VECTOR_TYPES = (tuple, list, set, numpy.ndarray)
 COMPLEX_TYPES = [complex, numpy.complex, numpy.complex64, numpy.complex128]
 REAL_TYPES = [float, numpy.float, numpy.float32, numpy.float64]
-INT_TYPES = [int, long, numpy.int, numpy.int8, numpy.int16, numpy.int32, 
numpy.uint64,
+INT_TYPES = [int, numpy.int, numpy.int8, numpy.int16, numpy.int32, 
numpy.uint64,
              numpy.uint, numpy.uint8, numpy.uint16, numpy.uint32, numpy.uint64]
 # Cast to tuple for isinstance, concat subtypes
 COMPLEX_TYPES = tuple(COMPLEX_TYPES + REAL_TYPES + INT_TYPES)
@@ -129,6 +133,6 @@ for name, key, sizeof, color in CORE_TYPES:
     TYPE_TO_COLOR[key] = color
     TYPE_TO_SIZEOF[key] = sizeof
 
-for key, (sizeof, color) in ALIAS_TYPES.iteritems():
+for key, (sizeof, color) in six.iteritems(ALIAS_TYPES):
     TYPE_TO_COLOR[key] = color
     TYPE_TO_SIZEOF[key] = sizeof
diff --git a/grc/core/Element.py b/grc/core/Element.py
index 67c36e1..e697d29 100644
--- a/grc/core/Element.py
+++ b/grc/core/Element.py
@@ -22,7 +22,7 @@ class Element(object):
 
     def __init__(self, parent=None):
         self._parent = parent
-        self._error_messages = list()
+        self._error_messages = []
 
     ##################################################
     # Element Validation API
@@ -64,7 +64,9 @@ class Element(object):
             a list of error message strings
         """
         error_messages = list(self._error_messages)  # Make a copy
-        for child in filter(lambda c: c.get_enabled() and not 
c.get_bypassed(), self.get_children()):
+        for child in self.get_children():
+            if not child.get_enabled() or child.get_bypassed():
+                continue
             for msg in child.get_error_messages():
                 error_messages.append("{}:\n\t{}".format(child, 
msg.replace("\n", "\n\t")))
         return error_messages
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index 949eeca..9edd4f2 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -15,12 +15,15 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
+from __future__ import absolute_import, print_function
+
 import imp
 import time
-from itertools import ifilter, chain
+import re
+from itertools import chain
 from operator import methodcaller, attrgetter
 
-import re
+from six.moves import filter
 
 from . import Messages
 from .Constants import FLOW_GRAPH_FILE_FORMAT_VERSION
@@ -87,7 +90,7 @@ class FlowGraph(Element):
         Returns:
             a sorted list of variable blocks in order of dependency (indep -> 
dep)
         """
-        variables = filter(attrgetter('is_variable'), 
self.iter_enabled_blocks())
+        variables = list(filter(attrgetter('is_variable'), 
self.iter_enabled_blocks()))
         return expr_utils.sort_objects(variables, methodcaller('get_id'), 
methodcaller('get_var_make'))
 
     def get_parameters(self):
@@ -97,15 +100,14 @@ class FlowGraph(Element):
         Returns:
             a list of parameterized variables
         """
-        parameters = filter(lambda b: _parameter_matcher.match(b.get_key()), 
self.iter_enabled_blocks())
+        parameters = [b for b in self.iter_enabled_blocks() if 
_parameter_matcher.match(b.get_key())]
         return parameters
 
     def get_monitors(self):
         """
         Get a list of all ControlPort monitors
         """
-        monitors = filter(lambda b: _monitors_searcher.search(b.get_key()),
-                          self.iter_enabled_blocks())
+        monitors = [b for b in self.iter_enabled_blocks() if 
_monitors_searcher.search(b.get_key())]
         return monitors
 
     def get_python_modules(self):
@@ -115,7 +117,7 @@ class FlowGraph(Element):
                 yield block.get_id(), 
block.get_param('source_code').get_value()
 
     def get_bussink(self):
-        bussink = filter(lambda b: _bussink_searcher.search(b.get_key()), 
self.get_enabled_blocks())
+        bussink = [b for b in self.get_enabled_blocks() if 
_bussink_searcher.search(b.get_key())]
 
         for i in bussink:
             for j in i.get_params():
@@ -124,7 +126,7 @@ class FlowGraph(Element):
         return False
 
     def get_bussrc(self):
-        bussrc = filter(lambda b: _bussrc_searcher.search(b.get_key()), 
self.get_enabled_blocks())
+        bussrc = [b for b in self.get_enabled_blocks() if 
_bussrc_searcher.search(b.get_key())]
 
         for i in bussrc:
             for j in i.get_params():
@@ -133,18 +135,18 @@ class FlowGraph(Element):
         return False
 
     def get_bus_structure_sink(self):
-        bussink = filter(lambda b: 
_bus_struct_sink_searcher.search(b.get_key()), self.get_enabled_blocks())
+        bussink = [b for b in self.get_enabled_blocks() if 
_bus_struct_sink_searcher.search(b.get_key())]
         return bussink
 
     def get_bus_structure_src(self):
-        bussrc = filter(lambda b: 
_bus_struct_src_searcher.search(b.get_key()), self.get_enabled_blocks())
+        bussrc = [b for b in self.get_enabled_blocks() if 
_bus_struct_src_searcher.search(b.get_key())]
         return bussrc
 
     def iter_enabled_blocks(self):
         """
         Get an iterator of all blocks that are enabled and not bypassed.
         """
-        return ifilter(methodcaller('get_enabled'), self.blocks)
+        return filter(methodcaller('get_enabled'), self.blocks)
 
     def get_enabled_blocks(self):
         """
@@ -162,7 +164,7 @@ class FlowGraph(Element):
         Returns:
             a list of blocks
         """
-        return filter(methodcaller('get_bypassed'), self.blocks)
+        return list(filter(methodcaller('get_bypassed'), self.blocks))
 
     def get_enabled_connections(self):
         """
@@ -171,7 +173,7 @@ class FlowGraph(Element):
         Returns:
             a list of connections
         """
-        return filter(methodcaller('get_enabled'), self.connections)
+        return list(filter(methodcaller('get_enabled'), self.connections))
 
     def get_option(self, key):
         """
@@ -206,7 +208,7 @@ class FlowGraph(Element):
         options_block_count = self.blocks.count(self._options_block)
         if not options_block_count:
             self.blocks.append(self._options_block)
-        for i in range(options_block_count-1):
+        for _ in range(options_block_count-1):
             self.blocks.remove(self._options_block)
 
         return self.blocks + self.connections
@@ -229,14 +231,14 @@ class FlowGraph(Element):
         # Load imports
         for expr in self.get_imports():
             try:
-                exec expr in namespace
+                exec(expr, namespace)
             except:
                 pass
 
         for id, expr in self.get_python_modules():
             try:
                 module = imp.new_module(id)
-                exec expr in module.__dict__
+                exec(expr, module.__dict__)
                 namespace[id] = module
             except:
                 pass
@@ -333,15 +335,15 @@ class FlowGraph(Element):
         if element in self.blocks:
             # Remove block, remove all involved connections
             for port in element.get_ports():
-                map(self.remove_element, port.get_connections())
+                for connection in port.get_connections():
+                    self.remove_element(connection)
             self.blocks.remove(element)
 
         elif element in self.connections:
             if element.is_bus():
-                cons_list = []
-                for i in map(lambda a: a.get_connections(), 
element.get_source().get_associated_ports()):
-                    cons_list.extend(i)
-                map(self.remove_element, cons_list)
+                for port in element.get_source().get_associated_ports():
+                    for connection in port.get_connections():
+                        self.remove_element(connection)
             self.connections.remove(element)
 
     ##############################################
@@ -484,21 +486,19 @@ class FlowGraph(Element):
                     get_p_gui = block.get_sinks_gui
                     bus_structure = block.form_bus_structure('sink')
 
-                if 'bus' in map(lambda a: a.get_type(), get_p_gui()):
+                if 'bus' in [a.get_type() for a in get_p_gui()]:
                     if len(get_p_gui()) > len(bus_structure):
-                        times = range(len(bus_structure), len(get_p_gui()))
+                        times = list(range(len(bus_structure), 
len(get_p_gui())))
                         for i in times:
                             for connect in get_p_gui()[-1].get_connections():
                                 block.get_parent().remove_element(connect)
                             get_p().remove(get_p_gui()[-1])
                     elif len(get_p_gui()) < len(bus_structure):
                         n = {'name': 'bus', 'type': 'bus'}
-                        if True in map(
-                                lambda a: isinstance(a.get_nports(), int),
-                                get_p()):
+                        if any(isinstance(a.get_nports(), int) for a in 
get_p()):
                             n['nports'] = str(1)
 
-                        times = range(len(get_p_gui()), len(bus_structure))
+                        times = list(range(len(get_p_gui()), 
len(bus_structure)))
 
                         for i in times:
                             n['key'] = str(len(get_p()))
@@ -507,8 +507,7 @@ class FlowGraph(Element):
                                 block=block, n=n, dir=direc)
                             get_p().append(port)
 
-                if 'bus' in map(lambda a: a.get_type(),
-                                block.get_sources_gui()):
+                if 'bus' in [a.get_type() for a in block.get_sources_gui()]:
                     for i in range(len(block.get_sources_gui())):
                         if len(block.get_sources_gui()[
                                    i].get_connections()) > 0:
diff --git a/grc/core/Messages.py b/grc/core/Messages.py
index 8daa12c..596b619 100644
--- a/grc/core/Messages.py
+++ b/grc/core/Messages.py
@@ -16,9 +16,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
 
+from __future__ import absolute_import
+
 import traceback
 import sys
-import os
 
 #  A list of functions that can receive a message.
 MESSENGERS_LIST = list()
diff --git a/grc/core/Param.py b/grc/core/Param.py
index 73d54b6..45f0187 100644
--- a/grc/core/Param.py
+++ b/grc/core/Param.py
@@ -17,20 +17,20 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 import ast
 import weakref
 import re
 
+from six.moves import builtins, filter, map, range, zip
+
 from . import Constants
-from .Constants import VECTOR_TYPES, COMPLEX_TYPES, REAL_TYPES, INT_TYPES
 from .Element import Element
 from .utils import odict
 
 # Blacklist certain ids, its not complete, but should help
-import __builtin__
-
-
-ID_BLACKLIST = ['self', 'options', 'gr', 'blks2', 'wxgui', 'wx', 'math', 
'forms', 'firdes'] + dir(__builtin__)
+ID_BLACKLIST = ['self', 'options', 'gr', 'blks2', 'wxgui', 'wx', 'math', 
'forms', 'firdes'] + dir(builtins)
 try:
     from gnuradio import gr
     ID_BLACKLIST.extend(attr for attr in dir(gr.top_block()) if not 
attr.startswith('_'))
@@ -64,7 +64,7 @@ def num_to_str(num):
                 return template.format(value / factor, symbol.strip())
         return template.format(value, '')
 
-    if isinstance(num, COMPLEX_TYPES):
+    if isinstance(num, Constants.COMPLEX_TYPES):
         num = complex(num)  # Cast to python complex
         if num == 0:
             return '0'
@@ -112,13 +112,13 @@ class Option(Element):
     # Access Opts
     ##############################################
     def get_opt_keys(self):
-        return self._opts.keys()
+        return list(self._opts.keys())
 
     def get_opt(self, key):
         return self._opts[key]
 
     def get_opts(self):
-        return self._opts.values()
+        return list(self._opts.values())
 
 
 class TemplateArg(object):
@@ -176,7 +176,8 @@ class Param(Element):
         # Create the Option objects from the n data
         self._options = list()
         self._evaluated = None
-        for option in map(lambda o: Option(param=self, n=o), 
n.findall('option')):
+        for o_n in n.findall('option'):
+            option = Option(param=self, n=o_n)
             key = option.get_key()
             # Test against repeated keys
             if key in self.get_option_keys():
@@ -257,9 +258,9 @@ class Param(Element):
         t = self.get_type()
         if isinstance(e, bool):
             return str(e)
-        elif isinstance(e, COMPLEX_TYPES):
+        elif isinstance(e, Constants.COMPLEX_TYPES):
             dt_str = num_to_str(e)
-        elif isinstance(e, VECTOR_TYPES):
+        elif isinstance(e, Constants.VECTOR_TYPES):
             # Vector types
             if len(e) > 8:
                 # Large vectors use code
@@ -310,13 +311,10 @@ class Param(Element):
         if self.get_key() == 'id' and not 
_show_id_matcher.match(self.get_parent().get_key()):
             return 'part'
         # Hide port controllers for type and nports
-        if self.get_key() in ' '.join(map(lambda p: ' '.join([p._type, 
p._nports]),
-                                          self.get_parent().get_ports())):
+        if self.get_key() in ' '.join([' '.join([p._type, p._nports]) for p in 
self.get_parent().get_ports()]):
             return 'part'
         # Hide port controllers for vlen, when == 1
-        if self.get_key() in ' '.join(map(
-            lambda p: p._vlen, self.get_parent().get_ports())
-        ):
+        if self.get_key() in ' '.join(p._vlen for p in 
self.get_parent().get_ports()):
             try:
                 if int(self.get_evaluated()) == 1:
                     return 'part'
@@ -339,7 +337,7 @@ class Param(Element):
         self._evaluated = None
         try:
             self._evaluated = self.evaluate()
-        except Exception, e:
+        except Exception as e:
             self.add_error_message(str(e))
 
     def get_evaluated(self):
@@ -372,21 +370,21 @@ class Param(Element):
             # Raise exception if python cannot evaluate this value
             try:
                 e = self.get_parent().get_parent().evaluate(v)
-            except Exception, e:
+            except Exception as e:
                 raise Exception('Value "{}" cannot be 
evaluated:\n{}'.format(v, e))
             # Raise an exception if the data is invalid
             if t == 'raw':
                 return e
             elif t == 'complex':
-                if not isinstance(e, COMPLEX_TYPES):
+                if not isinstance(e, Constants.COMPLEX_TYPES):
                     raise Exception('Expression "{}" is invalid for type 
complex.'.format(str(e)))
                 return e
             elif t == 'real' or t == 'float':
-                if not isinstance(e, REAL_TYPES):
+                if not isinstance(e, Constants.REAL_TYPES):
                     raise Exception('Expression "{}" is invalid for type 
float.'.format(str(e)))
                 return e
             elif t == 'int':
-                if not isinstance(e, INT_TYPES):
+                if not isinstance(e, Constants.INT_TYPES):
                     raise Exception('Expression "{}" is invalid for type 
integer.'.format(str(e)))
                 return e
             elif t == 'hex':
@@ -407,28 +405,28 @@ class Param(Element):
             # Raise exception if python cannot evaluate this value
             try:
                 e = self.get_parent().get_parent().evaluate(v)
-            except Exception, e:
+            except Exception as e:
                 raise Exception('Value "{}" cannot be 
evaluated:\n{}'.format(v, e))
             # Raise an exception if the data is invalid
             if t == 'complex_vector':
-                if not isinstance(e, VECTOR_TYPES):
+                if not isinstance(e, Constants.VECTOR_TYPES):
                     self._lisitify_flag = True
                     e = [e]
-                if not all([isinstance(ei, COMPLEX_TYPES) for ei in e]):
+                if not all([isinstance(ei, Constants.COMPLEX_TYPES) for ei in 
e]):
                     raise Exception('Expression "{}" is invalid for type 
complex vector.'.format(str(e)))
                 return e
             elif t == 'real_vector' or t == 'float_vector':
-                if not isinstance(e, VECTOR_TYPES):
+                if not isinstance(e, Constants.VECTOR_TYPES):
                     self._lisitify_flag = True
                     e = [e]
-                if not all([isinstance(ei, REAL_TYPES) for ei in e]):
+                if not all([isinstance(ei, Constants.REAL_TYPES) for ei in e]):
                     raise Exception('Expression "{}" is invalid for type float 
vector.'.format(str(e)))
                 return e
             elif t == 'int_vector':
-                if not isinstance(e, VECTOR_TYPES):
+                if not isinstance(e, Constants.VECTOR_TYPES):
                     self._lisitify_flag = True
                     e = [e]
-                if not all([isinstance(ei, INT_TYPES) for ei in e]):
+                if not all([isinstance(ei, Constants.INT_TYPES) for ei in e]):
                     raise Exception('Expression "{}" is invalid for type 
integer vector.'.format(str(e)))
                 return e
         #########################
@@ -545,7 +543,7 @@ class Param(Element):
                 for c in range(col_span):
                     self._hostage_cells.append((my_parent, (row+r, col+c)))
             # Avoid collisions
-            params = filter(lambda p: p is not self, 
self.get_all_params('grid_pos'))
+            params = [p for p in self.get_all_params('grid_pos') if p is not 
self]
             for param in params:
                 for parent, cell in param._hostage_cells:
                     if (parent, cell) in self._hostage_cells:
@@ -560,7 +558,7 @@ class Param(Element):
                 return ''
 
             # Get a list of all notebooks
-            notebook_blocks = filter(lambda b: b.get_key() == 'notebook', 
self.get_parent().get_parent().get_enabled_blocks())
+            notebook_blocks = [b for b in 
self.get_parent().get_parent().get_enabled_blocks() if b.get_key() == 
'notebook']
             # Check for notebook param syntax
             try:
                 notebook_id, page_index = map(str.strip, v.split(','))
@@ -568,7 +566,7 @@ class Param(Element):
                 raise Exception('Bad notebook page format.')
             # Check that the notebook id is valid
             try:
-                notebook_block = filter(lambda b: b.get_id() == notebook_id, 
notebook_blocks)[0]
+                notebook_block = [b for b in notebook_blocks if b.get_id() == 
notebook_id][0]
             except:
                 raise Exception('Notebook id "{}" is not an existing notebook 
id.'.format(notebook_id))
 
@@ -584,12 +582,12 @@ class Param(Element):
             # New namespace
             n = dict()
             try:
-                exec v in n
+                exec(v, n)
             except ImportError:
                 raise Exception('Import "{}" failed.'.format(v))
             except Exception:
                 raise Exception('Bad import syntax: "{}".'.format(v))
-            return filter(lambda k: str(k) != '__builtins__', n.keys())
+            return [k for k in list(n.keys()) if str(k) != '__builtins__']
 
         #########################
         else:
@@ -635,7 +633,10 @@ class Param(Element):
         Returns:
             a list of params
         """
-        return sum([filter(lambda p: p.get_type() == type, block.get_params()) 
for block in self.get_parent().get_parent().get_enabled_blocks()], [])
+        params = []
+        for block in self.get_parent().get_parent().get_enabled_blocks():
+            params.extend(p for p in block.get_params() if p.get_type() == 
type)
+        return params
 
     def is_enum(self):
         return self._type == 'enum'
diff --git a/grc/core/ParseXML.py b/grc/core/ParseXML.py
index c9f6541..d1306fc 100644
--- a/grc/core/ParseXML.py
+++ b/grc/core/ParseXML.py
@@ -17,8 +17,13 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 from lxml import etree
 
+import six
+from six.moves import map
+
 from .utils import odict
 
 xml_failures = {}
@@ -80,7 +85,9 @@ def from_file(xml_file):
     # Get the embedded instructions and build a dictionary item
     nested_data['_instructions'] = {}
     xml_instructions = xml.xpath('/processing-instruction()')
-    for inst in filter(lambda i: i.target == 'grc', xml_instructions):
+    for inst in xml_instructions:
+        if inst.target != 'grc':
+            continue
         nested_data['_instructions'] = odict(inst.attrib)
     return nested_data
 
@@ -100,13 +107,13 @@ def _from_file(xml):
         return odict({tag: xml.text or ''})  # store empty tags (text is None) 
as empty string
     nested_data = odict()
     for elem in xml:
-        key, value = _from_file(elem).items()[0]
+        key, value = list(_from_file(elem).items())[0]
         if key in nested_data:
             nested_data[key].append(value)
         else:
             nested_data[key] = [value]
     # Delistify if the length of values is 1
-    for key, values in nested_data.iteritems():
+    for key, values in six.iteritems(nested_data):
         if len(values) == 1:
             nested_data[key] = values[0]
 
@@ -127,7 +134,7 @@ def to_file(nested_data, xml_file):
     if instructions:
         xml_data += etree.tostring(etree.ProcessingInstruction(
             'grc', ' '.join(
-                "{0}='{1}'".format(*item) for item in instructions.iteritems())
+                "{0}='{1}'".format(*item) for item in 
six.iteritems(instructions))
         ), xml_declaration=True, pretty_print=True, encoding='utf-8')
     xml_data += etree.tostring(_to_file(nested_data)[0],
                                pretty_print=True, encoding='utf-8')
@@ -146,14 +153,14 @@ def _to_file(nested_data):
         the xml tree filled with child nodes
     """
     nodes = list()
-    for key, values in nested_data.iteritems():
+    for key, values in six.iteritems(nested_data):
         # Listify the values if not a list
         if not isinstance(values, (list, set, tuple)):
             values = [values]
         for value in values:
             node = etree.Element(key)
-            if isinstance(value, (str, unicode)):
-                node.text = unicode(value)
+            if isinstance(value, (str, six.text_type)):
+                node.text = six.text_type(value)
             else:
                 node.extend(_to_file(value))
             nodes.append(node)
diff --git a/grc/core/Platform.py b/grc/core/Platform.py
index 02a625b..25f4156 100644
--- a/grc/core/Platform.py
+++ b/grc/core/Platform.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+from __future__ import print_function
 import os
 import sys
 
@@ -32,6 +34,9 @@ from .Port import Port
 from .Param import Param
 
 from .utils import odict, extract_docs
+import six
+from six.moves import map
+from six.moves import range
 
 
 class Platform(Element):
@@ -156,7 +161,7 @@ class Platform(Element):
                 # print >> sys.stderr, 'Warning: Block validation 
failed:\n\t%s\n\tIgnoring: %s' % (e, xml_file)
                 pass
             except Exception as e:
-                print >> sys.stderr, 'Warning: XML parsing 
failed:\n\t%r\n\tIgnoring: %s' % (e, xml_file)
+                print('Warning: XML parsing failed:\n\t%r\n\tIgnoring: %s' % 
(e, xml_file), file=sys.stderr)
 
         self._docstring_extractor.finish()
         # self._docstring_extractor.wait()
@@ -168,7 +173,7 @@ class Platform(Element):
                 yield block_path
             elif os.path.isdir(block_path):
                 for dirpath, dirnames, filenames in os.walk(block_path):
-                    for filename in sorted(filter(lambda f: 
f.endswith('.xml'), filenames)):
+                    for filename in sorted(f for f in filenames if 
f.endswith('.xml')):
                         yield os.path.join(dirpath, filename)
 
     def load_block_xml(self, xml_file):
@@ -181,7 +186,7 @@ class Platform(Element):
         block = self.Block(self._flow_graph, n)
         key = block.get_key()
         if key in self.blocks:
-            print >> sys.stderr, 'Warning: Block with key "{}" already 
exists.\n\tIgnoring: {}'.format(key, xml_file)
+            print('Warning: Block with key "{}" already exists.\n\tIgnoring: 
{}'.format(key, xml_file), file=sys.stderr)
         else:  # Store the block
             self.blocks[key] = block
             self._blocks_n[key] = n
@@ -205,13 +210,13 @@ class Platform(Element):
 
         key = n.find('key')
         if not key:
-            print >> sys.stderr, 'Warning: Domain with emtpy key.\n\tIgnoring: 
{}'.format(xml_file)
+            print('Warning: Domain with emtpy key.\n\tIgnoring: 
{}'.format(xml_file), file=sys.stderr)
             return
         if key in self.domains:  # test against repeated keys
-            print >> sys.stderr, 'Warning: Domain with key "{}" already 
exists.\n\tIgnoring: {}'.format(key, xml_file)
+            print('Warning: Domain with key "{}" already exists.\n\tIgnoring: 
{}'.format(key, xml_file), file=sys.stderr)
             return
 
-        #to_bool = lambda s, d: d if s is None else s.lower() not in ('false', 
'off', '0', '')
+        # to_bool = lambda s, d: d if s is None else s.lower() not in 
('false', 'off', '0', '')
         def to_bool(s, d):
             if s is not None:
                 return s.lower() not in ('false', 'off', '0', '')
@@ -223,7 +228,7 @@ class Platform(Element):
             tuple(int(color[o:o + 2], 16) / 255.0 for o in range(1, 3 * 
chars_per_color, chars_per_color))
         except ValueError:
             if color:  # no color is okay, default set in GUI
-                print >> sys.stderr, 'Warning: Can\'t parse color code "{}" 
for domain "{}" '.format(color, key)
+                print('Warning: Can\'t parse color code "{}" for domain "{}" 
'.format(color, key), file=sys.stderr)
                 color = None
 
         self.domains[key] = dict(
@@ -235,9 +240,9 @@ class Platform(Element):
         for connection_n in n.findall('connection'):
             key = (connection_n.find('source_domain'), 
connection_n.find('sink_domain'))
             if not all(key):
-                print >> sys.stderr, 'Warning: Empty domain key(s) in 
connection template.\n\t{}'.format(xml_file)
+                print('Warning: Empty domain key(s) in connection 
template.\n\t{}'.format(xml_file), file=sys.stderr)
             elif key in self.connection_templates:
-                print >> sys.stderr, 'Warning: Connection template "{}" 
already exists.\n\t{}'.format(key, xml_file)
+                print('Warning: Connection template "{}" already 
exists.\n\t{}'.format(key, xml_file), file=sys.stderr)
             else:
                 self.connection_templates[key] = connection_n.find('make') or 
''
 
@@ -256,11 +261,12 @@ class Platform(Element):
             parent = (parent or []) + [cat_n.find('name')]
             block_tree.add_block(parent)
             # Recursive call to load sub categories
-            map(lambda c: load_category(c, parent), cat_n.findall('cat'))
+            for cat in cat_n.findall('cat'):
+                load_category(cat, parent)
             # Add blocks in this category
             for block_key in cat_n.findall('block'):
                 if block_key not in self.blocks:
-                    print >> sys.stderr, 'Warning: Block key "{}" not found 
when loading category tree.'.format(block_key)
+                    print('Warning: Block key "{}" not found when loading 
category tree.'.format(block_key), file=sys.stderr)
                     continue
                 block = self.blocks[block_key]
                 # If it exists, the block's category shall not be overridden 
by the xml tree
@@ -272,7 +278,7 @@ class Platform(Element):
             load_category(category_tree_n)
 
         # Add blocks to block tree
-        for block in self.blocks.itervalues():
+        for block in six.itervalues(self.blocks):
             # Blocks with empty categories are hidden
             if not block.get_category():
                 continue
@@ -280,7 +286,7 @@ class Platform(Element):
 
     def _save_docstring_extraction_result(self, key, docstrings):
         docs = {}
-        for match, docstring in docstrings.iteritems():
+        for match, docstring in six.iteritems(docstrings):
             if not docstring or match.endswith('_sptr'):
                 continue
             docstring = docstring.replace('\n\n', '\n').strip()
@@ -312,7 +318,7 @@ class Platform(Element):
         return self.FlowGraph(platform=self)
 
     def get_blocks(self):
-        return self.blocks.values()
+        return list(self.blocks.values())
 
     def get_new_block(self, flow_graph, key):
         return self.Block(flow_graph, n=self._blocks_n[key])
diff --git a/grc/core/Port.py b/grc/core/Port.py
index 6a8f484..a24262d 100644
--- a/grc/core/Port.py
+++ b/grc/core/Port.py
@@ -17,7 +17,10 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-from .Constants import DEFAULT_DOMAIN, GR_STREAM_DOMAIN, GR_MESSAGE_DOMAIN
+from __future__ import absolute_import
+
+from six.moves import filter
+
 from .Element import Element
 
 from . import Constants
@@ -47,13 +50,13 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]):
     try:
         return _get_source_from_virtual_source_port(
             _get_source_from_virtual_sink_port(
-                filter(  # Get all virtual sinks with a matching stream id
+                list(filter(  # Get all virtual sinks with a matching stream id
                     lambda vs: vs.get_param('stream_id').get_value() == 
vsp.get_parent().get_param('stream_id').get_value(),
-                    filter(  # Get all enabled blocks that are also virtual 
sinks
+                    list(filter(  # Get all enabled blocks that are also 
virtual sinks
                         lambda b: b.is_virtual_sink(),
                         vsp.get_parent().get_parent().get_enabled_blocks(),
-                    ),
-                )[0].get_sinks()[0]
+                    )),
+                ))[0].get_sinks()[0]
             ), traversed + [vsp],
         )
     except:
@@ -87,10 +90,10 @@ def _get_sink_from_virtual_sink_port(vsp, traversed=[]):
             _get_sink_from_virtual_source_port(
                 filter(  # Get all virtual source with a matching stream id
                     lambda vs: vs.get_param('stream_id').get_value() == 
vsp.get_parent().get_param('stream_id').get_value(),
-                    filter(  # Get all enabled blocks that are also virtual 
sinks
+                    list(filter(  # Get all enabled blocks that are also 
virtual sinks
                         lambda b: b.is_virtual_source(),
                         vsp.get_parent().get_parent().get_enabled_blocks(),
-                    ),
+                    )),
                 )[0].get_sources()[0]
             ), traversed + [vsp],
         )
@@ -113,10 +116,10 @@ class Port(Element):
         """
         self._n = n
         if n['type'] == 'message':
-            n['domain'] = GR_MESSAGE_DOMAIN
+            n['domain'] = Constants.GR_MESSAGE_DOMAIN
         if 'domain' not in n:
-            n['domain'] = DEFAULT_DOMAIN
-        elif n['domain'] == GR_MESSAGE_DOMAIN:
+            n['domain'] = Constants.DEFAULT_DOMAIN
+        elif n['domain'] == Constants.GR_MESSAGE_DOMAIN:
             n['key'] = n['name']
             n['type'] = 'message'  # For port color
         if n['type'] == 'msg':
@@ -147,7 +150,7 @@ class Port(Element):
             return 'Sink - {}({})'.format(self.get_name(), self.get_key())
 
     def get_types(self):
-        return Constants.TYPE_TO_SIZEOF.keys()
+        return list(Constants.TYPE_TO_SIZEOF.keys())
 
     def is_type_empty(self):
         return not self._n['type']
@@ -189,11 +192,11 @@ class Port(Element):
 
         # Update domain if was deduced from (dynamic) port type
         type_ = self.get_type()
-        if self._domain == GR_STREAM_DOMAIN and type_ == "message":
-            self._domain = GR_MESSAGE_DOMAIN
+        if self._domain == Constants.GR_STREAM_DOMAIN and type_ == "message":
+            self._domain = Constants.GR_MESSAGE_DOMAIN
             self._key = self._name
-        if self._domain == GR_MESSAGE_DOMAIN and type_ != "message":
-            self._domain = GR_STREAM_DOMAIN
+        if self._domain == Constants.GR_MESSAGE_DOMAIN and type_ != "message":
+            self._domain = Constants.GR_STREAM_DOMAIN
             self._key = '0'  # Is rectified in rewrite()
 
     def resolve_virtual_source(self):
@@ -341,7 +344,7 @@ class Port(Element):
     def get_name(self):
         number = ''
         if self.get_type() == 'bus':
-            busses = filter(lambda a: a._dir == self._dir, 
self.get_parent().get_ports_gui())
+            busses = [a for a in self.get_parent().get_ports_gui() if a._dir 
== self._dir]
             number = str(busses.index(self)) + '#' + 
str(len(self.get_associated_ports()))
         return self._name + number
 
@@ -373,7 +376,7 @@ class Port(Element):
             a list of connection objects
         """
         connections = self.get_parent().get_parent().connections
-        connections = filter(lambda c: c.get_source() is self or c.get_sink() 
is self, connections)
+        connections = [c for c in connections if c.get_source() is self or 
c.get_sink() is self]
         return connections
 
     def get_enabled_connections(self):
@@ -383,7 +386,7 @@ class Port(Element):
         Returns:
             a list of connection objects
         """
-        return filter(lambda c: c.get_enabled(), self.get_connections())
+        return [c for c in self.get_connections() if c.get_enabled()]
 
     def get_associated_ports(self):
         if not self.get_type() == 'bus':
@@ -400,5 +403,5 @@ class Port(Element):
             if bus_structure:
                 busses = [i for i in get_ports() if i.get_type() == 'bus']
                 bus_index = busses.index(self)
-                ports = filter(lambda a: ports.index(a) in 
bus_structure[bus_index], ports)
+                ports = [a for a in ports if ports.index(a) in 
bus_structure[bus_index]]
             return ports
diff --git a/grc/core/generator/FlowGraphProxy.py 
b/grc/core/generator/FlowGraphProxy.py
index 3723005..c673c5b 100644
--- a/grc/core/generator/FlowGraphProxy.py
+++ b/grc/core/generator/FlowGraphProxy.py
@@ -16,6 +16,10 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
 
+from __future__ import absolute_import
+from six.moves import range
+
+
 class FlowGraphProxy(object):
 
     def __init__(self, fg):
@@ -34,7 +38,7 @@ class FlowGraphProxy(object):
         Returns:
             a list of dicts with: type, label, vlen, size, optional
         """
-        return filter(lambda p: p['type'] != "message", 
self.get_hier_block_io(direction))
+        return [p for p in self.get_hier_block_io(direction) if p['type'] != 
"message"]
 
     def get_hier_block_message_io(self, direction):
         """
@@ -46,7 +50,7 @@ class FlowGraphProxy(object):
         Returns:
             a list of dicts with: type, label, vlen, size, optional
         """
-        return filter(lambda p: p['type'] == "message", 
self.get_hier_block_io(direction))
+        return [p for p in self.get_hier_block_io(direction) if p['type'] == 
"message"]
 
     def get_hier_block_io(self, direction):
         """
@@ -71,7 +75,7 @@ class FlowGraphProxy(object):
             }
             num_ports = pad.get_param('num_streams').get_evaluated()
             if num_ports > 1:
-                for i in xrange(num_ports):
+                for i in range(num_ports):
                     clone = master.copy()
                     clone['label'] += str(i)
                     ports.append(clone)
@@ -86,7 +90,7 @@ class FlowGraphProxy(object):
         Returns:
             a list of pad source blocks in this flow graph
         """
-        pads = filter(lambda b: b.get_key() == 'pad_source', 
self.get_enabled_blocks())
+        pads = [b for b in self.get_enabled_blocks() if b.get_key() == 
'pad_source']
         return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id()))
 
     def get_pad_sinks(self):
@@ -96,7 +100,7 @@ class FlowGraphProxy(object):
         Returns:
             a list of pad sink blocks in this flow graph
         """
-        pads = filter(lambda b: b.get_key() == 'pad_sink', 
self.get_enabled_blocks())
+        pads = [b for b in self.get_enabled_blocks() if b.get_key() == 
'pad_sink']
         return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id()))
 
     def get_pad_port_global_key(self, port):
@@ -123,4 +127,4 @@ class FlowGraphProxy(object):
                 # assuming we have either only sources or sinks
                 if not is_message_pad:
                     key_offset += len(pad.get_ports())
-        return -1
\ No newline at end of file
+        return -1
diff --git a/grc/core/generator/Generator.py b/grc/core/generator/Generator.py
index 0d0ca6f..c9b0653 100644
--- a/grc/core/generator/Generator.py
+++ b/grc/core/generator/Generator.py
@@ -16,9 +16,11 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
 
+from __future__ import absolute_import
 import codecs
 import os
 import tempfile
+import operator
 
 from Cheetah.Template import Template
 
@@ -85,14 +87,15 @@ class TopBlockGenerator(object):
     def write(self):
         """generate output and write it to files"""
         # Do throttle warning
-        throttling_blocks = filter(lambda b: b.throtteling(), 
self._flow_graph.get_enabled_blocks())
+        throttling_blocks = [b for b in self._flow_graph.get_enabled_blocks()
+                             if b.throtteling()]
         if not throttling_blocks and not 
self._generate_options.startswith('hb'):
             Messages.send_warning("This flow graph may not have flow control: "
                                   "no audio or RF hardware blocks found. "
                                   "Add a Misc->Throttle block to your flow "
                                   "graph to avoid CPU congestion.")
         if len(throttling_blocks) > 1:
-            keys = set(map(lambda b: b.get_key(), throttling_blocks))
+            keys = set([b.get_key() for b in throttling_blocks])
             if len(keys) > 1 and 'blocks_throttle' in keys:
                 Messages.send_warning("This flow graph contains a throttle "
                                       "block and another rate limiting block, "
@@ -139,15 +142,15 @@ class TopBlockGenerator(object):
             return code
 
         blocks = expr_utils.sort_objects(
-            filter(lambda b: b.get_enabled() and not b.get_bypassed(), 
fg.blocks),
-            lambda b: b.get_id(), _get_block_sort_text
+            [b for b in fg.blocks if b.get_enabled() and not b.get_bypassed()],
+            operator.methodcaller('get_id'), _get_block_sort_text
         )
         deprecated_block_keys = set(block.get_name() for block in blocks if 
block.is_deprecated)
         for key in deprecated_block_keys:
             Messages.send_warning("The block {!r} is deprecated.".format(key))
 
         # List of regular blocks (all blocks minus the special ones)
-        blocks = filter(lambda b: b not in (imports + parameters), blocks)
+        blocks = [b for b in blocks if b not in imports and b not in 
parameters]
 
         for block in blocks:
             key = block.get_key()
@@ -162,10 +165,10 @@ class TopBlockGenerator(object):
         # Filter out virtual sink connections
         def cf(c):
             return not (c.is_bus() or c.is_msg() or 
c.get_sink().get_parent().is_virtual_sink())
-        connections = filter(cf, fg.get_enabled_connections())
+        connections = [con for con in fg.get_enabled_connections() if cf(con)]
 
         # Get the virtual blocks and resolve their connections
-        virtual = filter(lambda c: 
c.get_source().get_parent().is_virtual_source(), connections)
+        virtual = [c for c in connections if 
c.get_source().get_parent().is_virtual_source()]
         for connection in virtual:
             source = connection.get_source().resolve_virtual_source()
             sink = connection.get_sink()
@@ -183,7 +186,7 @@ class TopBlockGenerator(object):
         for block in bypassed_blocks:
             # Get the upstream connection (off of the sink ports)
             # Use *connections* not get_connections()
-            source_connection = filter(lambda c: c.get_sink() == 
block.get_sinks()[0], connections)
+            source_connection = [c for c in connections if c.get_sink() == 
block.get_sinks()[0]]
             # The source connection should never have more than one element.
             assert (len(source_connection) == 1)
 
@@ -191,7 +194,7 @@ class TopBlockGenerator(object):
             source_port = source_connection[0].get_source()
 
             # Loop through all the downstream connections
-            for sink in filter(lambda c: c.get_source() == 
block.get_sources()[0], connections):
+            for sink in (c for c in connections if c.get_source() == 
block.get_sources()[0]):
                 if not sink.get_enabled():
                     # Ignore disabled connections
                     continue
@@ -210,7 +213,8 @@ class TopBlockGenerator(object):
         ))
 
         connection_templates = fg.get_parent().connection_templates
-        msgs = filter(lambda c: c.is_msg(), fg.get_enabled_connections())
+        msgs = [c for c in fg.get_enabled_connections() if c.is_msg()]
+
         # List of variable names
         var_ids = [var.get_id() for var in parameters + variables]
         # Prepend self.
@@ -222,7 +226,7 @@ class TopBlockGenerator(object):
             ]
         # Map var id to callbacks
         var_id2cbs = dict([
-            (var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, 
[var_id]), callbacks))
+            (var_id, [c for c in callbacks if 
expr_utils.get_variable_dependencies(c, [var_id])])
             for var_id in var_ids
         ])
         # Load the namespace
@@ -290,8 +294,8 @@ class HierBlockGenerator(TopBlockGenerator):
         parameters = self._flow_graph.get_parameters()
 
         def var_or_value(name):
-            if name in map(lambda p: p.get_id(), parameters):
-                return "$"+name
+            if name in (p.get_id() for p in parameters):
+                return "$" + name
             return name
 
         # Build the nested data
diff --git a/grc/core/generator/__init__.py b/grc/core/generator/__init__.py
index f44b94a..98f410c 100644
--- a/grc/core/generator/__init__.py
+++ b/grc/core/generator/__init__.py
@@ -15,4 +15,5 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
-from Generator import Generator
+from __future__ import absolute_import
+from .Generator import Generator
diff --git a/grc/core/utils/__init__.py b/grc/core/utils/__init__.py
index 6b23da2..0d84f71 100644
--- a/grc/core/utils/__init__.py
+++ b/grc/core/utils/__init__.py
@@ -15,8 +15,10 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
-import expr_utils
-import epy_block_io
-import extract_docs
+from __future__ import absolute_import
 
-from odict import odict
+from . import expr_utils
+from . import epy_block_io
+from . import extract_docs
+
+from .odict import odict
diff --git a/grc/core/utils/complexity.py b/grc/core/utils/complexity.py
index baa8040..d72db9b 100644
--- a/grc/core/utils/complexity.py
+++ b/grc/core/utils/complexity.py
@@ -8,8 +8,8 @@ def calculate_flowgraph_complexity(flowgraph):
             continue
 
         # Don't worry about optional sinks?
-        sink_list = filter(lambda c: not c.get_optional(), block.get_sinks())
-        source_list = filter(lambda c: not c.get_optional(), 
block.get_sources())
+        sink_list = [c for c in block.get_sinks() if not c.get_optional()]
+        source_list = [c for c in block.get_sources() if not c.get_optional()]
         sinks = float(len(sink_list))
         sources = float(len(source_list))
         base = max(min(sinks, sources), 1)
@@ -22,14 +22,15 @@ def calculate_flowgraph_complexity(flowgraph):
             multi = 1
 
         # Connection ratio multiplier
-        sink_multi = max(float(sum(map(lambda c: len(c.get_connections()), 
sink_list)) / max(sinks, 1.0)), 1.0)
-        source_multi = max(float(sum(map(lambda c: len(c.get_connections()), 
source_list)) / max(sources, 1.0)), 1.0)
-        dbal = dbal + (base * multi * sink_multi * source_multi)
+        sink_multi = max(float(sum(len(c.get_connections()) for c in 
sink_list) / max(sinks, 1.0)), 1.0)
+        source_multi = max(float(sum(len(c.get_connections()) for c in 
source_list) / max(sources, 1.0)), 1.0)
+        dbal += base * multi * sink_multi * source_multi
 
     blocks = float(len(flowgraph.blocks))
     connections = float(len(flowgraph.connections))
     elements = blocks + connections
-    disabled_connections = len(filter(lambda c: not c.get_enabled(), 
flowgraph.connections))
+    disabled_connections = sum(not c.get_enabled() for c in 
flowgraph.connections)
+
     variables = elements - blocks - connections
     enabled = float(len(flowgraph.get_enabled_blocks()))
 
diff --git a/grc/core/utils/epy_block_io.py b/grc/core/utils/epy_block_io.py
index 76b5005..7a2006a 100644
--- a/grc/core/utils/epy_block_io.py
+++ b/grc/core/utils/epy_block_io.py
@@ -1,7 +1,12 @@
 
+from __future__ import absolute_import
+
 import inspect
 import collections
 
+import six
+from six.moves import zip
+
 
 TYPE_MAP = {
     'complex64': 'complex', 'complex': 'complex',
@@ -31,10 +36,10 @@ def _ports(sigs, msgs):
 def _find_block_class(source_code, cls):
     ns = {}
     try:
-        exec source_code in ns
+        exec(source_code, ns)
     except Exception as e:
         raise ValueError("Can't interpret source code: " + str(e))
-    for var in ns.itervalues():
+    for var in six.itervalues(ns):
         if inspect.isclass(var) and issubclass(var, cls):
             return var
     raise ValueError('No python block class found in code')
@@ -52,7 +57,7 @@ def extract(cls):
 
     spec = inspect.getargspec(cls.__init__)
     init_args = spec.args[1:]
-    defaults = map(repr, spec.defaults or ())
+    defaults = [repr(arg) for arg in (spec.defaults or ())]
     doc = cls.__doc__ or cls.__init__.__doc__ or ''
     cls_name = cls.__name__
 
diff --git a/grc/core/utils/expr_utils.py b/grc/core/utils/expr_utils.py
index 6691175..0577f06 100644
--- a/grc/core/utils/expr_utils.py
+++ b/grc/core/utils/expr_utils.py
@@ -17,7 +17,12 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import, print_function
+
 import string
+
+import six
+
 VAR_CHARS = string.letters + string.digits + '_'
 
 
@@ -50,7 +55,7 @@ class graph(object):
         self._graph[src_node_key].remove(dest_node_key)
 
     def get_nodes(self):
-        return self._graph.keys()
+        return list(self._graph.keys())
 
     def get_edges(self, node_key):
         return self._graph[node_key]
@@ -85,7 +90,7 @@ def expr_split(expr):
             toks.append(char)
             tok = ''
     toks.append(tok)
-    return filter(lambda t: t, toks)
+    return [t for t in toks if t]
 
 
 def expr_replace(expr, replace_dict):
@@ -101,7 +106,7 @@ def expr_replace(expr, replace_dict):
     """
     expr_splits = expr_split(expr)
     for i, es in enumerate(expr_splits):
-        if es in replace_dict.keys():
+        if es in list(replace_dict.keys()):
             expr_splits[i] = replace_dict[es]
     return ''.join(expr_splits)
 
@@ -118,7 +123,7 @@ def get_variable_dependencies(expr, vars):
         a subset of vars used in the expression
     """
     expr_toks = expr_split(expr)
-    return set(filter(lambda v: v in expr_toks, vars))
+    return set(v for v in vars if v in expr_toks)
 
 
 def get_graph(exprs):
@@ -131,12 +136,12 @@ def get_graph(exprs):
     Returns:
         a graph of variable deps
     """
-    vars = exprs.keys()
+    vars = list(exprs.keys())
     # Get dependencies for each expression, load into graph
     var_graph = graph()
     for var in vars:
         var_graph.add_node(var)
-    for var, expr in exprs.iteritems():
+    for var, expr in six.iteritems(exprs):
         for dep in get_variable_dependencies(expr, vars):
             if dep != var:
                 var_graph.add_edge(dep, var)
@@ -159,7 +164,7 @@ def sort_variables(exprs):
     # Determine dependency order
     while var_graph.get_nodes():
         # Get a list of nodes with no edges
-        indep_vars = filter(lambda var: not var_graph.get_edges(var), 
var_graph.get_nodes())
+        indep_vars = [var for var in var_graph.get_nodes() if not 
var_graph.get_edges(var)]
         if not indep_vars:
             raise Exception('circular dependency caught in sort_variables')
         # Add the indep vars to the end of the list
@@ -193,4 +198,4 @@ def sort_objects(objects, get_id, get_expr):
 
 if __name__ == '__main__':
     for i in sort_variables({'x': '1', 'y': 'x+1', 'a': 'x+y', 'b': 'y+1', 
'c': 'a+b+x+y'}):
-        print i
+        print(i)
diff --git a/grc/core/utils/extract_docs.py b/grc/core/utils/extract_docs.py
index a6e0bc9..cff8a81 100644
--- a/grc/core/utils/extract_docs.py
+++ b/grc/core/utils/extract_docs.py
@@ -17,15 +17,19 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import, print_function
+
 import sys
 import re
 import subprocess
 import threading
 import json
-import Queue
 import random
 import itertools
 
+import six
+from six.moves import queue, filter, range
+
 
 ###############################################################################
 # The docstring extraction
@@ -124,7 +128,7 @@ class SubprocessLoader(object):
         self.callback_query_result = callback_query_result
         self.callback_finished = callback_finished or (lambda: None)
 
-        self._queue = Queue.Queue()
+        self._queue = queue.Queue()
         self._thread = None
         self._worker = None
         self._shutdown = threading.Event()
@@ -157,14 +161,14 @@ class SubprocessLoader(object):
                 cmd, args = self._last_cmd
                 if cmd == 'query':
                     msg += " (crashed while loading {0!r})".format(args[0])
-                print >> sys.stderr, msg
+                print(msg, file=sys.stderr)
                 continue  # restart
             else:
                 break  # normal termination, return
             finally:
                 self._worker.terminate()
         else:
-            print >> sys.stderr, "Warning: docstring loader crashed too often"
+            print("Warning: docstring loader crashed too often", 
file=sys.stderr)
         self._thread = None
         self._worker = None
         self.callback_finished()
@@ -203,9 +207,9 @@ class SubprocessLoader(object):
             key, docs = args
             self.callback_query_result(key, docs)
         elif cmd == 'error':
-            print args
+            print(args)
         else:
-            print >> sys.stderr, "Unknown response:", cmd, args
+            print("Unknown response:", cmd, args, file=sys.stderr)
 
     def query(self, key, imports=None, make=None):
         """ Request docstring extraction for a certain key """
@@ -270,12 +274,12 @@ if __name__ == '__worker__':
 
 elif __name__ == '__main__':
     def callback(key, docs):
-        print key
-        for match, doc in docs.iteritems():
-            print '-->', match
-            print doc.strip()
-            print
-        print
+        print(key)
+        for match, doc in six.iteritems(docs):
+            print('-->', match)
+            print(doc.strip())
+            print()
+        print()
 
     r = SubprocessLoader(callback)
 
diff --git a/grc/core/utils/odict.py b/grc/core/utils/odict.py
index 20970e9..38f898a 100644
--- a/grc/core/utils/odict.py
+++ b/grc/core/utils/odict.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 from UserDict import DictMixin
 
 
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 492bf8d..9c3e924 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -18,6 +18,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 02110-1301, USA
 """
 
 
+from __future__ import absolute_import, print_function
+
 import os
 import subprocess
 
@@ -114,7 +116,7 @@ class ActionHandler:
         ##################################################
         if action == Actions.APPLICATION_INITIALIZE:
             if not self.init_file_paths:
-                self.init_file_paths = filter(os.path.exists, 
Preferences.get_open_files())
+                self.init_file_paths = list(filter(os.path.exists, 
Preferences.get_open_files()))
             if not self.init_file_paths: self.init_file_paths = ['']
             for file_path in self.init_file_paths:
                 if file_path: main.new_page(file_path) #load pages from file 
paths
@@ -603,7 +605,7 @@ class ActionHandler:
                 try:
                     page.process.kill()
                 except:
-                    print "could not kill process: %d" % page.process.pid
+                    print("could not kill process: %d" % page.process.pid)
         elif action == Actions.PAGE_CHANGE:  # pass and run the global actions
             pass
         elif action == Actions.RELOAD_BLOCKS:
@@ -645,7 +647,7 @@ class ActionHandler:
                              shell=True, stdout=subprocess.PIPE, 
stderr=subprocess.STDOUT)
 
         else:
-            print '!!! Action "%s" not handled !!!' % action
+            print('!!! Action "%s" not handled !!!' % action)
         ##################################################
         # Global Actions for all States
         ##################################################
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index d0e1142..3a51e80 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -17,13 +17,17 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
+import six
+
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
 from gi.repository import Gdk
 from gi.repository import GObject
 
-import Preferences
+from . import Preferences
 
 NO_MODS_MASK = 0
 
@@ -47,7 +51,6 @@ def handle_key_press(event):
     Returns:
         true if handled
     """
-    _used_mods_mask = reduce(lambda x, y: x | y, [mod_mask for keyval, 
mod_mask in _actions_keypress_dict], NO_MODS_MASK)
     # extract the key value and the consumed modifiers
     _unused, keyval, egroup, level, consumed = 
_keymap.translate_keyboard_state(
         event.hardware_keycode, event.get_state(), event.group)
@@ -80,13 +83,16 @@ class _ActionBase(object):
     Register actions and keypresses with this module.
     """
     def __init__(self, label, keypresses):
+        global _used_mods_mask
+
         _all_actions_list.append(self)
         for i in range(len(keypresses)/2):
             keyval, mod_mask = keypresses[i*2:(i+1)*2]
             # register this keypress
-            if _actions_keypress_dict.has_key((keyval, mod_mask)):
+            if (keyval, mod_mask) in _actions_keypress_dict:
                 raise KeyError('keyval/mod_mask pair already registered "%s"' 
% str((keyval, mod_mask)))
             _actions_keypress_dict[(keyval, mod_mask)] = self
+            _used_mods_mask |= mod_mask
             # set the accelerator group, and accelerator path
             # register the key name and mod mask with the accelerator path
             if label is None:
@@ -102,7 +108,7 @@ class _ActionBase(object):
         The string representation should be the name of the action id.
         Try to find the action id for this action by searching this module.
         """
-        for name, value in globals().iteritems():
+        for name, value in six.iteritems(globals()):
             if value == self:
                 return name
         return self.get_name()
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index c8631aa..0c18836 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
@@ -206,7 +207,7 @@ class SubMenuCreator(object):
 
     def _fill_flow_graph_recent_submenu(self, action):
         """menu showing recent flow-graphs"""
-        import Preferences
+        from . import Preferences
         menu = Gtk.Menu()
         recent_files = Preferences.get_recent_files()
         if len(recent_files) > 0:
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 1b90cf6..a6c31cd 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import math
 import gi
 gi.require_version('Gtk', '3.0')
@@ -150,7 +151,7 @@ class Block(Element, _Block):
         W = self.label_width + 2 * BLOCK_LABEL_PADDING
 
         def get_min_height_for_ports():
-            visible_ports = filter(lambda p: not p.get_hide(), ports)
+            visible_ports = [p for p in ports if not p.get_hide()]
             min_height = 2*PORT_BORDER_SEPARATION + len(visible_ports) * 
PORT_SEPARATION
             if visible_ports:
                 min_height -= ports[0].H
diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py
index 829ddfe..26086f5 100644
--- a/grc/gui/BlockTreeWindow.py
+++ b/grc/gui/BlockTreeWindow.py
@@ -17,6 +17,9 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+import six
+
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
@@ -33,7 +36,7 @@ def _format_doc(doc):
     docs = []
     if doc.get(''):
         docs += doc.pop('').splitlines() + ['']
-    for block_name, docstring in doc.iteritems():
+    for block_name, docstring in six.iteritems(doc):
         docs.append('--- {0} ---'.format(block_name))
         docs += docstring.splitlines()
         docs.append('')
@@ -142,8 +145,9 @@ class BlockTreeWindow(Gtk.VBox):
         if categories is None:
             categories = self._categories
 
-        if isinstance(category, (str, unicode)): category = category.split('/')
-        category = tuple(filter(lambda x: x, category))  # tuple is hashable
+        if isinstance(category, (str, six.text_type)):
+            category = category.split('/')
+        category = tuple(x for x in category if x)  # tuple is hashable
         # add category and all sub categories
         for i, cat_name in enumerate(category):
             sub_category = category[:i+1]
@@ -210,8 +214,8 @@ class BlockTreeWindow(Gtk.VBox):
             self.treeview.set_model(self.treestore)
             self.treeview.collapse_all()
         else:
-            matching_blocks = filter(lambda b: key in b.get_key().lower() or 
key in b.get_name().lower(),
-                                     self.platform.blocks.values())
+            matching_blocks = [b for b in list(self.platform.blocks.values())
+                               if key in b.get_key().lower() or key in 
b.get_name().lower()]
 
             self.treestore_search.clear()
             self._categories_search = {tuple(): None}
diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py
index a03a7bc..b2ed55b 100644
--- a/grc/gui/Colors.py
+++ b/grc/gui/Colors.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 
 
 def get_color(color_code):
diff --git a/grc/gui/Config.py b/grc/gui/Config.py
index 9b0c5d4..b6556ad 100644
--- a/grc/gui/Config.py
+++ b/grc/gui/Config.py
@@ -17,8 +17,11 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import, print_function
+
 import sys
 import os
+
 from ..core.Config import Config as _Config
 from . import Constants
 
@@ -57,7 +60,7 @@ class Config(_Config):
                 raise Exception()
             return value
         except:
-            print >> sys.stderr, "Error: invalid 'canvas_default_size' 
setting."
+            print("Error: invalid 'canvas_default_size' setting.", 
file=sys.stderr)
             return Constants.DEFAULT_CANVAS_SIZE_DEFAULT
 
     @property
@@ -69,6 +72,6 @@ class Config(_Config):
                 raise Exception()
         except:
             font_size = Constants.DEFAULT_FONT_SIZE
-            print >> sys.stderr, "Error: invalid 'canvas_font_size' setting."
+            print("Error: invalid 'canvas_font_size' setting.", 
file=sys.stderr)
 
         return font_size
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index 46414c9..8953ca0 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -17,16 +17,14 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-import gi
-gi.require_version('Gtk', '3.0')
-from gi.repository import Gtk
-from gi.repository import Gdk
+from __future__ import absolute_import
 
+from six.moves import map
 
-import Colors
-import Utils
-from Constants import CONNECTOR_ARROW_BASE, CONNECTOR_ARROW_HEIGHT
-from Element import Element
+from . import Colors
+from . import Utils
+from .Constants import CONNECTOR_ARROW_BASE, CONNECTOR_ARROW_HEIGHT
+from .Element import Element
 
 from ..core.Constants import GR_MESSAGE_DOMAIN
 from ..core.Connection import Connection as _Connection
@@ -130,7 +128,7 @@ class Connection(Element, _Connection):
             #points[0][0] -> source connector should not be in the direction 
of source
             if Utils.get_angle_from_coordinates(points[0][0], (x1, y1)) == 
source.get_connector_direction(): points.reverse()
             #create 3-line connector
-            p1, p2 = map(int, points[0][0]), map(int, points[0][1])
+            p1, p2 = list(map(int, points[0][0])), list(map(int, points[0][1]))
             self.add_line((x1, y1), p1)
             self.add_line(p1, p2)
             self.add_line((x2, y2), p2)
diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py
index 55739a7..8bb15ac 100644
--- a/grc/gui/Constants.py
+++ b/grc/gui/Constants.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
diff --git a/grc/gui/Dialogs.py b/grc/gui/Dialogs.py
index 953373e..8f0f60d 100644
--- a/grc/gui/Dialogs.py
+++ b/grc/gui/Dialogs.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
diff --git a/grc/gui/DrawingArea.py b/grc/gui/DrawingArea.py
index d1e0e78..33c669c 100644
--- a/grc/gui/DrawingArea.py
+++ b/grc/gui/DrawingArea.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 from gi.repository import Gtk, Gdk, GObject
 
 
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index 30c0f5d..4e88df3 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -17,10 +17,12 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-from Constants import LINE_SELECT_SENSITIVITY
-from Constants import POSSIBLE_ROTATIONS
+from __future__ import absolute_import
+from .Constants import LINE_SELECT_SENSITIVITY
+from .Constants import POSSIBLE_ROTATIONS
 
 import gi
+from six.moves import zip
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
 from gi.repository import Gdk
diff --git a/grc/gui/Executor.py b/grc/gui/Executor.py
index 13a1cfd..a8c6798 100644
--- a/grc/gui/Executor.py
+++ b/grc/gui/Executor.py
@@ -15,6 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
+from __future__ import absolute_import
 import os
 import threading
 import shlex
diff --git a/grc/gui/FileDialogs.py b/grc/gui/FileDialogs.py
index 63d4a39..3ee715d 100644
--- a/grc/gui/FileDialogs.py
+++ b/grc/gui/FileDialogs.py
@@ -17,18 +17,19 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
 from gi.repository import GObject
 
-from Dialogs import MessageDialogHelper
-from Constants import \
+from .Dialogs import MessageDialogHelper
+from .Constants import \
     DEFAULT_FILE_PATH, IMAGE_FILE_EXTENSION, TEXT_FILE_EXTENSION, \
     NEW_FLOGRAPH_TITLE
-import Preferences
+from . import Preferences
 from os import path
-import Utils
+from . import Utils
 
 ##################################################
 # Constants
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 802c54f..50e146b 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -17,16 +17,20 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 import functools
 import random
 from distutils.spawn import find_executable
 from itertools import chain, count
 from operator import methodcaller
 
+import six
+from six.moves import filter
+
 from gi.repository import GObject
 
-from . import Actions, Colors, Constants, Utils, Bars, Dialogs
-from .Constants import SCROLL_PROXIMITY_SENSITIVITY, SCROLL_DISTANCE
+from . import Actions, Colors, Utils, Bars, Dialogs
 from .Element import Element
 from .external_editor import ExternalEditor
 
@@ -179,10 +183,10 @@ class FlowGraph(Element, _Flowgraph):
             x_min = min(x, x_min)
             y_min = min(y, y_min)
         #get connections between selected blocks
-        connections = filter(
+        connections = list(filter(
             lambda c: c.get_source().get_parent() in blocks and 
c.get_sink().get_parent() in blocks,
             self.connections,
-        )
+        ))
         clipboard = (
             (x_min, y_min),
             [block.export_data() for block in blocks],
@@ -222,7 +226,7 @@ class FlowGraph(Element, _Flowgraph):
                 block.get_param('_io_cache').set_value(params.pop('_io_cache'))
                 
block.get_param('_source_code').set_value(params.pop('_source_code'))
                 block.rewrite()  # this creates the other params
-            for param_key, param_value in params.iteritems():
+            for param_key, param_value in six.iteritems(params):
                 #setup id parameter
                 if param_key == 'id':
                     old_id2block[param_value] = block
diff --git a/grc/gui/MainWindow.py b/grc/gui/MainWindow.py
index ce16074..3236768 100644
--- a/grc/gui/MainWindow.py
+++ b/grc/gui/MainWindow.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 import os
 
 import gi
@@ -270,7 +272,7 @@ class MainWindow(Gtk.Window):
         Returns:
             true if all closed
         """
-        open_files = filter(lambda file: file, self._get_files()) #filter 
blank files
+        open_files = [file for file in self._get_files() if file] #filter 
blank files
         open_file = self.current_page.file_path
         #close each page
         for page in sorted(self.get_pages(), key=lambda p: p.saved):
@@ -416,7 +418,7 @@ class MainWindow(Gtk.Window):
         Returns:
             list of file paths
         """
-        return map(lambda page: page.file_path, self.get_pages())
+        return [page.file_path for page in self.get_pages()]
 
     def get_pages(self):
         """
diff --git a/grc/gui/NotebookPage.py b/grc/gui/NotebookPage.py
index bcfb4d8..757dcbc 100644
--- a/grc/gui/NotebookPage.py
+++ b/grc/gui/NotebookPage.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import os
 
 from gi.repository import Gtk, Gdk, GObject
diff --git a/grc/gui/Param.py b/grc/gui/Param.py
index 0f88015..137c5e0 100644
--- a/grc/gui/Param.py
+++ b/grc/gui/Param.py
@@ -15,6 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
+from __future__ import absolute_import
 from . import Utils, Constants
 
 from . import ParamWidgets
diff --git a/grc/gui/ParamWidgets.py b/grc/gui/ParamWidgets.py
index 2fd6ccd..e0979e1 100644
--- a/grc/gui/ParamWidgets.py
+++ b/grc/gui/ParamWidgets.py
@@ -15,6 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
+from __future__ import absolute_import
 import os
 
 from gi.repository import Gtk, Gdk
diff --git a/grc/gui/ParserErrorsDialog.py b/grc/gui/ParserErrorsDialog.py
index f49e692..28cc8ec 100644
--- a/grc/gui/ParserErrorsDialog.py
+++ b/grc/gui/ParserErrorsDialog.py
@@ -17,12 +17,16 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
+import six
+
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import Gtk
 from gi.repository import GObject
 
-from Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT
+from .Constants import MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT
 
 
 class ParserErrorsDialog(Gtk.Dialog):
@@ -72,7 +76,7 @@ class ParserErrorsDialog(Gtk.Dialog):
         """set up data model"""
         self.tree_store.clear()
         self._error_logs = error_logs
-        for filename, errors in error_logs.iteritems():
+        for filename, errors in six.iteritems(error_logs):
             parent = self.tree_store.append(None, [str(filename)])
             try:
                 with open(filename, 'r') as fp:
diff --git a/grc/gui/Platform.py b/grc/gui/Platform.py
index 500df1c..997e96a 100644
--- a/grc/gui/Platform.py
+++ b/grc/gui/Platform.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import, print_function
+
 import os
 import sys
 
@@ -58,7 +60,7 @@ class Platform(Element, _Platform):
                 import shutil
                 shutil.move(old_gui_prefs_file, gui_prefs_file)
             except Exception as e:
-                print >> sys.stderr, e
+                print(e, file=sys.stderr)
 
     ##############################################
     # Constructors
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index fb1cd67..0fa3557 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 import math
 import gi
 gi.require_version('Gtk', '3.0')
@@ -68,7 +69,7 @@ class Port(_Port, Element):
         #get all sibling ports
         ports = self.get_parent().get_sources_gui() \
             if self.is_source else self.get_parent().get_sinks_gui()
-        ports = filter(lambda p: not p.get_hide(), ports)
+        ports = [p for p in ports if not p.get_hide()]
         #get the max width
         self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH])
         W = self.W if not self._label_hidden() else PORT_LABEL_HIDDEN_WIDTH
@@ -79,16 +80,15 @@ class Port(_Port, Element):
             if hasattr(self, '_connector_length'):
                 del self._connector_length
             return
-        length = len(filter(lambda p: not p.get_hide(), ports))
         #reverse the order of ports for these rotations
         if rotation in (180, 270):
-            index = length-index-1
+            index = len(ports)-index-1
 
         port_separation = PORT_SEPARATION \
             if not self.get_parent().has_busses[self.is_source] \
             else max([port.H for port in ports]) + PORT_SPACING
 
-        offset = (self.get_parent().H - (length-1)*port_separation - self.H)/2
+        offset = (self.get_parent().H - (len(ports)-1)*port_separation - 
self.H)/2
         #create areas and connector coordinates
         if (self.is_sink and rotation == 0) or (self.is_source and rotation == 
180):
             x = -W
diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py
index 5fbdfe9..8756a7a 100644
--- a/grc/gui/Preferences.py
+++ b/grc/gui/Preferences.py
@@ -17,9 +17,12 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import, print_function
+
 import os
 import sys
-import ConfigParser
+
+from six.moves import configparser
 
 
 HEADER = """\
@@ -31,7 +34,7 @@ HEADER = """\
 """
 
 _platform = None
-_config_parser = ConfigParser.SafeConfigParser()
+_config_parser = configparser.SafeConfigParser()
 
 
 def file_extension():
@@ -45,12 +48,12 @@ def load(platform):
     for section in ['main', 'files_open', 'files_recent']:
         try:
             _config_parser.add_section(section)
-        except Exception, e:
-             print e
+        except Exception as e:
+            print(e)
     try:
         _config_parser.read(_platform.get_prefs_file())
     except Exception as err:
-        print >> sys.stderr, err
+        print(err, file=sys.stderr)
 
 
 def save():
@@ -59,7 +62,7 @@ def save():
             fp.write(HEADER)
             _config_parser.write(fp)
     except Exception as err:
-        print >> sys.stderr, err
+        print(err, file=sys.stderr)
 
 
 def entry(key, value=None, default=None):
@@ -74,7 +77,7 @@ def entry(key, value=None, default=None):
         }.get(_type, _config_parser.get)
         try:
             result = getter('main', key)
-        except ConfigParser.Error:
+        except configparser.Error:
             result = _type() if default is None else default
     return result
 
@@ -106,7 +109,7 @@ def get_file_list(key):
     try:
         files = [value for name, value in _config_parser.items(key)
                  if name.startswith('%s_' % key)]
-    except ConfigParser.Error:
+    except configparser.Error:
         files = []
     return files
 
@@ -121,7 +124,7 @@ def set_open_files(files):
 
 def get_recent_files():
     """ Gets recent files, removes any that do not exist and re-saves it """
-    files = filter(os.path.exists, get_file_list('files_recent'))
+    files = list(filter(os.path.exists, get_file_list('files_recent')))
     set_recent_files(files)
     return files
 
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index d6b6494..f87ca6e 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -17,10 +17,12 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
 from gi.repository import Gtk, Gdk, GObject, Pango
 
 from . import Actions, Utils, Constants
 from .Dialogs import SimpleTextDisplay
+import six
 
 
 class PropsDialog(Gtk.Dialog):
@@ -160,7 +162,7 @@ class PropsDialog(Gtk.Dialog):
                     # child.destroy()   # disabled because it throw errors...
                 # repopulate the params box
                 box_all_valid = True
-                for param in filter(lambda p: p.get_tab_label() == tab, 
self._block.get_params()):
+                for param in [p for p in self._block.get_params() if 
p.get_tab_label() == tab]:
                     # fixme: why do we even rebuild instead of really hiding 
params?
                     if param.get_hide() == 'all':
                         continue
@@ -212,7 +214,7 @@ class PropsDialog(Gtk.Dialog):
             docstrings = {block_class: docstrings[block_class]}
 
         # show docstring(s) extracted from python sources
-        for cls_name, docstring in docstrings.iteritems():
+        for cls_name, docstring in six.iteritems(docstrings):
             buf.insert_with_tags_by_name(pos, cls_name + '\n', 'b')
             buf.insert(pos, docstring + '\n\n')
         pos.backward_chars(2)
diff --git a/grc/gui/StateCache.py b/grc/gui/StateCache.py
index 3cdb5f3..b109a12 100644
--- a/grc/gui/StateCache.py
+++ b/grc/gui/StateCache.py
@@ -17,8 +17,9 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-import Actions
-from Constants import STATE_CACHE_SIZE
+from __future__ import absolute_import
+from . import Actions
+from .Constants import STATE_CACHE_SIZE
 
 class StateCache(object):
     """
diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py
index 311b37f..e5d4cca 100644
--- a/grc/gui/Utils.py
+++ b/grc/gui/Utils.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import
+
 import gi
 gi.require_version('Gtk', '3.0')
 from gi.repository import GLib
@@ -47,7 +49,7 @@ def get_rotated_coordinate(coor, rotation):
     return x * cos_r + y * sin_r, -x * sin_r + y * cos_r
 
 
-def get_angle_from_coordinates((x1, y1), (x2, y2)):
+def get_angle_from_coordinates(p1, p2):
     """
     Given two points, calculate the vector direction from point1 to point2, 
directions are multiples of 90 degrees.
 
@@ -58,6 +60,8 @@ def get_angle_from_coordinates((x1, y1), (x2, y2)):
     Returns:
         the direction in degrees
     """
+    (x1, y1) = p1
+    (x2, y2) = p2
     if y1 == y2:  # 0 or 180
         return 0 if x2 > x1 else 180
     else:  # 90 or 270
@@ -78,7 +82,7 @@ def align_to_grid(coor, mode=round):
     def align(value):
         return int(mode(value / (1.0 * CANVAS_GRID_SIZE)) * CANVAS_GRID_SIZE)
     try:
-        return map(align, coor)
+        return [align(c) for c in coor]
     except TypeError:
         x = coor
         return align(coor)
diff --git a/grc/gui/VariableEditor.py b/grc/gui/VariableEditor.py
index d34903e..399e4ec 100644
--- a/grc/gui/VariableEditor.py
+++ b/grc/gui/VariableEditor.py
@@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-from operator import attrgetter
+from __future__ import absolute_import
 
 import gi
 gi.require_version('Gtk', '3.0')
@@ -221,8 +221,8 @@ class VariableEditor(Gtk.VBox):
                 sp('foreground', 'red')
 
     def update_gui(self, blocks):
-        self._imports = filter(attrgetter('is_import'), blocks)
-        self._variables = filter(attrgetter('is_variable'), blocks)
+        self._imports = [block for block in blocks if block.is_import]
+        self._variables = [block for block in blocks if block.is_variable]
         self._rebuild()
         self.treeview.expand_all()
 
diff --git a/grc/gui/external_editor.py b/grc/gui/external_editor.py
index 76f2141..11d6fd7 100644
--- a/grc/gui/external_editor.py
+++ b/grc/gui/external_editor.py
@@ -17,6 +17,8 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
+from __future__ import absolute_import, print_function
+
 import os
 import sys
 import time
@@ -71,7 +73,7 @@ class ExternalEditor(threading.Thread):
                 time.sleep(1)
 
         except Exception as e:
-            print >> sys.stderr, "file monitor crashed:", str(e)
+            print("file monitor crashed:", str(e), file=sys.stderr)
         else:
             # print "file monitor: done with", filename
             pass
@@ -79,7 +81,7 @@ class ExternalEditor(threading.Thread):
 
 if __name__ == '__main__':
     def p(data):
-        print data
+        print(data)
 
     e = ExternalEditor('/usr/bin/gedit', "test", "content", p)
     e.open_editor()
diff --git a/grc/main.py b/grc/main.py
index cd98637..810ac7c 100755
--- a/grc/main.py
+++ b/grc/main.py
@@ -15,6 +15,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
USA
 
+from __future__ import absolute_import
 import optparse
 
 import gi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]