Commit 9ff72ded authored by Robert Bradshaw's avatar Robert Bradshaw

merge

parents 710360fe 3c4a95e1
...@@ -12,12 +12,12 @@ exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'> ...@@ -12,12 +12,12 @@ exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
>>> with_exception(None) >>> with_exception(None)
enter enter
value value
exit <type 'type'> <class 'withstat.MyException'> <type 'traceback'> exit <type 'type'> <type 'MyException'> <type 'traceback'>
outer except outer except
>>> with_exception(True) >>> with_exception(True)
enter enter
value value
exit <type 'type'> <class 'withstat.MyException'> <type 'traceback'> exit <type 'type'> <type 'MyException'> <type 'traceback'>
>>> multitarget() >>> multitarget()
enter enter
1 2 3 4 5 1 2 3 4 5
...@@ -32,20 +32,23 @@ enter ...@@ -32,20 +32,23 @@ enter
exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'> exit <type 'NoneType'> <type 'NoneType'> <type 'NoneType'>
""" """
def typename(t):
return u"<type '%s'>" % type(t).__name__
class MyException(Exception): class MyException(Exception):
pass pass
class ContextManager: class ContextManager(object):
def __init__(self, value, exit_ret = None): def __init__(self, value, exit_ret = None):
self.value = value self.value = value
self.exit_ret = exit_ret self.exit_ret = exit_ret
def __exit__(self, a, b, tb): def __exit__(self, a, b, tb):
print "exit", type(a), type(b), type(tb) print u"exit", typename(a), typename(b), typename(tb)
return self.exit_ret return self.exit_ret
def __enter__(self): def __enter__(self):
print "enter" print u"enter"
return self.value return self.value
def no_as(): def no_as():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment