def __init__(self, pyslosl, viewreg, name_override=None, **variable_initializations): ReflectiveObservable.__init__(self) self._slosl_statement = pyslosl self.parents = tuple( viewreg[parent] # raises KeyError for parent in pyslosl.parents ) self.name = name_override or pyslosl.name self._viewreg = viewreg self._attribute_dependencies = pyslosl.attribute_dependencies self._variables = variables = {} _globals = globals() _locals = {} for var_name, var_value in pyslosl.withs: variables[var_name] = eval(var_value, _globals, _locals) ranked = pyslosl.ranked function_name = ranked.function or None if function_name in VIEW_FUNCTIONS.VALID_FUNCTIONS: node_selector = getattr(VIEW_FUNCTIONS, function_name) self._node_ranker = node_selector(*ranked.parameters) else: self._node_ranker = None for var_name, value in variable_initializations.iteritems(): self._setVariable(var_name, value) # check attribute dependencies against parent # TODO: how to supply all parent attributes if the spec list is empty (i.e. unrestricted?) ## for parent in self.parents: ## if hasattr(parent, 'getNodeAttributes'): ## parent_attributes = parent.getNodeAttributes() ## for attr_dep in self._attribute_dependencies: ## if attr_dep.name not in parent_attributes: ## raise DependencyError(parent.name, attr_dep.name) # build class for view nodes self._node_class = self._build_node_class() self.distinct_selector = VIEW_FUNCTIONS._hash_distinct # populate view and register self._select_parent_nodes() viewreg.register(self)
def __init__(self, name, local_node, pyattributes, attribute_defaults=None): ReflectiveObservable.__init__(self) self.name = name self.local_node = local_node self.__identifiers = sorted( attribute.name for attribute in pyattributes.values() if attribute.identifier ) def node_identifier(node): return tuple(getattr(node, name) for name in self.__identifiers) self.node_identifier = node_identifier self.__orig_attributes = pyattributes self.__attributes = pyattributes self.__attribute_defaults = attribute_defaults or {} self.__nodes = {} self.__views = {} self.__logger = logging.getLogger('DB')