Ńň †°Ic@s”dZddklZddklZddgZeƒZdd d„ƒYZdefd„ƒYZ de fd „ƒYZ d e fd „ƒYZ d S(s­ A dynamic-scope-like system, aka fluid variables. The idea behind dynamic scoped variables is for when, at one level, you want to change the behavior of something you call. Except you can't pass in any new arguments (e.g., there's some function or object inbetween you and the thing you want to change), or you can't predict exactly what you will want to change. You should use it like:: context = Context() def do_stuff(): state = context.set(inside='do_stuff') try: do stuff... finally: state.restore() Then ``context.inside`` will be set to ``'do_stuff'`` inside that try block. If a value isn't set, you'll get an attribute error. Note that all values are thread local; this means you cannot use a context object to pass information to another thread. In a single-thread environment it doesn't really matter. Typically you will create ``Context`` instances for your application, environment, etc. These should be global module-level variables, that may be imported by any interested module; each instance is a namespace of its own. Sometimes it's nice to have default values, instead of getting attribute errors. This makes it easier to put in new variables that are intended to be used elsewhere, without having to use ``getattr(context, 'var', default)`` to avoid AttributeErrors. There are two ways (that can be used together) to do this. First, when instantiating a ``Context`` object, you can give it a ``default`` value. If given, then all variables will default to that value. ``None`` is a typical value for that. Another is ``context.set_default(**vars)``, which will set only those variables to default values. This will not effect the stack of scopes, but will only add defaults. When Python 2.5 comes out, this syntax would certainly be useful:: with context(page='view'): do stuff... And ``page`` will be set to ``'view'`` only inside that ``with`` block. i˙˙˙˙(tthreadinglocal(tcounttContexttContextRestoreErrort _NoDefaultcBseZRS((t__name__t __module__(((s6/usr/lib/python2.6/site-packages/formencode/context.pyR@scBseZdZRS(s9 Raised when something is restored out-of-order. (RRt__doc__(((s6/usr/lib/python2.6/site-packages/formencode/context.pyRCscBsJeZed„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(cCs$tiƒ|id<||idi i s...i˙˙˙˙s%s=%ss <%s %s %s>t (RRRthextabstidt __class__RR$tkeystsorttreprRRtjoin( R RtmyidtcurtvarsRR+tvarlisttkeytrep((s6/usr/lib/python2.6/site-packages/formencode/context.pyt__repr__„s,    ( RRRRRRR!R#R%R5(((s6/usr/lib/python2.6/site-packages/formencode/context.pyRHs     RcBseZd„Zd„ZRS(cCs||_||_t|_dS(N(RtcontexttFalsetrestored(R R6R((s6/usr/lib/python2.6/site-packages/formencode/context.pyRœs  cCs/|iodS|ii|iƒt|_dS(N(R8R6R#RtTrue(R ((s6/usr/lib/python2.6/site-packages/formencode/context.pytrestoreĄs (RRRR:(((s6/usr/lib/python2.6/site-packages/formencode/context.pyRšs N(( Rtformencode.utilRt itertoolsRt__all__RRt ExceptionRtobjectRR(((s6/usr/lib/python2.6/site-packages/formencode/context.pyt7s  R