summaryrefslogtreecommitdiff
path: root/grc/core/Param.py
diff options
context:
space:
mode:
Diffstat (limited to 'grc/core/Param.py')
-rw-r--r--grc/core/Param.py64
1 files changed, 32 insertions, 32 deletions
diff --git a/grc/core/Param.py b/grc/core/Param.py
index 201032d010..26f9d2f451 100644
--- a/grc/core/Param.py
+++ b/grc/core/Param.py
@@ -49,14 +49,14 @@ def _get_elem(lst, key):
try:
return lst[_get_keys(lst).index(key)]
except ValueError:
- raise ValueError('Key "{}" not found in {}.'.format(key, _get_keys(lst)))
+ raise ValueError('Key "{0}" not found in {1}.'.format(key, _get_keys(lst)))
def num_to_str(num):
""" Display logic for numbers """
def eng_notation(value, fmt='g'):
"""Convert a number to a string in engineering notation. E.g., 5e-9 -> 5n"""
- template = '{:' + fmt + '}{}'
+ template = '{0:' + fmt + '}{1}'
magnitude = abs(value)
for exp, symbol in zip(range(9, -15-1, -3), 'GMk munpf'):
factor = 10 ** exp
@@ -92,15 +92,15 @@ class Option(Element):
try:
key, value = opt.split(':')
except:
- raise Exception('Error separating "{}" into key:value'.format(opt))
+ raise Exception('Error separating "{0}" into key:value'.format(opt))
# Test against repeated keys
if key in self._opts:
- raise Exception('Key "{}" already exists in option'.format(key))
+ raise Exception('Key "{0}" already exists in option'.format(key))
# Store the option
self._opts[key] = value
def __str__(self):
- return 'Option {}({})'.format(self.get_name(), self.get_key())
+ return 'Option {0}({1})'.format(self.get_name(), self.get_key())
def get_name(self):
return self._name
@@ -180,26 +180,26 @@ class Param(Element):
key = option.get_key()
# Test against repeated keys
if key in self.get_option_keys():
- raise Exception('Key "{}" already exists in options'.format(key))
+ raise Exception('Key "{0}" already exists in options'.format(key))
# Store the option
self.get_options().append(option)
# Test the enum options
if self.is_enum():
# Test against options with identical keys
if len(set(self.get_option_keys())) != len(self.get_options()):
- raise Exception('Options keys "{}" are not unique.'.format(self.get_option_keys()))
+ raise Exception('Options keys "{0}" are not unique.'.format(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():
if set(opt_keys) != set(option.get_opt_keys()):
- raise Exception('Opt keys "{}" are not identical across all options.'.format(opt_keys))
+ raise Exception('Opt keys "{0}" are not identical across all options.'.format(opt_keys))
# If a value is specified, it must be in the options keys
if value or value in self.get_option_keys():
self._value = value
else:
self._value = self.get_option_keys()[0]
if self.get_value() not in self.get_option_keys():
- raise Exception('The value "{}" is not in the possible values of "{}".'.format(self.get_value(), self.get_option_keys()))
+ raise Exception('The value "{0}" is not in the possible values of "{1}".'.format(self.get_value(), self.get_option_keys()))
else:
self._value = value or ''
self._default = value
@@ -290,7 +290,7 @@ class Param(Element):
return self.get_value()
def __str__(self):
- return 'Param - {}({})'.format(self.get_name(), self.get_key())
+ return 'Param - {0}({1})'.format(self.get_name(), self.get_key())
def get_color(self):
"""
@@ -366,7 +366,7 @@ class Param(Element):
"""
Element.validate(self)
if self.get_type() not in self.get_types():
- self.add_error_message('Type "{}" is not a possible type.'.format(self.get_type()))
+ self.add_error_message('Type "{0}" is not a possible type.'.format(self.get_type()))
self._evaluated = None
try:
@@ -405,30 +405,30 @@ class Param(Element):
try:
e = self.get_parent().get_parent().evaluate(v)
except Exception, e:
- raise Exception('Value "{}" cannot be evaluated:\n{}'.format(v, e))
+ raise Exception('Value "{0}" cannot be evaluated:\n{1}'.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):
- raise Exception('Expression "{}" is invalid for type complex.'.format(str(e)))
+ raise Exception('Expression "{0}" is invalid for type complex.'.format(str(e)))
return e
elif t == 'real' or t == 'float':
if not isinstance(e, REAL_TYPES):
- raise Exception('Expression "{}" is invalid for type float.'.format(str(e)))
+ raise Exception('Expression "{0}" is invalid for type float.'.format(str(e)))
return e
elif t == 'int':
if not isinstance(e, INT_TYPES):
- raise Exception('Expression "{}" is invalid for type integer.'.format(str(e)))
+ raise Exception('Expression "{0}" is invalid for type integer.'.format(str(e)))
return e
elif t == 'hex':
return hex(e)
elif t == 'bool':
if not isinstance(e, bool):
- raise Exception('Expression "{}" is invalid for type bool.'.format(str(e)))
+ raise Exception('Expression "{0}" is invalid for type bool.'.format(str(e)))
return e
else:
- raise TypeError('Type "{}" not handled'.format(t))
+ raise TypeError('Type "{0}" not handled'.format(t))
#########################
# Numeric Vector Types
#########################
@@ -440,28 +440,28 @@ class Param(Element):
try:
e = self.get_parent().get_parent().evaluate(v)
except Exception, e:
- raise Exception('Value "{}" cannot be evaluated:\n{}'.format(v, e))
+ raise Exception('Value "{0}" cannot be evaluated:\n{1}'.format(v, e))
# Raise an exception if the data is invalid
if t == 'complex_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
if not all([isinstance(ei, COMPLEX_TYPES) for ei in e]):
- raise Exception('Expression "{}" is invalid for type complex vector.'.format(str(e)))
+ raise Exception('Expression "{0}" 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):
self._lisitify_flag = True
e = [e]
if not all([isinstance(ei, REAL_TYPES) for ei in e]):
- raise Exception('Expression "{}" is invalid for type float vector.'.format(str(e)))
+ raise Exception('Expression "{0}" is invalid for type float vector.'.format(str(e)))
return e
elif t == 'int_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
if not all([isinstance(ei, INT_TYPES) for ei in e]):
- raise Exception('Expression "{}" is invalid for type integer vector.'.format(str(e)))
+ raise Exception('Expression "{0}" is invalid for type integer vector.'.format(str(e)))
return e
#########################
# String Types
@@ -484,14 +484,14 @@ class Param(Element):
elif t == 'id':
# Can python use this as a variable?
if not _check_id_matcher.match(v):
- raise Exception('ID "{}" must begin with a letter and may contain letters, numbers, and underscores.'.format(v))
+ raise Exception('ID "{0}" must begin with a letter and may contain letters, numbers, and underscores.'.format(v))
ids = [param.get_value() for param in self.get_all_params(t)]
# Id should only appear once, or zero times if block is disabled
if ids.count(v) > 1:
- raise Exception('ID "{}" is not unique.'.format(v))
+ raise Exception('ID "{0}" is not unique.'.format(v))
if v in ID_BLACKLIST:
- raise Exception('ID "{}" is blacklisted.'.format(v))
+ raise Exception('ID "{0}" is blacklisted.'.format(v))
return v
#########################
@@ -507,11 +507,11 @@ class Param(Element):
if self.get_parent().is_virtual_sink():
# Id should only appear once, or zero times if block is disabled
if ids.count(v) > 1:
- raise Exception('Stream ID "{}" is not unique.'.format(v))
+ raise Exception('Stream ID "{0}" is not unique.'.format(v))
# Check that the virtual source's steam id is found
if self.get_parent().is_virtual_source():
if v not in ids:
- raise Exception('Stream ID "{}" is not found.'.format(v))
+ raise Exception('Stream ID "{0}" is not found.'.format(v))
return v
#########################
@@ -581,7 +581,7 @@ class Param(Element):
for param in params:
for parent, cell in param._hostage_cells:
if (parent, cell) in self._hostage_cells:
- raise Exception('Another graphical element is using parent "{}", cell "{}".'.format(str(parent), str(cell)))
+ raise Exception('Another graphical element is using parent "{0}", cell "{1}".'.format(str(parent), str(cell)))
return e
#########################
# Notebook Page Type
@@ -602,11 +602,11 @@ class Param(Element):
try:
notebook_block = filter(lambda b: b.get_id() == notebook_id, notebook_blocks)[0]
except:
- raise Exception('Notebook id "{}" is not an existing notebook id.'.format(notebook_id))
+ raise Exception('Notebook id "{0}" is not an existing notebook id.'.format(notebook_id))
# Check that page index exists
if int(page_index) not in range(len(notebook_block.get_param('labels').evaluate())):
- raise Exception('Page index "{}" is not a valid index number.'.format(page_index))
+ raise Exception('Page index "{0}" is not a valid index number.'.format(page_index))
return notebook_id, page_index
#########################
@@ -618,14 +618,14 @@ class Param(Element):
try:
exec v in n
except ImportError:
- raise Exception('Import "{}" failed.'.format(v))
+ raise Exception('Import "{0}" failed.'.format(v))
except Exception:
- raise Exception('Bad import syntax: "{}".'.format(v))
+ raise Exception('Bad import syntax: "{0}".'.format(v))
return filter(lambda k: str(k) != '__builtins__', n.keys())
#########################
else:
- raise TypeError('Type "{}" not handled'.format(t))
+ raise TypeError('Type "{0}" not handled'.format(t))
def to_code(self):
"""