Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def in_edges_iter(self, nbunch=None, keys=False):
"""Return iterator over out edges in the graph.
If the optional nbunch (container of nodes) only out edges
adjacent to nodes in nbunch will be returned.
Note: modifying the graph structure while iterating over
edges may produce unpredictable results. Use in_edges()
as an alternative.
"""
if nbunch is None: # all nodes
nh = gv.agfstnode(self.handle)
while nh is not None:
eh = gv.agfstin(self.handle, nh)
while eh is not None:
e = Edge(self, eh=eh)
if keys:
yield (e[0], e[1], e.name)
else:
yield e
try:
eh = gv.agnxtin(self.handle, eh)
except StopIteration:
break
try:
nh = gv.agnxtnode(self.handle, nh)
except StopIteration:
return
elif nbunch in self: # if nbunch is a single node
n = Node(self, nbunch)
def predecessors_iter(self, n):
"""Return iterator over predecessor nodes of n.
Note: modifying the graph structure while iterating over
node predecessors may produce unpredictable results. Use
predecessors() as an alternative.
"""
n = Node(self, n)
nh = n.handle
eh = gv.agfstin(self.handle, nh)
while eh is not None:
(s, t) = Edge(self, eh=eh)
if s == n:
yield Node(self, t)
else:
yield Node(self, s)
try:
eh = gv.agnxtin(self.handle, eh)
except StopIteration:
return
def predecessors_iter(self,n):
"""Return iterator over predecessor nodes of n.
Note: modifying the graph structure while iterating over
node predecessors may produce unpredictable results. Use
predecessors() as an alternative.
"""
n=Node(self,n)
nh=n.handle
eh=gv.agfstin(self.handle,nh)
while eh is not None:
(s,t)=Edge(self,eh=eh)
if s==n:
yield Node(self,t)
else:
yield Node(self,s)
eh=gv.agnxtin(self.handle,eh)
raise StopIteration
if keys:
yield (e[0], e[1], e.name)
else:
yield e
try:
eh = gv.agnxtin(self.handle, eh)
except StopIteration:
break
try:
nh = gv.agnxtnode(self.handle, nh)
except StopIteration:
return
elif nbunch in self: # if nbunch is a single node
n = Node(self, nbunch)
nh = n.handle
eh = gv.agfstin(self.handle, nh)
while eh is not None:
e = Edge(self, eh=eh)
if keys:
yield (e[0], e[1], e.name)
else:
yield e
try:
eh = gv.agnxtin(self.handle, eh)
except StopIteration:
break
else: # if nbunch is a sequence of nodes
try:
bunch = [n for n in nbunch if n in self]
except TypeError:
raise TypeError("nbunch is not a node or a sequence of nodes.")
for n in nbunch:
if nbunch is None: # all nodes
nh=gv.agfstnode(self.handle)
while nh is not None:
eh=gv.agfstin(self.handle,nh)
while eh is not None:
e=Edge(self,eh=eh)
if keys:
yield (e[0],e[1],e.name)
else:
yield e
eh=gv.agnxtin(self.handle,eh)
nh=gv.agnxtnode(self.handle,nh)
elif nbunch in self: # if nbunch is a single node
n=Node(self,nbunch)
nh=n.handle
eh=gv.agfstin(self.handle,nh)
while eh is not None:
e=Edge(self,eh=eh)
if keys:
yield (e[0],e[1],e.name)
else:
yield e
eh=gv.agnxtin(self.handle,eh)
else: # if nbunch is a sequence of nodes
try: bunch=[n for n in nbunch if n in self]
except TypeError:
raise TypeError("nbunch is not a node or a sequence of nodes.")
for n in nbunch:
try:
nh=Node(self,n).handle
except KeyError:
continue
def in_edges_iter(self, nbunch=None, keys=False):
"""Return iterator over out edges in the graph.
If the optional nbunch (container of nodes) only out edges
adjacent to nodes in nbunch will be returned.
Note: modifying the graph structure while iterating over
edges may produce unpredictable results. Use in_edges()
as an alternative.
"""
if nbunch is None: # all nodes
nh=gv.agfstnode(self.handle)
while nh is not None:
eh=gv.agfstin(self.handle,nh)
while eh is not None:
e=Edge(self,eh=eh)
if keys:
yield (e[0],e[1],e.name)
else:
yield e
eh=gv.agnxtin(self.handle,eh)
nh=gv.agnxtnode(self.handle,nh)
elif nbunch in self: # if nbunch is a single node
n=Node(self,nbunch)
nh=n.handle
eh=gv.agfstin(self.handle,nh)
while eh is not None:
e=Edge(self,eh=eh)
if keys:
yield (e[0],e[1],e.name)