File manager - Edit - /opt/imh-python/lib/python2.7/site-packages/rads/implementation/contextdecorator.pyc
Back
� �]c @ s� d Z d d l Z y d d l m Z Wn e k rB d � Z n Xe j d k r] d d Un d d Uy e Wn e k r� d � Z n Xd d d g Z d Z d Z d e f d � � YZ d e f d � � YZ d � Z d S( s� Create objects that act as both context managers *and* as decorators, and behave the same in both cases. Context managers inheriting from ``ContextDecorator`` have to implement ``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its optional exception handling even when used as a decorator. Example:: from contextlib import ContextDecorator class mycontext(ContextDecorator): def __enter__(self): print 'Starting' return self def __exit__(self, *exc): print 'Finishing' return False @mycontext() def function(): print 'The bit in the middle' with mycontext(): print 'The bit in the middle' Existing context managers that already have a base class can be extended by using ``ContextDecorator`` as a mixin class:: from contextlib import ContextDecorator class mycontext(ContextBaseClass, ContextDecorator): def __enter__(self): return self def __exit__(self, *exc): return False i����N( t wrapsc s � f d � } | S( Nc s � j | _ | S( N( t __name__( t f( t original( sS /opt/imh-python/lib/python2.7/site-packages/rads/implementation/contextdecorator.pyt inner5 s ( ( R R ( ( R sS /opt/imh-python/lib/python2.7/site-packages/rads/implementation/contextdecorator.pyR 4 s i i s+ def _reraise(cls, val, tb): raise val s4 def _reraise(cls, val, tb): raise cls, val, tb c C s | j � S( N( t next( t gen( ( sS /opt/imh-python/lib/python2.7/site-packages/rads/implementation/contextdecorator.pyR K s t __version__t ContextDecoratort contextmanagers 0.10.0c B s e Z d Z d � Z RS( sJ A base class or mixin that enables context managers to work as decorators.c s"