Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/networkx/utils/contextmanagers.py @ 2:6af9afd405e9 draft
"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author | shellac |
---|---|
date | Thu, 14 May 2020 14:56:58 -0400 |
parents | 26e78fe6e8c4 |
children |
comparison
equal
deleted
inserted
replaced
1:75ca89e9b81c | 2:6af9afd405e9 |
---|---|
1 | |
2 from contextlib import contextmanager | |
3 | |
4 __all__ = [ | |
5 'reversed', | |
6 ] | |
7 | |
8 | |
9 @contextmanager | |
10 def reversed(G): | |
11 """A context manager for temporarily reversing a directed graph in place. | |
12 | |
13 This is a no-op for undirected graphs. | |
14 | |
15 Parameters | |
16 ---------- | |
17 G : graph | |
18 A NetworkX graph. | |
19 """ | |
20 directed = G.is_directed() | |
21 if directed: | |
22 G._pred, G._succ = G._succ, G._pred | |
23 G._adj = G._succ | |
24 | |
25 try: | |
26 yield | |
27 finally: | |
28 if directed: | |
29 # Reverse the reverse. | |
30 G._pred, G._succ = G._succ, G._pred | |
31 G._adj = G._succ |