Skip to content

Commit 9551c38

Browse files
committed
Move context module to jaraco.context package.
1 parent 9fc85a6 commit 9551c38

File tree

5 files changed

+9
-53
lines changed

5 files changed

+9
-53
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Changes
1111
has been moved to the ``jaraco.classes`` package.
1212
* Deprecated ``jaraco.util.classlib.ensure_sequence``. Use
1313
``jaraco.itertools.always_iterable`` instead.
14+
* Deprecated ``jaraco.util.context``. Functionality moved to
15+
``jaraco.context``.
1416

1517
10.8
1618
~~~~

jaraco/util/context.py

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,7 @@
1-
import contextlib
1+
import warnings
22

3+
from jaraco.context import *
34

4-
@contextlib.contextmanager
5-
def null_context():
6-
yield
5+
warnings.warn("Use jaraco.context package", DeprecationWarning)
76

8-
9-
class ExceptionTrap(object):
10-
"""
11-
A context manager that will catch certain exceptions and provide an
12-
indication they occurred.
13-
14-
>>> with ExceptionTrap() as trap:
15-
... raise Exception()
16-
>>> bool(trap)
17-
True
18-
19-
>>> with ExceptionTrap() as trap:
20-
... pass
21-
>>> bool(trap)
22-
False
23-
24-
>>> with ExceptionTrap(ValueError) as trap:
25-
... raise ValueError("1 + 1 is not 3")
26-
>>> bool(trap)
27-
True
28-
29-
>>> with ExceptionTrap(ValueError) as trap:
30-
... raise Exception()
31-
Traceback (most recent call last):
32-
...
33-
Exception
34-
35-
>>> bool(trap)
36-
False
37-
"""
38-
exc_info = None, None, None
39-
40-
def __init__(self, exceptions=(Exception,)):
41-
self.exceptions = exceptions
42-
43-
def __enter__(self):
44-
return self
45-
46-
def __exit__(self, exc_type, exc_val, traceback):
47-
matches = exc_type and issubclass(exc_type, self.exceptions)
48-
if matches:
49-
self.exc_info = exc_type, exc_val, traceback
50-
return matches
51-
52-
def __bool__(self):
53-
return bool(self.exc_info[0])
54-
__nonzero__ = __bool__
7+
null_context = null

jaraco/util/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
from . import context
3+
from jaraco import context
44

55

66
def throws_exception(callable, *exceptions):

jaraco/util/string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import six
1010
from jaraco.functools import compose
11+
from jaraco.context import ExceptionTrap
1112

12-
from .context import ExceptionTrap
1313
import jaraco.util.dictlib
1414

1515

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
'jaraco.itertools',
5757
'jaraco.logging',
5858
'jaraco.classes>=1.1',
59+
'jaraco.context>=1.2',
5960
],
6061
tests_require=[
6162
'pytest>=2',

0 commit comments

Comments
 (0)