Merged grc developer branch r10679:10938
[debian/gnuradio] / grc / src / platforms / python / Port.py
index e75b47e4b07fdac566e6aee94b1778871c4c6ca8..b5bc9696b5a7e7d5cad1247346f1a6959f103be5 100644 (file)
@@ -1,5 +1,5 @@
 """
-Copyright 2008 Free Software Foundation, Inc.
+Copyright 2008, 2009 Free Software Foundation, Inc.
 This file is part of GNU Radio
 
 GNU Radio Companion is free software; you can redistribute it and/or
@@ -18,7 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
 from .. base.Port import Port as _Port
-from ... import utils
 import Constants
 
 class Port(_Port):
@@ -33,9 +32,9 @@ class Port(_Port):
                @param n the nested odict
                @return a new port
                """
-               vlen = utils.exists_or_else(n, 'vlen', '1')
-               nports = utils.exists_or_else(n, 'nports', '')
-               optional = utils.exists_or_else(n, 'optional', '')
+               vlen = n.find('vlen') or '1'
+               nports = n.find('nports') or ''
+               optional = n.find('optional') or ''
                #build the port
                _Port.__init__(
                        self,
@@ -46,6 +45,13 @@ class Port(_Port):
                self._vlen = vlen
                self._optional = bool(optional)
 
+       def validate(self):
+               _Port.validate(self)
+               try: assert(self.get_enabled_connections() or self.get_optional())
+               except AssertionError: self._add_error_message('Port is not connected.')
+               try: assert(self.is_source() or len(self.get_enabled_connections()) <= 1)
+               except AssertionError: self._add_error_message('Port has too many connections.')
+
        def get_vlen(self):
                """
                Get the vector length.
@@ -98,15 +104,6 @@ class Port(_Port):
                        }[self.get_type()]
                except: return _Port.get_color(self)
 
-       def is_empty(self):
-               """
-               Is this port empty?
-               An empty port has no connections.
-               Not empty of optional is set.
-               @return true if empty
-               """
-               return not self.get_optional() and not self.get_connections()
-
 class Source(Port):
 
        def __init__(self, block, n):