%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyc

�
b�Nc@s�dZddlZddlZddlZddlZyddlZWnek
r_eZnXddlm	Z	ddlm
Z
ddlmZddlm
Z
ddlmZddlmZd	efd
��YZddd
gZdefd��YZd�Zejde�d�Zejde�d�Zd�Zd�Zejde�defd��YZed�Zd
efd��YZdd�Zeeed�ZdS(sH
WSGI applications that parse the URL and dispatch to on-disk resources
i����N(trequest(tfileapp(t
import_string(thttpexceptions(tETAG(t
converterst	NoDefaultcBseZRS((t__name__t
__module__(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRst	URLParsertStaticURLParsertPkgResourcesParsercBs�eZdZiZeZiZeeedd�Zd�Z	d�Z
dd�Zd�Zd�Z
d�Zd�Zee�Zd	�Zd
�Zd�ZRS(
s	
    WSGI middleware

    Application dispatching, based on URL.  An instance of `URLParser` is
    an application that loads and delegates to other applications.  It
    looks for files in its directory that match the first part of
    PATH_INFO; these may have an extension, but are not required to have
    one, in which case the available files are searched to find the
    appropriate file.  If it is ambiguous, a 404 is returned and an error
    logged.

    By default there is a constructor for .py files that loads the module,
    and looks for an attribute ``application``, which is a ready
    application object, or an attribute that matches the module name,
    which is a factory for building applications, and is called with no
    arguments.

    URLParser will also look in __init__.py for special overrides.
    These overrides are:

    ``urlparser_hook(environ)``
        This can modify the environment.  Its return value is ignored,
        and it cannot be used to change the response in any way.  You
        *can* use this, for example, to manipulate SCRIPT_NAME/PATH_INFO
        (try to keep them consistent with the original URL -- but
        consuming PATH_INFO and moving that to SCRIPT_NAME is ok).

    ``urlparser_wrap(environ, start_response, app)``:
        After URLParser finds the application, it calls this function
        (if present).  If this function doesn't call
        ``app(environ, start_response)`` then the application won't be
        called at all!  This can be used to allocate resources (with
        ``try:finally:``) or otherwise filter the output of the
        application.

    ``not_found_hook(environ, start_response)``:
        If no file can be found (*in this directory*) to match the
        request, then this WSGI application will be called.  You can
        use this to change the URL and pass the request back to
        URLParser again, or on to some other application.  This
        doesn't catch all ``404 Not Found`` responses, just missing
        files.

    ``application(environ, start_response)``:
        This basically overrides URLParser completely, and the given
        application is used for all requests.  ``urlparser_wrap`` and
        ``urlparser_hook`` are still called, but the filesystem isn't
        searched in any way.
    c
Ks�|r%ddl}	|	jdt�ni}tjjdkrX|jtjjd�}n||_||_|t	kr�|j
dd�}ntj|�|_
|t	kr�|j
d
d�}ntj|�|_|t	kr�|j
dd�}ntj|�|_|jj�|_|r.|jj|�nx�|j�D]~\}
}|
jd�sotd|
|f��n|
td�j�}t|ttf�r�tj|�}n||j|<q;WdS(s�
        Create a URLParser object that looks at `directory`.
        `base_python_name` is the package that this directory
        represents, thus any Python modules in this directory will
        be given names under this package.
        i����NsfThe global_conf argument to URLParser is deprecated; either pass in None or {}, or use make_url_parsert/tindex_namestindextIndextmaintMainthide_extensionss.pycs.baks.py~s.pyotignore_extensionssconstructor s]Only extra configuration keys allowed are 'constructor .ext = import_expr'; you gave %r (=%r)(sindexRsmainR(s.pycs.baks.py~s.pyo((twarningstwarntDeprecationWarningtostpathtseptreplacet	directorytbase_python_nameRtgetRtaslistR
RRtglobal_constructorstcopytconstructorstupdatetitemst
startswitht
ValueErrortlentstript
isinstancetstrtunicodeRteval_import(
tselftglobal_confRRR
RRR!tconstructor_confRtnametvaluetext((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyt__init__VsD

		c
Cs
|j|d<|jtkr1|j|�|_n|jdd�}|sY|j||�S|jr�t|jdd�r�|jj|�n|d}|d}|j	|�\}}|s�|jr#t|jdd�r#|jd�|k	r#|jj
}||d<||d<||d<|||�S|dkr�tj|d�\}	}
|	spdd	j
|jpfd
g�}	n|j||d|	|jf�S|djd
|�|j||d||jf�Sn|jr�t|jdd�r�|jj|||�S|||�SdS(Ns paste.urlparser.base_python_namet	PATH_INFOtturlparser_hooktSCRIPT_NAMEtnot_found_hooks paste.urlparser.not_found_parsers	one of %ss, s(no index_names defined)s"Tried to load %s from directory %sswsgi.errorss7Found resource %s, but could not construct application
turlparser_wrap(Rtinit_moduleRtfind_init_moduleRt	add_slashtgetattrtNoneR5tfind_applicationR7Rtpath_info_splittjoinR
t	not_foundRtwriteR8(R,tenvirontstart_responset	path_infotorig_path_infotorig_script_nametapplicationtfilenameR7R/trest_of_path((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyt__call__�sV
	

	



		
		
cCs-|jrVt|jdd�rV|jd�|dkrV|d|d<|jjdfStj|d�\}}||d<|dk	r�|jdd�d||d<n|s�|j}xE|D]"}|j||�}|r�Pq�q�Wd}n|j||�}|dkrd|fS|j	||�|fSdS(NRHs paste.urlparser.init_applicationR6R3R4R(
R9R<R=RRHRR?R
t	find_filetget_application(R,RCR/RJtnamest
index_nameRI((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR>�s(	
!	
	
cCs2tjdtj|�d|�}|j||�S(Ns%The resource at %s could not be foundtcomment(RtHTTPNotFoundRt
construct_urltwsgi_application(R,RCRDt
debug_messagetexc((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRA�s
	cCsutj|dt�}|d7}|jd�rC|d|d7}ntjd|dd|fg�}|j||�S(s^
        This happens when you try to get to a directory
        without a trailing /
        twith_query_stringRtQUERY_STRINGt?sFThe resource has moved to %s - you should be redirected automatically.theaderstlocation(RRRtFalseRRtHTTPMovedPermanentlyRS(R,RCRDturlRU((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR;�s
cCs$g}x�tj|j�D]�}tjj|�\}}tjj|j|�}||jks|rkqn||kr�|j|�qn||jkr�qn||kr|j|�qqW|s�dSt
|�dkr||kr�|S|djdtj
|�dj|�f�dS|dS(Niswsgi.errorss$Ambiguous URL: %s; matches files %s
s, i(RtlistdirRRtsplitextR@RtappendRR=R&RBRRR(R,RCt
base_filenametpossibleRItbaseR1t
full_filename((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRL�s2

cCs�tjj|�rd}ntjj|�d}|jj||jjd��}|dkrb|S||||�}|dkr�n|S(Ntdirit*(RRtisdirR_R!RR=(R,RCRItttconstructortapp((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRMs	!cCsD|j}|j|�s6td||||f��|||<dS(s�
        Register a function as a constructor.  Registered constructors
        apply to all instances of `URLParser`.

        The extension should have a leading ``.``, or the special
        extensions ``dir`` (for directories) and ``*`` (a catch-all).

        `constructor` must be a callable that takes two arguments:
        ``environ`` and ``filename``, and returns a WSGI application.
        saA constructor already exists for the extension %r (%r) when attemption to register constructor %rN(Rthas_keytAssertionError(tclst	extensionRitd((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytregister_constructor!s
	cCszy|j||fSWn^tk
ru|ji||d|jd|jd|jd|j�}||j||f<|SXdS(s�
        Get a parser for the given directory, or create one if
        necessary.  This way parsers can be cached and reused.

        # @@: settings are inherited from the first caller
        R
RRR!N(tparsers_by_directorytKeyErrort	__class__R
RRR!(R,RRtparser((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyt
get_parser4s
				cCs;tjj|jd�}tjj|�s.dSt||�S(Ns__init__.py(RRR@RtexistsR=tload_module(R,RCRI((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR:HscCs2d|jj|j|jttt|���fS(Ns"<%s directory=%r; module=%s at %s>(RsRRRthextabstid(R,((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyt__repr__Ns
	N(RRt__doc__RqRR9RR=R2RKR>RAR;RLRMRptclassmethodRuR:R{(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR	s&21	0			#				cCsO|d}|r-|dtjj|�7}ntjj|�}|j||�S(Ns paste.urlparser.base_python_namet.(RRtbasenameRu(RtRCRIR((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytmake_directoryUs

RecCs
tj|�S(N(RtFileApp(RtRCRI((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytmake_unknown_sRfcCsZ|d}tjjtjj|��d}|rC|d|}nt||||d�S(Ns paste.urlparser.base_python_nameiR~swsgi.errors(RRR_Rtload_module_from_name(RCRIRtmodule_name((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRwds
"cCs�tjj|�rtj|Stjjtjj|�d�}tjj|�s�yt|d�}Wn=t	t
fk
r�}|jdtjj|�|f�dSX|jd�|j
�nd}tjj|�r�tj|Sd|kr?dj|jd�d �}|jd�d}	t|tjj|�||�}
n|}	d}zFtj|	tjj|�g�\}}}tj||||�}
Wd|dk	r�|j
�nX|
S(Ns__init__.pytws5Cannot write __init__.py file into directory %s (%s)
s#
R~i����(tsystmodulesRkRRR@tdirnameRvtopentOSErrortIOErrorRBR=tclosetsplitR�timptfind_moduleRw(RCRIR�terrorst
init_filenametftetfptparent_namet	base_nametparenttpathnametstufftmodule((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR�ls<!

$cCs�t||�}|sdSt|d�rG|jrGt|jd|j�S|jjd�d}t||�r�t||�}t|d�r�|jSt||��Sn|djd||f�dS(NRHRSR~i����swsgi.errorss'Cound not find application or %s in %s
(	RwR=thasattrRHR<RR�RSRB(RtRCRIR�R�tobj((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytmake_py�s
s.pycBskeZdZd	d	d�Zd�Zee�Zd�Zd�Zd�Z	d	d�Z
d�Zd�ZRS(
s�
    Like ``URLParser`` but only serves static files.

    ``cache_max_age``:
      integer specifies Cache-Control max_age in seconds
    cCs7|j|�|_|j|p!|�|_||_dS(N(tnormpathRtroot_directoryt
cache_max_age(R,RR�R�((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR2�scCstjjtjj|��S(N(RRtnormcasetabspath(R((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR��sc
Cs�|jdd�}|s(|j||�S|dkr=d}ntj|�}|jtjj|j|��}|j	|j
�s�|j||�Stjj|�s�|j||�Stjj
|�r�|j|d|j
d|j�||�S|jd�r|jd�dkr|j||�S|jd�}|r�tj|�j}t|�|kr�g}tj||�|d|�dgSn|j|�}	|jr�|	jd	|j�n|	||�S(
NR3R4Rs
index.htmlR�R�tHTTP_IF_NONE_MATCHs304 Not Modifiedtmax_age(RR;Rt
path_info_popR�RRR@RR$R�RARvRgRsR�terror_extra_pathtstattst_mtimeR)RR"tmake_appt
cache_control(
R,RCRDRERItfullt
if_none_matchtmytimeRYtfa((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRK�s:	!$

	cCs
tj|�S(N(RR�(R,RI((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR��scCsutj|dt�}|d7}|jd�rC|d|d7}ntjd|dd|fg�}|j||�S(s^
        This happens when you try to get to a directory
        without a trailing /
        RVRRWRXsFThe resource has moved to %s - you should be redirected automatically.RYRZ(RRRR[RRR\RS(R,RCRDR]RU((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR;�s
c	Cs]tjdtj|�dd|jd�|jd�|j|pCdf�}|j||�S(Ns%The resource at %s could not be foundRPs6SCRIPT_NAME=%r; PATH_INFO=%r; looking in %r; debug: %sR6R3s(none)(RRQRRRRRRS(R,RCRDRTRU((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRA�scCs'tjd|d�}|j||�S(Ns#The trailing path %r is not allowedR3(RRQRS(R,RCRDRU((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR��scCsd|jj|jfS(Ns<%s %r>(RsRR(R,((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR{�sN(
RRR|R=R2R�tstaticmethodRKR�R;RAR�R{(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR
�s		&				cCs+|dk	rt|�}nt|d|�S(s�
    Return a WSGI application that serves a directory (configured
    with document_root)

    cache_max_age - integer specifies CACHE_CONTROL max_age in seconds
    R�N(R=tintR
(R-t
document_rootR�((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytmake_static�scBs5eZddd�Zd�Zd�Zdd�ZRS(cCs�tdkrtd��nt|ttf�rEtj|�|_n	||_||_|dkrrtj	�}n||_
|dkr�|}ntjj
|�|_dS(Ns"This class requires pkg_resources.(t
pkg_resourcesR=tNotImplementedErrorR(R)R*tget_distributionteggt
resource_nametResourceManagertmanagerRRR�t
root_resource(R,tegg_or_specR�R�R�((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR2
s				cCs d|jj|jj|jfS(Ns<%s for %s:%r>(RsRR�tproject_nameR�(R,((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyR{s		c
Cs�|jdd�}|s(|j||�S|dkr=d}ntj|�}tjjtjj|jd|��}|j	dk	r�|j|j	�r�|j||�S|j
j|�s�|j||�S|j
j|�r$|j	dk	r�|j	p�|j}|j|j
||jd|�||�S|jd�rX|jd�dkrX|j||�Stj|�\}}|s|d}ny|j
j|j|�}	Wn9ttfk
r�}
tjd|
�}|j||�SX|dd	|fg�tj|	�S(
NR3R4Rs
index.htmlR�sapplication/octet-streams,You are not permitted to view this file (%s)s200 OKscontent-type(RR;RR�RRR�R�R�R�R=R$RAR�thas_resourcetresource_isdirRsR�R�t	mimetypest
guess_typetget_resource_streamR�R�Rt
HTTPForbiddenRSRt	_FileIter(R,RCRDRERItresourcet
child_rootttypetencodingtfileR�RU((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRK"s>	"	$	
c
Csctjdtj|�dd|jd�|jd�|j|j|pIdf�}|j||�S(Ns%The resource at %s could not be foundRPs=SCRIPT_NAME=%r; PATH_INFO=%r; looking in egg:%s#%r; debug: %sR6R3s(none)(RRQRRRRR�R�RS(R,RCRDRTRU((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRAIsN(RRR=R2R{RKRA(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyRs		'R4cCs(tdkrtd��nt||�S(s
    A static file parser that loads data from an egg using
    ``pkg_resources``.  Takes a configuration value ``egg``, which is
    an egg spec, and a base ``resource_name`` (default empty string)
    which is the path in the egg that this starts at.
    s%This function requires pkg_resources.N(R�R=R�R(R-R�R�((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytmake_pkg_resourcesRscKs�|dkr!|jdd�}ntj|�}|dkrQ|jdd
�}ntj|�}|dkr�|jd
d�}ntj|�}ti||d|d|d
||�S(s�
    Create a URLParser application that looks in ``directory``, which
    should be the directory for the Python package named in
    ``base_python_name``.  ``index_names`` are used when viewing the
    directory (like ``'index'`` for ``'index.html'``).
    ``hide_extensions`` are extensions that are not viewable (like
    ``'.pyc'``) and ``ignore_extensions`` are viewable but only if an
    explicit extension is given.
    R
RRRRRs.pyctbakspy~RN(sindexsIndexsmainsMain(s.pycR�spy~((R=RRRR	(R-RRR
RRR.((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pytmake_url_parser]s"
( R|RR�R�R�R�tImportErrorR=tpasteRRt
paste.utilRRthttpheadersRRtobjectRt__all__R	R�RpR�RwR�R�R
R�RR�R�(((s@/opt/alt/python27/lib/python2.7/site-packages/paste/urlparser.pyt<module>s@

�;				"	\G

Zerion Mini Shell 1.0