Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def newNodeHelper(self, description, title=None, position=None):
"""
Return a new initialized :class:`.SchemeNode`. If `title`
and `position` are not supplied they are initialized to sensible
defaults.
"""
if title is None:
title = self.enumerateTitle(description.name)
if position is None:
position = self.nextPosition()
return SchemeNode(description, title=title, position=position)
def scheme_node_from_element(node_el, registry):
"""
Create a SchemeNode from an `Element` instance.
"""
try:
widget_desc = registry.widget(node_el.get("qualified_name"))
except KeyError as ex:
raise UnknownWidgetDefinition(*ex.args)
title = node_el.get("title")
pos = node_el.get("position")
if pos is not None:
pos = tuple_eval(pos)
return SchemeNode(widget_desc, title=title, position=pos)
node_ids = defaultdict(inf_range().__next__)
builder.start("nodes", {})
for node in scheme.nodes:
desc = node.description
attrs = {
"id": str(node_ids[node]),
"name": desc.name,
"qualified_name": desc.qualified_name,
"project_name": desc.project_name or "",
"version": desc.version or "",
"title": node.title,
}
if node.position is not None:
attrs["position"] = str(node.position)
if type(node) is not SchemeNode:
attrs["scheme_node_type"] = "%s.%s" % (
type(node).__name__,
type(node).__module__,
)
builder.start("node", attrs)
builder.end("node")
builder.end("nodes")
## Links
link_ids = defaultdict(inf_range().__next__)
builder.start("links", {})
for link in scheme.links:
source = link.source_node
sink = link.sink_node
source_id = node_ids[source]
def copy_node(node):
x, y = node.position
return SchemeNode(
node.description,
node.title,
position=(x + 20, y + 20),
properties=copy.deepcopy(node.properties),
)
nodes = []
nodes_by_id = {}
links = []
annotations = []
scheme.title = desc.title
scheme.description = desc.description
for node_d in desc.nodes:
try:
w_desc = registry.widget(node_d.qualified_name)
except KeyError as ex:
error_handler(UnknownWidgetDefinition(*ex.args))
nodes_not_found.append(node_d.id)
else:
node = SchemeNode(w_desc, title=node_d.title, position=node_d.position)
data = node_d.data
if data:
try:
properties = loads(data.data, data.format)
except Exception:
log.error(
"Could not load properties for %r.", node.title, exc_info=True
)
else:
node.properties = properties
nodes.append(node)
nodes_by_id[node_d.id] = node
for link_d in desc.links:
nodes = []
links = []
for widget_el in etree.findall("widgets/widget"):
caption = widget_el.get("caption")
name = widget_el.get("widgetName")
x_pos = widget_el.get("xPos")
y_pos = widget_el.get("yPos")
if name in widgets_by_name:
desc = widgets_by_name[name]
else:
error_handler(UnknownWidgetDefinition(name))
widgets_not_found.append(caption)
continue
node = SchemeNode(desc, title=caption, position=(int(x_pos), int(y_pos)))
nodes_by_caption[caption] = node
nodes.append(node)
for channel_el in etree.findall("channels/channel"):
in_caption = channel_el.get("inWidgetCaption")
out_caption = channel_el.get("outWidgetCaption")
if in_caption in widgets_not_found or out_caption in widgets_not_found:
continue
source = nodes_by_caption[out_caption]
sink = nodes_by_caption[in_caption]
enabled = channel_el.get("enabled") == "1"
signals = literal_eval(channel_el.get("signals"))
for source_channel, sink_channel in signals: