summaryrefslogtreecommitdiff
path: root/grc/base
diff options
context:
space:
mode:
Diffstat (limited to 'grc/base')
-rw-r--r--grc/base/Block.py14
-rw-r--r--grc/base/Connection.py12
-rw-r--r--grc/base/FlowGraph.py20
-rw-r--r--grc/base/Param.py30
-rw-r--r--grc/base/Platform.py21
-rw-r--r--grc/base/Port.py6
-rw-r--r--grc/base/odict.py8
7 files changed, 55 insertions, 56 deletions
diff --git a/grc/base/Block.py b/grc/base/Block.py
index 42eb6b3fb..fe7ad3c2f 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -92,8 +92,8 @@ class Block(Element):
for param in map(lambda n: self.get_parent().get_parent().Param(block=self, n=n), params):
key = param.get_key()
#test against repeated keys
- try: assert key not in self.get_param_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in params'%key
+ if key in self.get_param_keys():
+ raise Exception, 'Key "%s" already exists in params'%key
#store the param
self.get_params().append(param)
#create the source objects
@@ -101,8 +101,8 @@ class Block(Element):
for source in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='source'), sources):
key = source.get_key()
#test against repeated keys
- try: assert key not in self.get_source_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in sources'%key
+ if key in self.get_source_keys():
+ raise Exception, 'Key "%s" already exists in sources'%key
#store the port
self.get_sources().append(source)
#create the sink objects
@@ -110,8 +110,8 @@ class Block(Element):
for sink in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='sink'), sinks):
key = sink.get_key()
#test against repeated keys
- try: assert key not in self.get_sink_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in sinks'%key
+ if key in self.get_sink_keys():
+ raise Exception, 'Key "%s" already exists in sinks'%key
#store the port
self.get_sinks().append(sink)
diff --git a/grc/base/Connection.py b/grc/base/Connection.py
index 94d4751b2..3ce7fd07f 100644
--- a/grc/base/Connection.py
+++ b/grc/base/Connection.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -37,10 +37,12 @@ class Connection(Element):
for port in (porta, portb):
if port.is_source(): source = port
if port.is_sink(): sink = port
- assert(source and sink)
+ if not source: raise ValueError('Connection could not isolate source')
+ if not sink: raise ValueError('Connection could not isolate sink')
#ensure that this connection (source -> sink) is unique
for connection in self.get_parent().get_connections():
- assert not (connection.get_source() is source and connection.get_sink() is sink)
+ if connection.get_source() is source and connection.get_sink() is sink:
+ raise Exception('This connection between source and sink is not unique.')
self._source = source
self._sink = sink
@@ -62,8 +64,8 @@ class Connection(Element):
Element.validate(self)
source_type = self.get_source().get_type()
sink_type = self.get_sink().get_type()
- try: assert source_type == sink_type
- except AssertionError: self.add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type))
+ if source_type != sink_type:
+ self.add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type))
def get_enabled(self):
"""
diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py
index b4ac8fc3a..0ba1f2389 100644
--- a/grc/base/FlowGraph.py
+++ b/grc/base/FlowGraph.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -194,18 +194,26 @@ class FlowGraph(Element):
sink_key = connection_n.find('sink_key')
#verify the blocks
block_ids = map(lambda b: b.get_id(), self.get_blocks())
- assert(source_block_id in block_ids)
- assert(sink_block_id in block_ids)
+ if source_block_id not in block_ids:
+ raise LookupError('source block id "%s" not in block ids'%source_block_id)
+ if sink_block_id not in block_ids:
+ raise LookupError('sink block id "%s" not in block ids'%sink_block_id)
#get the blocks
source_block = self.get_block(source_block_id)
sink_block = self.get_block(sink_block_id)
#verify the ports
- assert(source_key in source_block.get_source_keys())
- assert(sink_key in sink_block.get_sink_keys())
+ if source_key not in source_block.get_source_keys():
+ raise LookupError('source key "%s" not in source block keys'%source_key)
+ if sink_key not in sink_block.get_sink_keys():
+ raise LookupError('sink key "%s" not in sink block keys'%sink_key)
#get the ports
source = source_block.get_source(source_key)
sink = sink_block.get_sink(sink_key)
#build the connection
self.connect(source, sink)
- except AssertionError: Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be made.'%(source_block_id, source_key, sink_block_id, sink_key))
+ except LookupError, e: Messages.send_error_load(
+ 'Connection between %s(%s) and %s(%s) could not be made.\n\t%s'%(
+ source_block_id, source_key, sink_block_id, sink_key, e
+ )
+ )
self.rewrite() #global rewrite
diff --git a/grc/base/Param.py b/grc/base/Param.py
index 5cd0f9d6d..c2fa5461a 100644
--- a/grc/base/Param.py
+++ b/grc/base/Param.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -34,16 +34,16 @@ class Option(Element):
self._opts = dict()
opts = n.findall('opt')
#test against opts when non enum
- try: assert self.get_parent().is_enum() or not opts
- except AssertionError: raise Exception, 'Options for non-enum types cannot have sub-options'
+ if not self.get_parent().is_enum() and opts:
+ raise Exception, 'Options for non-enum types cannot have sub-options'
#extract opts
for opt in opts:
#separate the key:value
try: key, value = opt.split(':')
except: raise Exception, 'Error separating "%s" into key:value'%opt
#test against repeated keys
- try: assert not self._opts.has_key(key)
- except AssertionError: raise Exception, 'Key "%s" already exists in option'%key
+ if self._opts.has_key(key):
+ raise Exception, 'Key "%s" already exists in option'%key
#store the option
self._opts[key] = value
@@ -79,24 +79,24 @@ class Param(Element):
for option in map(lambda o: Option(param=self, n=o), n.findall('option')):
key = option.get_key()
#test against repeated keys
- try: assert key not in self.get_option_keys()
- except AssertionError: raise Exception, 'Key "%s" already exists in options'%key
+ if key in self.get_option_keys():
+ raise Exception, 'Key "%s" already exists in options'%key
#store the option
self.get_options().append(option)
#test the enum options
if self.is_enum():
#test against options with identical keys
- try: assert len(set(self.get_option_keys())) == len(self.get_options())
- except AssertionError: raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
+ if len(set(self.get_option_keys())) != len(self.get_options()):
+ raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys()
#test against inconsistent keys in options
opt_keys = self.get_options()[0].get_opt_keys()
for option in self.get_options():
- try: assert set(opt_keys) == set(option.get_opt_keys())
- except AssertionError: raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
+ if set(opt_keys) != set(option.get_opt_keys()):
+ raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys
#if a value is specified, it must be in the options keys
self._value = value if value or value in self.get_option_keys() else self.get_option_keys()[0]
- try: assert self.get_value() in self.get_option_keys()
- except AssertionError: raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
+ if self.get_value() not in self.get_option_keys():
+ raise Exception, 'The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys())
else: self._value = value or ''
def validate(self):
@@ -105,8 +105,8 @@ class Param(Element):
The value must be evaluated and type must a possible type.
"""
Element.validate(self)
- try: assert self.get_type() in self.get_types()
- except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
+ if self.get_type() not in self.get_types():
+ self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
def get_evaluated(self): raise NotImplementedError
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 096fdec41..a66c28ab9 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009, 2011 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -17,16 +17,6 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-#Perform python integrity checks:
-# GRC will not work with interpreters that fail the checks below.
-# This can fail on interpreters built with special optimizations.
-try:
- assert False
- raise Exception, 'Failed python integrity check: assert not supported'
-except AssertionError: pass
-if __doc__ is None:
- raise Exception, 'Failed python integrity check: __doc__ not supported'
-
import os
import sys
from .. base import ParseXML, odict
@@ -91,13 +81,12 @@ class Platform(_Element):
block = self.Block(self._flow_graph, n)
key = block.get_key()
#test against repeated keys
- try:
- assert key not in self.get_block_keys()
- #store the block
+ if key in self.get_block_keys():
+ print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s'%(key, xml_file)
+ #store the block
+ else:
self._blocks[key] = block
self._blocks_n[key] = n
- except AssertionError:
- print >> sys.stderr, 'Warning: Block with key "%s" already exists.\n\tIgnoring: %s'%(key, xml_file)
except ParseXML.XMLSyntaxError, e:
try: #try to add the xml file as a block tree
ParseXML.validate_dtd(xml_file, BLOCK_TREE_DTD)
diff --git a/grc/base/Port.py b/grc/base/Port.py
index 494ea894f..7a1b5d4e6 100644
--- a/grc/base/Port.py
+++ b/grc/base/Port.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -42,8 +42,8 @@ class Port(Element):
The port must be non-empty and type must a possible type.
"""
Element.validate(self)
- try: assert self.get_type() in self.get_types()
- except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
+ if self.get_type() not in self.get_types():
+ self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
def __str__(self):
if self.is_source():
diff --git a/grc/base/odict.py b/grc/base/odict.py
index ac3cb2070..044d04ad7 100644
--- a/grc/base/odict.py
+++ b/grc/base/odict.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -55,7 +55,7 @@ class odict(DictMixin):
@param val the value for the new entry
"""
index = (pos_key is None) and len(self._keys) or self._keys.index(pos_key)
- assert key not in self._keys
+ if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key))
self._keys.insert(index+1, key)
self._data[key] = val
@@ -67,8 +67,8 @@ class odict(DictMixin):
@param key the key for the new entry
@param val the value for the new entry
"""
- index = (pos_key is not None) and self._keys.index(pos_key) or 0
- assert key not in self._keys
+ index = (pos_key is not None) and self._keys.index(pos_key) or 0
+ if key in self._keys: raise KeyError('Cannot insert, key "%s" already exists'%str(key))
self._keys.insert(index, key)
self._data[key] = val