(prefix, reset=False)
| 34 | |
| 35 | @contextlib.contextmanager |
| 36 | def NameScope(prefix, reset=False): |
| 37 | global _threadlocal_scope |
| 38 | assert isinstance(prefix, basestring) or prefix is None, \ |
| 39 | "NameScope takes in a string as its argument." |
| 40 | old_scope = CurrentNameScope() |
| 41 | prefix = prefix + _NAMESCOPE_SEPARATOR if prefix else '' |
| 42 | if reset: |
| 43 | _threadlocal_scope.namescope = prefix |
| 44 | else: |
| 45 | _threadlocal_scope.namescope = _threadlocal_scope.namescope + prefix |
| 46 | |
| 47 | try: |
| 48 | yield |
| 49 | finally: |
| 50 | assert _threadlocal_scope.namescope.endswith(prefix), \ |
| 51 | "The namescope variable is changed from outside NameScope() calls." |
| 52 | _threadlocal_scope.namescope = old_scope |
| 53 | |
| 54 | |
| 55 | @contextlib.contextmanager |
no test coverage detected
searching dependent graphs…