Rename class ContextManager to ContextWrapper, per Nick's proposal.
This commit is contained in:
parent
f2d367de26
commit
cc0bfb59f2
|
@ -258,7 +258,7 @@ Generator Decorator
|
|||
that makes it possible to use a generator that yields exactly once
|
||||
to control a with-statement. Here's a sketch of such a decorator:
|
||||
|
||||
class ContextManager(object):
|
||||
class ContextWrapper(object):
|
||||
|
||||
def __init__(self, gen):
|
||||
self.gen = gen
|
||||
|
@ -287,14 +287,14 @@ Generator Decorator
|
|||
|
||||
def contextmanager(func):
|
||||
def helper(*args, **kwds):
|
||||
return ContextManager(func(*args, **kwds))
|
||||
return ContextWrapper(func(*args, **kwds))
|
||||
return helper
|
||||
|
||||
This decorator could be used as follows:
|
||||
|
||||
@contextmanager
|
||||
def opening(filename):
|
||||
f = open(filename) # IOError is untouched by ContextManager
|
||||
f = open(filename) # IOError is untouched by ContextWrapper
|
||||
try:
|
||||
yield f
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue