403Webshell
Server IP : 182.53.201.61  /  Your IP : 216.73.217.175
Web Server : Apache/2.2.15 (Fedora)
System : Linux km10.dyndns.org 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686
User : apache ( 48)
PHP Version : 5.3.3
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python2.6/site-packages/paste/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python2.6/site-packages/paste//registry.pyc
Ñò
•ÊIc@sÆdZddkZddkiiZddddgZdefd„ƒYZdefd	„ƒYZd
efd„ƒYZ	defd„ƒYZ
defd
„ƒYZeƒZd„Z
e
ie
_dS(s©
Registry for handling request-local module globals sanely

Dealing with module globals in a thread-safe way is good if your
application is the sole responder in a thread, however that approach fails
to properly account for various scenarios that occur with WSGI applications
and middleware.

What is actually needed in the case where a module global is desired that
is always set properly depending on the current request, is a stacked
thread-local object. Such an object is popped or pushed during the request
cycle so that it properly represents the object that should be active for
the current request.

To make it easy to deal with such variables, this module provides a special
StackedObjectProxy class which you can instantiate and attach to your
module where you'd like others to access it. The object you'd like this to
actually "be" during the request is then registered with the
RegistryManager middleware, which ensures that for the scope of the current
WSGI application everything will work properly.

Example:

.. code-block:: python
    
    #yourpackage/__init__.py
    
    from paste.registry import RegistryManager, StackedObjectProxy
    myglobal = StackedObjectProxy()
    
    #wsgi app stack
    app = RegistryManager(yourapp)
    
    #inside your wsgi app
    class yourapp(object):
        def __call__(self, environ, start_response):
            obj = someobject  # The request-local object you want to access
                              # via yourpackage.myglobal
            if environ.has_key('paste.registry'):
                environ['paste.registry'].register(myglobal, obj)

You will then be able to import yourpackage anywhere in your WSGI app or in
the calling stack below it and be assured that it is using the object you
registered with Registry.

RegistryManager can be in the WSGI stack multiple times, each time it
appears it registers a new request context.


Performance
===========

The overhead of the proxy object is very minimal, however if you are using
proxy objects extensively (Thousands of accesses per request or more), there
are some ways to avoid them. A proxy object runs approximately 3-20x slower
than direct access to the object, this is rarely your performance bottleneck
when developing web applications.

Should you be developing a system which may be accessing the proxy object
thousands of times per request, the performance of the proxy will start to
become more noticeable. In that circumstance, the problem can be avoided by
getting at the actual object via the proxy with the ``_current_obj`` function:

.. code-block:: python
    
    #sessions.py
    Session = StackedObjectProxy()
    # ... initialization code, etc.
    
    # somemodule.py
    import sessions
    
    def somefunc():
        session = sessions.Session._current_obj()
        # ... tons of session access

This way the proxy is used only once to retrieve the object for the current
context and the overhead is minimized while still making it easy to access
the underlying object. The ``_current_obj`` function is preceded by an
underscore to more likely avoid clashing with the contained object's
attributes.

**NOTE:** This is *highly* unlikely to be an issue in the vast majority of
cases, and requires incredibly large amounts of proxy object access before
one should consider the proxy object to be causing slow-downs. This section
is provided solely in the extremely rare case that it is an issue so that a
quick way to work around it is documented.

iÿÿÿÿNtStackedObjectProxytRegistryManagertStackedObjectRestorertrestorert	NoDefaultcBseZRS((t__name__t
__module__(((s2/usr/lib/python2.6/site-packages/paste/registry.pyRbscBseZdZedd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
d	„Zd
„Zd„Z
d„Zd
„Zd„Zd„Zd„Zd„Zdd„Zd„Zd„Zdeie_d„Zdeie_dd„Zdeie_RS(sÈTrack an object instance internally using a stack
    
    The StackedObjectProxy proxies access to an object internally using a
    stacked thread-local. This makes it safe for complex WSGI environments
    where access to the object may be desired in multiple places without
    having to pass the actual object around.
    
    New objects are added to the top of the stack with _push_object while
    objects can be removed with _pop_object. 
    
    tDefaultcCsB||id<tiƒ|id<|tj	o||id<ndS(s¡Create a new StackedObjectProxy
        
        If a default is given, its used in every thread if no other object
        has been pushed on.
        
        t
____name__t____local__t____default_object__N(t__dict__tthreadinglocaltlocalR(tselftdefaulttname((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__init__ps

cCs]t|iƒ|iiƒ}y|it|iƒƒƒWntj
onX|iƒ|S(sfReturn a list of the StackedObjectProxy's and proxied
        object's (if one exists) names.
        (tdirt	__class__Rtkeystextendt_current_objt	TypeErrortsort(Rtdir_list((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__dir__|s
cCst|iƒ|ƒS(N(tgetattrR(Rtattr((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__getattr__ˆscCst|iƒ||ƒdS(N(tsetattrR(RRtvalue((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__setattr__‹scCst|iƒ|ƒdS(N(tdelattrR(RR((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__delattr__ŽscCs|iƒ|S(N(R(Rtkey((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__getitem__‘scCs||iƒ|<dS(N(R(RR#R((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__setitem__”scCs|iƒ|=dS(N(R(RR#((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__delitem__—scOs|iƒ||ŽS(N(R(Rtargstkw((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__call__šscCsTyt|iƒƒSWn9ttfj
o'd|ii|iit|ƒfSXdS(Ns<%s.%s object at 0x%x>(treprRRtAttributeErrorRRRtid(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__repr__s	cCst|iƒƒS(N(titerR(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__iter__¥scCst|iƒƒS(N(tlenR(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__len__¨scCs||iƒjS(N(R(RR#((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__contains__«scCst|iƒƒS(N(tboolR(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyt__nonzero__®scCsct|iddƒ}|o	|dS|iidtƒ}|tj	o|Std|iƒ‚dS(sÙReturns the current active object being proxied to
        
        In the event that no object was pushed, the default object if
        provided will be used. Otherwise, a TypeError will be raised.
        
        tobjectsiÿÿÿÿR
s8No object (name: %s) has been registered for this threadN(RR	tNoneRtgetRRR(RR5tobj((s2/usr/lib/python2.6/site-packages/paste/registry.pyR±s	
cCs:t|idƒpg|i_n|iii|ƒdS(sˆMake ``obj`` the active object for this thread-local.
        
        This should be used like:
        
        .. code-block:: python

            obj = yourobject()
            module.glob = StackedObjectProxy()
            module.glob._push_object(obj)
            try:
                ... do stuff ...
            finally:
                module.glob._pop_object(conf)
        
        R5N(thasattrR	R5tappend(RR8((s2/usr/lib/python2.6/site-packages/paste/registry.pyt_push_objectÄscCskt|idƒptdƒ‚n|iiiƒ}|o+||j	otd||fƒ‚qgndS(s²Remove a thread-local object.
        
        If ``obj`` is given, it is checked against the popped object and an
        error is emitted if they don't match.
        
        R5s-No object has been registered for this threadsBThe object popped (%s) is not the same as the object expected (%s)N(R9R	tAssertionErrorR5tpop(RR8tpopped((s2/usr/lib/python2.6/site-packages/paste/registry.pyt_pop_objectØs
cCs*y|iiSWntj
ogSXdS(sjReturns all of the objects stacked in this container

        (Might return [] if there are none)
        N(R	R5R<(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyt
_object_stackèscCs.tiƒ}|oti||ƒS|iƒS(N(Rtin_restorationtget_saved_proxied_objt_current_obj_orig(Rt
request_id((s2/usr/lib/python2.6/site-packages/paste/registry.pyt_current_obj_restorationöss.%s
(StackedObjectRestorer restoration enabled)cCs"tiƒp|i|ƒndS(N(RRAt_push_object_orig(RR8((s2/usr/lib/python2.6/site-packages/paste/registry.pyt_push_object_restorationÿs
cCs"tiƒp|i|ƒndS(N(RRAt_pop_object_orig(RR8((s2/usr/lib/python2.6/site-packages/paste/registry.pyt_pop_object_restorations
N(RRt__doc__RRRRR R"R$R%R&R)R-R/R1R2R4RR;R6R?R@RERGRI(((s2/usr/lib/python2.6/site-packages/paste/registry.pyRds8																	
	
tRegistrycBs8eZdZd„Zd„Zd„ZeZd„ZRS(sƒTrack objects and stacked object proxies for removal
    
    The Registry object is instantiated a single time for the request no
    matter how many times the RegistryManager is used in a WSGI stack. Each
    RegistryManager must call ``prepare`` before continuing the call to
    start a new context for object registering.
    
    Each context is tracked with a dict inside a list. The last list
    element is the currently executing context. Each context dict is keyed
    by the id of the StackedObjectProxy instance being proxied, the value
    is a tuple of the StackedObjectProxy instance and the object being
    tracked.
    
    cCs
g|_dS(s¥Create a new Registry object
        
        ``prepare`` must still be called before this Registry object can be
        used to register objects.
        
        N(treglist(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyRscCs|iihƒdS(sõUsed to create a new registry context
        
        Anytime a new RegistryManager is called, ``prepare`` needs to be
        called on the existing Registry object. This sets up a new context
        for registering objects.
        
        N(RLR:(R((s2/usr/lib/python2.6/site-packages/paste/registry.pytprepare%scCsg|id}t|ƒ}||jo |i||dƒ||=n|i|ƒ||f||<dS(s,Register an object with a StackedObjectProxyiÿÿÿÿiN(RLR,R?R;(RtstackedR8t	myreglistt
stacked_id((s2/usr/lib/python2.6/site-packages/paste/registry.pytregister/s


cCsBx.|idiƒD]\}}|i|ƒqW|iiƒdS(skRemove all objects from all StackedObjectProxy instances that
        were tracked at this Registry contextiÿÿÿÿN(RLt
itervaluesR?R=(RRNR8((s2/usr/lib/python2.6/site-packages/paste/registry.pytcleanup<s(RRRJRRMRQtreplaceRS(((s2/usr/lib/python2.6/site-packages/paste/registry.pyRK
s			
	cBs,eZdZed„Zd„Zd„ZRS(sKCreates and maintains a Registry context
    
    RegistryManager creates a new registry context for the registration of
    StackedObjectProxy instances. Multiple RegistryManager's can be in a
    WSGI stack and will manage the context so that the StackedObjectProxies
    always proxy to the proper object.
    
    The object being registered can be any object sub-class, list, or dict.
    
    Registering objects is done inside a WSGI application under the
    RegistryManager instance, using the ``environ['paste.registry']``
    object which is a Registry instance.
        
    cCs||_||_dS(N(tapplicationt	streaming(RRURV((s2/usr/lib/python2.6/site-packages/paste/registry.pyRRs	cCs)d}|idtƒƒ}|iƒ|io|i|||ƒSy|i||ƒ}Wn¿tj
o}|idƒoYt	}x4|idgƒD] }t
||ƒo
t}q•q•W|pti
|ƒqÕn|iƒ‚n@|idƒoti
|ƒn|iƒ‚nX|iƒ|S(Nspaste.registryspaste.evalexceptionspaste.expected_exceptions(R6t
setdefaultRKRMRVtstreaming_iterRUt	ExceptionR7tFalset
isinstancetTrueRtsave_registry_stateRS(Rtenvirontstart_responsetapp_itertregtetexpectedtexpect((s2/usr/lib/python2.6/site-packages/paste/registry.pyR)Vs2




ccsöy&x|i||ƒD]}|VqWWn¿tj
o}|idƒoYt}x4|idgƒD] }t||ƒo
t}qbqbW|pti|ƒq¢n|iƒ‚n@|idƒoti|ƒn|iƒ‚nX|iƒdS(Nspaste.evalexceptionspaste.expected_exceptions(	RURYR7RZR[R\RR]RS(RRaR^R_titemRbRcRd((s2/usr/lib/python2.6/site-packages/paste/registry.pyRXzs*


(RRRJRZRR)RX(((s2/usr/lib/python2.6/site-packages/paste/registry.pyRCs	$cBsVeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z	d„Z
RS(	sTrack StackedObjectProxies and their proxied objects for automatic
    restoration within EvalException's interactive debugger.

    An instance of this class tracks all StackedObjectProxy state in existence
    when unexpected exceptions are raised by WSGI applications housed by
    EvalException and RegistryManager. Like EvalException, this information is
    stored for the life of the process.

    When an unexpected exception occurs and EvalException is present in the
    WSGI stack, save_registry_state is intended to be called to store the
    Registry state and enable automatic restoration on all currently registered
    StackedObjectProxies.

    With restoration enabled, those StackedObjectProxies' _current_obj
    (overwritten by _current_obj_restoration) method's strategy is modified:
    it will return its appropriate proxied object from the restorer when
    a restoration context is active in the current thread.

    The StackedObjectProxies' _push/pop_object methods strategies are also
    changed: they no-op when a restoration context is active in the current
    thread (because the pushing/popping work is all handled by the
    Registry/restorer).

    The request's Registry objects' reglists are restored from the restorer
    when a restoration context begins, enabling the Registry methods to work
    while their changes are tracked by the restorer.

    The overhead of enabling restoration is negligible (another threadlocal
    access for the changed StackedObjectProxy methods) for normal use outside
    of a restoration context, but worth mentioning when combined with
    StackedObjectProxies normal overhead. Once enabled it does not turn off,
    however:

    o Enabling restoration only occurs after an unexpected exception is
    detected. The server is likely to be restarted shortly after the exception
    is raised to fix the cause

    o StackedObjectRestorer is only enabled when EvalException is enabled (not
    on a production server) and RegistryManager exists in the middleware
    stackcCsh|_tiƒ|_dS(N(tsaved_registry_statesRR
trestoration_context_id(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyRÁs	cCs¨|idƒ}|p*t|iƒp|i|ƒ|ijodS||if|i|i|ƒ<x;|iD]0}x'|iƒD]\}}|i|ƒqƒWqpWdS(s§Save the state of this request's Registry (if it hasn't already been
        saved) to the saved_registry_states dict, keyed by the request's unique
        identifierspaste.registryN(R7R0RLtget_request_idRfRRtenable_restoration(RR^tregistryRLRNR8((s2/usr/lib/python2.6/site-packages/paste/registry.pyR]Æs 

cCs†|i|d}t|ƒd}t|ƒ}xJtoB|djo|iƒS||}||joPn|d8}q0W||dS(svRetrieve the saved object proxied by the specified
        StackedObjectProxy for the request identified by request_idii(RfR0R,R\RC(RRNRDRLtstack_levelRPtcontext((s2/usr/lib/python2.6/site-packages/paste/registry.pyRBÛs


cCsjd|ijodSxNdD]F}t||ƒ}t||dƒ}||i|d<||i|<qWdS(	s¹Replace the specified StackedObjectProxy's methods with their
        respective restoration versions.

        _current_obj_restoration forces recovery of the saved proxied object
        when a restoration context is active in the current thread.

        _push/pop_object_restoration avoid pushing/popping data
        (pushing/popping is only done at the Registry level) when a restoration
        context is active in the current threadRCNRR;R?t_restorationt_orig(s_current_objs_push_objects_pop_object(RR(RRNt	func_namet	orig_functrestoration_func((s2/usr/lib/python2.6/site-packages/paste/registry.pyRiòs
cCsddkl}||ƒS(s2Return a unique identifier for the current requestiÿÿÿÿ(tget_debug_count(tpaste.evalexception.middlewareRr(RR^Rr((s2/usr/lib/python2.6/site-packages/paste/registry.pyRhscCs@||ijo |i|\}}||_n||i_dS(sWEnable a restoration context in the current thread for the specified
        request_idN(RfRLRgRD(RRDRjRL((s2/usr/lib/python2.6/site-packages/paste/registry.pytrestoration_begins
cCs'y
|i`Wntj
onXdS(s9Register a restoration context as finished, if one existsN(RgRDR+(R((s2/usr/lib/python2.6/site-packages/paste/registry.pytrestoration_ends
cCst|idtƒS(sŠDetermine if a restoration context is active for the current thread.
        Returns the request_id it's active for if so, otherwise FalseRD(RRgRZ(R((s2/usr/lib/python2.6/site-packages/paste/registry.pyRAs(RRRJRR]RBRiRhRtRuRA(((s2/usr/lib/python2.6/site-packages/paste/registry.pyR˜s(						
	cCs
t|ƒS(N(R(tapptglobal_conf((s2/usr/lib/python2.6/site-packages/paste/registry.pytmake_registry_manager%s(RJtsystpaste.util.threadinglocaltutilRt__all__tobjectRRRKRRRRx(((s2/usr/lib/python2.6/site-packages/paste/registry.pyt<module>[s		©6U‰		

Youez - 2016 - github.com/yon3zu
LinuXploit