%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyo

�
a�Nc@s)dZddlmZddlZdgZddgZdefd��YZdefd	��YZ	defd
��YZ
defd��YZdefd
��YZ
de
fd��YZde
fd��YZdefd��YZde
fd��YZdefd��YZd�Zee_dS(s
Middleware to make internal requests and forward requests internally.

When applied, several keys are added to the environment that will allow
you to trigger recursive redirects and forwards.

  paste.recursive.include:
      When you call
      ``environ['paste.recursive.include'](new_path_info)`` a response
      will be returned.  The response has a ``body`` attribute, a
      ``status`` attribute, and a ``headers`` attribute.

  paste.recursive.script_name:
      The ``SCRIPT_NAME`` at the point that recursive lives.  Only
      paths underneath this path can be redirected to.

  paste.recursive.old_path_info:
      A list of previous ``PATH_INFO`` values from previous redirects.

Raise ``ForwardRequestException(new_path_info)`` to do a forward
(aborting the current request).
i����(tStringIONtRecursiveMiddlewaretForwardRequestExceptiont
RecursionLoopcBseZdZRS(s*Raised when a recursion enters into a loop(t__name__t
__module__t__doc__(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR stCheckForRecursionMiddlewarecBseZd�Zd�ZRS(cCs||_||_dS(N(tapptenv(tselfRR	((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyt__init__%s	cCs�|jdd�}||jjdg�krMtd||jdf��n|jjdg�}|j|jjdd��|j||�S(Nt	PATH_INFOtspaste.recursive.old_path_infosGForwarding loop detected; %r visited twice (internal redirect path: %s)(tgetR	Rt
setdefaulttappendR(R
tenvirontstart_responset	path_infot
old_path_info((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyt__call__)s(RRRR(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR$s	cBs#eZdZdd�Zd�ZRS(s}
    A WSGI middleware that allows for recursive and forwarded calls.
    All these calls go to the same 'application', but presumably that
    application acts differently with different URLs.  The forwarded
    URLs must be relative to this container.

    Interface is entirely through the ``paste.recursive.forward`` and
    ``paste.recursive.include`` environmental keys.
    cCs
||_dS(N(tapplication(R
Rtglobal_conf((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRAscCs�t|j||�|d<t|j||�|d<t|j||�|d<|jdd�}||d<y|j||�SWn5tk
r�}t|j|�|�}|||�SXdS(Nspaste.recursive.forwardspaste.recursive.includes paste.recursive.include_app_itertSCRIPT_NAMER
spaste.recursive.script_name(t	ForwarderRtIncludertIncluderAppIterRRRtfactory(R
RRtmy_script_nametet
middleware((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRDs(



N(RRRtNoneRR(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR5s
cBs#eZdZdiddd�ZRS(s

    Used to signal that a request should be forwarded to a different location.

    ``url``
        The URL to forward to starting with a ``/`` and relative to
        ``RecursiveMiddleware``. URL fragments can also contain query strings
        so ``/error?code=404`` would be a valid URL fragment.

    ``environ``
        An altertative WSGI environment dictionary to use for the forwarded
        request. If specified is used *instead* of the ``url_fragment``

    ``factory``
        If specifed ``factory`` is used instead of ``url`` or ``environ``.
        ``factory`` is a callable that takes a WSGI application object
        as the first argument and returns an initialised WSGI middleware
        which can alter the forwarded response.

    Basic usage (must have ``RecursiveMiddleware`` present) :

    .. code-block:: python

        from paste.recursive import ForwardRequestException
        def app(environ, start_response):
            if environ['PATH_INFO'] == '/hello':
                start_response("200 OK", [('Content-type', 'text/plain')])
                return ['Hello World!']
            elif environ['PATH_INFO'] == '/error':
                start_response("404 Not Found", [('Content-type', 'text/plain')])
                return ['Page not found']
            else:
                raise ForwardRequestException('/error')

        from paste.recursive import RecursiveMiddleware
        app = RecursiveMiddleware(app)

    If you ran this application and visited ``/hello`` you would get a
    ``Hello World!`` message. If you ran the application and visited
    ``/not_found`` a ``ForwardRequestException`` would be raised and the caught
    by the ``RecursiveMiddleware``. The ``RecursiveMiddleware`` would then
    return the headers and response from the ``/error`` URL but would display
    a ``404 Not found`` status message.

    You could also specify an ``environ`` dictionary instead of a url. Using
    the same example as before:

    .. code-block:: python

        def app(environ, start_response):
            ... same as previous example ...
            else:
                new_environ = environ.copy()
                new_environ['PATH_INFO'] = '/error'
                raise ForwardRequestException(environ=new_environ)

    Finally, if you want complete control over every aspect of the forward you
    can specify a middleware factory. For example to keep the old status code
    but use the headers and resposne body from the forwarded response you might
    do this:

    .. code-block:: python

        from paste.recursive import ForwardRequestException
        from paste.recursive import RecursiveMiddleware
        from paste.errordocument import StatusKeeper

        def app(environ, start_response):
            if environ['PATH_INFO'] == '/hello':
                start_response("200 OK", [('Content-type', 'text/plain')])
                return ['Hello World!']
            elif environ['PATH_INFO'] == '/error':
                start_response("404 Not Found", [('Content-type', 'text/plain')])
                return ['Page not found']
            else:
                def factory(app):
                    return StatusKeeper(app, status='404 Not Found', url='/error')
                raise ForwardRequestException(factory=factory)

        app = RecursiveMiddleware(app)
    csP|r�rtd��n|r6�r6td��n�rQ�rQtd��n|r��sstjdtd�ntd��||_n�r�dt��kr��|_ndtfd	��Y�t|d
�r�|j���fd�}||_nQ�r��fd�}||_n-�rC��fd
�}||_n	||_dS(Ns?You cannot specify factory and a url in ForwardRequestExceptionsAYou cannot specify factory and environ in ForwardRequestExceptions=You cannot specify environ and url in ForwardRequestExceptionsgForwardRequestException(path_info=...) has been deprecated; please use ForwardRequestException(url=...)is;You cannot use url and path_info in ForwardRequestExceptiont?t!ForwardRequestExceptionMiddlewarecBseZd�ZRS(cSs
||_dS(N(R(R
R((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s(RRR(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR"�sRcs&d�f�fd��Y}||�S(NtPathInfoForwardcseZ�fd�ZRS(cs�|d<|j||�S(NR(R(R
RR(tp(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s
(RRR((R$(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR#�s((RR#(R"R$(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pytfactory_�scs&d�f�fd��Y}||�S(Nt
URLForwardcseZ�fd�ZRS(cs>�jd�d|d<�jd�d|d<|j||�S(NR!iRitQUERY_STRING(tsplitR(R
RR(turl(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s(RRR((R)(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR&�s((RR&(R"R)(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR%�scs&d�f�fd��Y}||�S(NtEnvironForwardcseZ�fd�ZRS(cs|j�|�S(N(R(R
tenviron_R(R(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s(RRR((R(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR*�s((RR*(R"R(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR%�s(	t	TypeErrortwarningstwarntDeprecationWarningRtstrtobjectthasattrR(R
R)RRRR%((R"RR$R)s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s<
	N(RRRR R(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRZs
Pt	RecursivecBs/eZd�Zdd�Zd�Zd�ZRS(cCs.||_|j�|_||_||_dS(N(Rtcopytoriginal_environtprevious_environR(R
RRR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s		cCs�|jj�}|r%|j|�n|j|d<|jjd�}|jd�rj|t|�d}nd|}||d<d|d<d|d	<d
|d<td
�|d<|j|�S(
s�
        `extra_environ` is an optional dictionary that is also added
        to the forwarded request.  E.g., ``{'HTTP_HOST': 'new.host'}``
        could be used to forward to a different virtual host.
        s paste.recursive.previous_environRt/iRtGETtREQUEST_METHODt0tCONTENT_LENGTHR
tCONTENT_TYPEs
wsgi.input(	R5R4tupdateR6Rt
startswithtlenRtactivate(R
tpatht
extra_environRt	base_pathR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s





cCs
t�dS(N(tNotImplementedError(R
R((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR@scCs/d|jj|jj|jjd�p*dfS(Ns<%s.%s from %s>RR7(t	__class__RRR5R(R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyt__repr__s		N(RRRR RR@RF(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR3�s		RcBseZdZd�ZRS(s	
    The forwarder will try to restart the request, except with
    the new `path` (replacing ``PATH_INFO`` in the request).

    It must not be called after and headers have been returned.
    It returns an iterator that must be returned back up the call
    stack, so it must be used like:

    .. code-block:: python

        return environ['paste.recursive.forward'](path)

    Meaningful transformations cannot be done, since headers are
    sent directly to the server and cannot be inspected or
    rewritten.
    cCs&tjdtd�|j||j�S(NsKrecursive.Forwarder has been deprecated; please use ForwardRequestExceptioni(R-R.R/RR(R
R((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR@.s
(RRRR@(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRsRcBseZdZd�ZRS(s�
    Starts another request with the given path and adding or
    overwriting any values in the `extra_environ` dictionary.
    Returns an IncludeResponse object.
    cs}t��d�fd�}|j||�}z"x|D]}�j|�q7WWdt|d�rn|j�nX�j��S(Ncs:|r!|d|d|d�n|�_|�_�jS(Niii(tstatustheaderstwrite(RGRHtexc_info(tresponse(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR@s
		tclose(tIncludedResponseR RRIR2RL(R
RRtapp_iterts((RKs@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR@>s	

(RRRR@(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR6sRMcBsAeZd�Zd�Zd�Zd�Zd�Zee�ZRS(cCs+d|_d|_t�|_d|_dS(N(R RHRGRtoutputR0(R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRRs		cCs,|jj�|_|jj�d|_dS(N(RPtgetvalueR0RLR (R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRLXs
cCs|jj|�dS(N(RPRI(R
RO((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRI]scCs|jS(N(tbody(R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyt__str__cscCs'|jdkr|jj�S|jSdS(N(R0R RPRQ(R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyt	body__getfs
(	RRRRLRIRSRTtpropertyRR(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRMPs					RcBseZdZd�ZRS(sk
    Like Includer, but just stores the app_iter response
    (be sure to call close on the response!)
    cs:t��d�fd�}|j||�}|�_�S(Ncs:|r!|d|d|d�n|�_|�_�jS(Niii(RGRHRI(RGRHRJ(RK(s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRvs
		(tIncludedAppIterResponseR RRN(R
RRRN((RKs@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR@ts
		(RRRR@(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRnsRVcBs#eZd�Zd�Zd�ZRS(cCs1d|_d|_g|_d|_t|_dS(N(R RGRHtaccumulatedRNtFalset_closed(R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyR�s
				cCs&t|jd�r"|jj�ndS(NRL(R2RNRL(R
((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRL�scCs|jjdS(N(RWR(R
RO((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRI�s(RRRRLRI(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyRV�s		cCs
t|�S(N(R(RR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pytmake_recursive_middleware�s(Rt	cStringIORR-t__all__t
__pudge_all__tAssertionErrorRR1RRt	ExceptionRR3RRRMRRVRZ(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/recursive.pyt<module>s 	%�*	

Zerion Mini Shell 1.0