summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grc/base/Platform.py2
-rw-r--r--grc/python/Block.py13
-rw-r--r--grc/python/Connection.py6
-rw-r--r--grc/python/Param.py78
-rw-r--r--grc/python/Platform.py2
-rw-r--r--grc/python/Port.py21
-rw-r--r--grc/python/expr_utils.py6
-rw-r--r--grc/python/extract_docs.py6
8 files changed, 64 insertions, 70 deletions
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 0620cf21b..a6d420799 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
diff --git a/grc/python/Block.py b/grc/python/Block.py
index bd03eb5cd..14a5859e4 100644
--- a/grc/python/Block.py
+++ b/grc/python/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
@@ -65,9 +65,8 @@ class Block(_Block, _GUIBlock):
for check in self._checks:
check_res = self.resolve_dependencies(check)
try:
- check_eval = self.get_parent().evaluate(check_res)
- try: assert check_eval
- except AssertionError: self.add_error_message('Check "%s" failed.'%check)
+ if not self.get_parent().evaluate(check_res):
+ self.add_error_message('Check "%s" failed.'%check)
except: self.add_error_message('Check "%s" did not evaluate.'%check)
def rewrite(self):
@@ -134,9 +133,9 @@ class Block(_Block, _GUIBlock):
try:
value = param.get_evaluated()
value = value + direction
- assert 0 < value
- param.set_value(value)
- changed = True
+ if 0 < value:
+ param.set_value(value)
+ changed = True
except: pass
return changed
diff --git a/grc/python/Connection.py b/grc/python/Connection.py
index edc18841a..39f915740 100644
--- a/grc/python/Connection.py
+++ b/grc/python/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
@@ -38,5 +38,5 @@ class Connection(_Connection, _GUIConnection):
#check vector length
source_vlen = self.get_source().get_vlen()
sink_vlen = self.get_sink().get_vlen()
- try: assert source_vlen == sink_vlen
- except AssertionError: self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))
+ if source_vlen != sink_vlen:
+ self.add_error_message('Source vector length "%s" does not match sink vector length "%s".'%(source_vlen, sink_vlen))
diff --git a/grc/python/Param.py b/grc/python/Param.py
index 303ab3ed8..f62a33550 100644
--- a/grc/python/Param.py
+++ b/grc/python/Param.py
@@ -213,8 +213,7 @@ class Param(_Param, _GUIParam):
lambda p: p._vlen, self.get_parent().get_ports())
):
try:
- assert int(self.get_evaluated()) == 1
- return 'part'
+ if int(self.get_evaluated()) == 1: return 'part'
except: pass
#hide empty grid positions
if self.get_key() in ('grid_pos', 'notebook') and not self.get_value(): return 'part'
@@ -244,8 +243,7 @@ class Param(_Param, _GUIParam):
def eval_string(v):
try:
e = self.get_parent().get_parent().evaluate(v)
- assert isinstance(e, str)
- return e
+ if isinstance(e, str): return e
except:
self._stringify_flag = True
return v
@@ -265,21 +263,21 @@ class Param(_Param, _GUIParam):
#raise an exception if the data is invalid
if t == 'raw': return e
elif t == 'complex':
- try: assert isinstance(e, COMPLEX_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type complex.'%str(e)
+ if not isinstance(e, COMPLEX_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type complex.'%str(e)
return e
elif t == 'real':
- try: assert isinstance(e, REAL_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type real.'%str(e)
+ if not isinstance(e, REAL_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type real.'%str(e)
return e
elif t == 'int':
- try: assert isinstance(e, INT_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer.'%str(e)
+ if not isinstance(e, INT_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type integer.'%str(e)
return e
elif t == 'hex': return hex(e)
elif t == 'bool':
- try: assert isinstance(e, bool)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type bool.'%str(e)
+ if not isinstance(e, bool):
+ raise Exception, 'Expression "%s" is invalid for type bool.'%str(e)
return e
else: raise TypeError, 'Type "%s" not handled'%t
#########################
@@ -295,25 +293,25 @@ class Param(_Param, _GUIParam):
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
- try:
- for ei in e: assert isinstance(ei, COMPLEX_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type complex vector.'%str(e)
+ for ei in e:
+ if not isinstance(ei, COMPLEX_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type complex vector.'%str(e)
return e
elif t == 'real_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
- try:
- for ei in e: assert isinstance(ei, REAL_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type real vector.'%str(e)
+ for ei in e:
+ if not isinstance(ei, REAL_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type real vector.'%str(e)
return e
elif t == 'int_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
- try:
- for ei in e: assert isinstance(ei, INT_TYPES)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e)
+ for ei in e:
+ if not isinstance(ei, INT_TYPES):
+ raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e)
return e
#########################
# String Types
@@ -327,13 +325,13 @@ class Param(_Param, _GUIParam):
#########################
elif t == 'id':
#can python use this as a variable?
- try: assert _check_id_matcher.match(v)
- except AssertionError: raise Exception, 'ID "%s" must begin with a letter and may contain letters, numbers, and underscores.'%v
+ if not _check_id_matcher.match(v):
+ raise Exception, 'ID "%s" must begin with a letter and may contain letters, numbers, and underscores.'%v
ids = [param.get_value() for param in self.get_all_params(t)]
- try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled
- except: raise Exception, 'ID "%s" is not unique.'%v
- try: assert v not in ID_BLACKLIST
- except: raise Exception, 'ID "%s" is blacklisted.'%v
+ if ids.count(v) > 1: #id should only appear once, or zero times if block is disabled
+ raise Exception, 'ID "%s" is not unique.'%v
+ if v in ID_BLACKLIST:
+ raise Exception, 'ID "%s" is blacklisted.'%v
return v
#########################
# Stream ID Type
@@ -346,12 +344,12 @@ class Param(_Param, _GUIParam):
)]
#check that the virtual sink's stream id is unique
if self.get_parent().is_virtual_sink():
- try: assert ids.count(v) <= 1 #id should only appear once, or zero times if block is disabled
- except: raise Exception, 'Stream ID "%s" is not unique.'%v
+ if ids.count(v) > 1: #id should only appear once, or zero times if block is disabled
+ raise Exception, 'Stream ID "%s" is not unique.'%v
#check that the virtual source's steam id is found
if self.get_parent().is_virtual_source():
- try: assert v in ids
- except: raise Exception, 'Stream ID "%s" is not found.'%v
+ if v not in ids:
+ raise Exception, 'Stream ID "%s" is not found.'%v
return v
#########################
# GUI Position/Hint
@@ -382,17 +380,15 @@ class Param(_Param, _GUIParam):
elif t == 'grid_pos':
if not v: return '' #allow for empty grid pos
e = self.get_parent().get_parent().evaluate(v)
- try:
- assert isinstance(e, (list, tuple)) and len(e) == 4
- for ei in e: assert isinstance(ei, int)
- except AssertionError: raise Exception, 'A grid position must be a list of 4 integers.'
+ if not isinstance(e, (list, tuple)) or len(e) != 4 or not all([isinstance(ei, int) for ei in e]):
+ raise Exception, 'A grid position must be a list of 4 integers.'
row, col, row_span, col_span = e
#check row, col
- try: assert row >= 0 and col >= 0
- except AssertionError: raise Exception, 'Row and column must be non-negative.'
+ if row < 0 or col < 0:
+ raise Exception, 'Row and column must be non-negative.'
#check row span, col span
- try: assert row_span > 0 and col_span > 0
- except AssertionError: raise Exception, 'Row and column span must be greater than zero.'
+ if row_span <= 0 or col_span <= 0:
+ raise Exception, 'Row and column span must be greater than zero.'
#get hostage cell parent
try: my_parent = self.get_parent().get_param('notebook').evaluate()
except: my_parent = ''
@@ -421,8 +417,8 @@ class Param(_Param, _GUIParam):
try: notebook_block = filter(lambda b: b.get_id() == notebook_id, notebook_blocks)[0]
except: raise Exception, 'Notebook id "%s" is not an existing notebook id.'%notebook_id
#check that page index exists
- try: assert int(page_index) in range(len(notebook_block.get_param('labels').evaluate()))
- except: raise Exception, 'Page index "%s" is not a valid index number.'%page_index
+ if int(page_index) not in range(len(notebook_block.get_param('labels').evaluate())):
+ raise Exception, 'Page index "%s" is not a valid index number.'%page_index
return notebook_id, page_index
#########################
# Import Type
diff --git a/grc/python/Platform.py b/grc/python/Platform.py
index 54535965b..a9c2b18ad 100644
--- a/grc/python/Platform.py
+++ b/grc/python/Platform.py
@@ -1,5 +1,5 @@
__doc__ = """
-Copyright 2008, 2009, 2010, 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
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 6e5a5c59f..3846b0f4e 100644
--- a/grc/python/Port.py
+++ b/grc/python/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
@@ -83,16 +83,16 @@ class Port(_Port, _GUIPort):
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.')
+ if not self.get_enabled_connections() and not self.get_optional():
+ self.add_error_message('Port is not connected.')
+ if not self.is_source() and len(self.get_enabled_connections()) > 1:
+ self.add_error_message('Port has too many connections.')
#message port logic
if self.get_type() == 'msg':
- try: assert not self.get_nports()
- except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.')
- try: assert self.get_vlen() == 1
- except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.')
+ if self.get_nports():
+ self.add_error_message('A port of type "msg" cannot have "nports" set.')
+ if self.get_vlen() != 1:
+ self.add_error_message('A port of type "msg" must have a "vlen" of 1.')
def rewrite(self):
"""
@@ -134,8 +134,7 @@ class Port(_Port, _GUIPort):
if not nports: return ''
try:
nports = int(self.get_parent().get_parent().evaluate(nports))
- assert 0 < nports
- return nports
+ if 0 < nports: return nports
except: return 1
def get_optional(self): return bool(self._optional)
diff --git a/grc/python/expr_utils.py b/grc/python/expr_utils.py
index 3c39f5d89..a2e56eedf 100644
--- a/grc/python/expr_utils.py
+++ b/grc/python/expr_utils.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
@@ -118,7 +118,7 @@ def sort_variables(exprs):
Get a list of variables in order of dependencies.
@param exprs a mapping of variable name to expression
@return a list of variable names
- @throws AssertionError circular dependencies
+ @throws Exception circular dependencies
"""
var_graph = get_graph(exprs)
sorted_vars = list()
@@ -126,7 +126,7 @@ def sort_variables(exprs):
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())
- assert indep_vars
+ if not indep_vars: raise Exception('circular dependency caught in sort_variables')
#add the indep vars to the end of the list
sorted_vars.extend(sorted(indep_vars))
#remove each edge-less node from the graph
diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py
index f41f415b2..aa85397f9 100644
--- a/grc/python/extract_docs.py
+++ b/grc/python/extract_docs.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
@@ -81,8 +81,8 @@ def extract(key):
@param key the block key
@return a string with documentation
"""
- try: assert _docs_cache.has_key(key)
- except: _docs_cache[key] = _extract(key)
+ if not _docs_cache.has_key(key):
+ _docs_cache[key] = _extract(key)
return _docs_cache[key]
if __name__ == '__main__':