Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()

This commit is contained in:
Nick Coghlan 2006-05-03 13:02:47 +00:00
parent 1b06a1d4e3
commit afd5e63e24
8 changed files with 101 additions and 120 deletions

View file

@ -2,10 +2,10 @@
import sys
__all__ = ["contextfactory", "nested", "closing"]
__all__ = ["contextmanager", "nested", "closing"]
class GeneratorContext(object):
"""Helper for @contextfactory decorator."""
class GeneratorContextManager(object):
"""Helper for @contextmanager decorator."""
def __init__(self, gen):
self.gen = gen
@ -45,12 +45,12 @@ class GeneratorContext(object):
raise
def contextfactory(func):
"""@contextfactory decorator.
def contextmanager(func):
"""@contextmanager decorator.
Typical usage:
@contextfactory
@contextmanager
def some_generator(<arguments>):
<setup>
try:
@ -74,7 +74,7 @@ def contextfactory(func):
"""
def helper(*args, **kwds):
return GeneratorContext(func(*args, **kwds))
return GeneratorContextManager(func(*args, **kwds))
try:
helper.__name__ = func.__name__
helper.__doc__ = func.__doc__
@ -84,7 +84,7 @@ def contextfactory(func):
return helper
@contextfactory
@contextmanager
def nested(*managers):
"""Support multiple context managers in a single with-statement.