~ssweeny/friends/fix-lp1258657

« back to all changes in this revision

Viewing changes to friends/errors.py

  • Committer: Robert Bruce Park
  • Date: 2013-05-01 17:05:12 UTC
  • mfrom: (160.11.31 trunk-next)
  • Revision ID: robert.park@canonical.com-20130501170512-d3xrvv4vmv24k3ir
Land trunk-next into lp:friends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    ]
24
24
 
25
25
 
 
26
try:
 
27
    from contextlib import ignored
 
28
except ImportError:
 
29
    from contextlib import contextmanager
 
30
 
 
31
    # This is a fun toy from Python 3.4, but I want it NOW!!
 
32
    @contextmanager
 
33
    def ignored(*exceptions):
 
34
        """Context manager to ignore specifed exceptions.
 
35
 
 
36
             with ignored(OSError):
 
37
                 os.remove(somefile)
 
38
 
 
39
        Thanks to Raymond Hettinger for this.
 
40
        """
 
41
        try:
 
42
            yield
 
43
        except exceptions:
 
44
            pass
 
45
 
 
46
 
26
47
class FriendsError(Exception):
27
48
    """Base class for all internal Friends exceptions."""
28
49