summaryrefslogtreecommitdiff
path: root/grc/core
diff options
context:
space:
mode:
authorVolker Schroer <3470424+dl1ksv@users.noreply.github.com>2021-04-11 15:05:42 +0200
committermormj <34754695+mormj@users.noreply.github.com>2021-04-15 15:00:24 -0400
commit035ed74a765180c1985035e1df428f81861b431c (patch)
treeadd1f3046d5bafa44c04764d228ecb10af71a697 /grc/core
parent67650b19d7c1462229f86627f7a58f51e344d42c (diff)
grc: update id blackist with imports
Signed-off-by: Volker Schroer <3470424+dl1ksv@users.noreply.github.com>
Diffstat (limited to 'grc/core')
-rw-r--r--grc/core/FlowGraph.py13
-rw-r--r--grc/core/params/dtypes.py17
-rw-r--r--grc/core/params/param.py2
3 files changed, 22 insertions, 10 deletions
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index 3b952428c4..84ca180861 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -44,6 +44,7 @@ class FlowGraph(Element):
self._eval_cache = {}
self.namespace = {}
+ self.imported_names = []
self.grc_file_path = ''
@@ -190,6 +191,16 @@ class FlowGraph(Element):
except Exception as e:
raise ValueError("Can't parse run command {!r}: {}".format(run_command, e))
+ def get_imported_names(self):
+ """
+ Get a lis of imported names.
+ These names may not be used as id's
+
+ Returns:
+ a list of imported names
+ """
+ return self.imported_names
+
##############################################
# Access Elements
##############################################
@@ -229,6 +240,8 @@ class FlowGraph(Element):
log.exception('Failed to evaluate import expression "{0}"'.format(expr), exc_info=True)
pass
+ self.imported_names = list(namespace.keys())
+
for id, expr in self.get_python_modules():
try:
module = types.ModuleType(id)
diff --git a/grc/core/params/dtypes.py b/grc/core/params/dtypes.py
index 8857ce075b..9426e4670f 100644
--- a/grc/core/params/dtypes.py
+++ b/grc/core/params/dtypes.py
@@ -13,7 +13,7 @@ from .. import Constants
# Blacklist certain ids, its not complete, but should help
-ID_BLACKLIST = ['self', 'options', 'gr', 'math', 'firdes', 'default'] + dir(builtins)
+ID_BLACKLIST = ['self', 'default'] + dir(builtins)
try:
from gnuradio import gr
ID_BLACKLIST.extend(attr for attr in dir(gr.top_block()) if not attr.startswith('_'))
@@ -32,19 +32,18 @@ def validates(*dtypes):
return func
return decorator
-
class ValidateError(Exception):
"""Raised by validate functions"""
@validates('id')
-def validate_block_id(param):
+def validate_block_id(param,black_listed_ids):
value = param.value
# Can python use this as a variable?
if not re.match(r'^[a-z|A-Z]\w*$', value):
raise ValidateError('ID "{}" must begin with a letter and may contain letters, numbers, '
'and underscores.'.format(value))
- if value in ID_BLACKLIST:
+ if value in (black_listed_ids + ID_BLACKLIST):
raise ValidateError('ID "{}" is blacklisted.'.format(value))
block_names = [block.name for block in param.parent_flowgraph.iter_enabled_blocks()]
# Id should only appear once, or zero times if block is disabled
@@ -56,7 +55,7 @@ def validate_block_id(param):
@validates('name')
-def validate_name(param):
+def validate_name(param,black_listed_ids):
# Name of a function or other block that will be generated literally not as a string
value = param.value
@@ -69,7 +68,7 @@ def validate_name(param):
@validates('stream_id')
-def validate_stream_id(param):
+def validate_stream_id(param,black_listed_ids):
value = param.value
stream_ids = [
block.params['stream_id'].value
@@ -86,7 +85,7 @@ def validate_stream_id(param):
@validates('complex', 'real', 'float', 'int')
-def validate_scalar(param):
+def validate_scalar(param,black_listed_ids):
valid_types = Constants.PARAM_TYPE_MAP[param.dtype]
if not isinstance(param.get_evaluated(), valid_types):
raise ValidateError('Expression {!r} is invalid for type {!r}.'.format(
@@ -94,7 +93,7 @@ def validate_scalar(param):
@validates('complex_vector', 'real_vector', 'float_vector', 'int_vector')
-def validate_vector(param):
+def validate_vector(param,black_listed_ids):
# todo: check vector types
if param.get_evaluated() is None:
@@ -106,7 +105,7 @@ def validate_vector(param):
param.get_evaluated(), param.dtype))
@validates('gui_hint')
-def validate_gui_hint(param):
+def validate_gui_hint(param,black_listed_ids):
try:
param.parse_gui_hint(param.value)
except Exception as e:
diff --git a/grc/core/params/param.py b/grc/core/params/param.py
index de370c9bff..fae008935e 100644
--- a/grc/core/params/param.py
+++ b/grc/core/params/param.py
@@ -156,7 +156,7 @@ class Param(Element):
validator = dtypes.validators.get(self.dtype, None)
if self._init and validator:
try:
- validator(self)
+ validator(self,self.parent_flowgraph.get_imported_names())
except dtypes.ValidateError as e:
self.add_error_message(str(e))