本文整理汇总了Python中edge.Edge.get_subclasses方法的典型用法代码示例。如果您正苦于以下问题:Python Edge.get_subclasses方法的具体用法?Python Edge.get_subclasses怎么用?Python Edge.get_subclasses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edge.Edge
的用法示例。
在下文中一共展示了Edge.get_subclasses方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __declare_last__
# 需要导入模块: from edge import Edge [as 别名]
# 或者: from edge.Edge import get_subclasses [as 别名]
def __declare_last__(cls):
src_ids, dst_ids = [], []
for scls in Edge.get_subclasses():
name = scls.__name__
name_in = '_{}_in'.format(name)
name_out = '_{}_out'.format(name)
src_assoc = getattr(scls, SRC_DST_ASSOC)
dst_assoc = getattr(scls, DST_SRC_ASSOC)
if scls.__dst_class__ == cls.__name__:
if not hasattr(cls, name_in):
edge_in = relationship(
name,
foreign_keys=[scls.dst_id],
backref='dst',
cascade='all, delete, delete-orphan',
)
setattr(cls, name_in, edge_in)
cls._edges_in.append(name_in)
dst_ids.append(scls.dst_id)
cls._set_association_proxy(scls, dst_assoc, name_in, 'src')
if scls.__src_class__ == cls.__name__:
if not hasattr(cls, name_out):
edge_out = relationship(
name,
foreign_keys=[scls.src_id],
backref='src',
cascade='all, delete, delete-orphan',
)
setattr(cls, name_out, edge_out)
cls._edges_out.append(name_out)
src_ids.append(scls.src_id)
cls._set_association_proxy(scls, src_assoc, name_out, 'dst')
示例2: get_edge_by_labels
# 需要导入模块: from edge import Edge [as 别名]
# 或者: from edge.Edge import get_subclasses [as 别名]
def get_edge_by_labels(self, src_label, edge_label, dst_label):
src_classes = [n for n in Node.get_subclasses()
if n.get_label() == src_label]
dst_classes = [n for n in Node.get_subclasses()
if n.get_label() == dst_label]
assert len(src_classes) == 1,\
'No classes found with src_label {}'.format(src_label)
assert len(dst_classes) == 1,\
'No classes found with dst_label {}'.format(dst_label)
edges = [edge for edge in Edge.get_subclasses()
if edge.__src_class__ == src_classes[0].__name__
and edge.__dst_class__ == dst_classes[0].__name__
and edge.get_label() == edge_label]
assert len(edges) == 1,\
'Expected 1 edge {}-{}->{}, found {}'.format(
src_label, edge_label, dst_label, len(edges))
return edges[0]