Ñò jž³Kc@s´dZddkZddkZddkZddkZyddkZWnej o eZnXddkl Z ddkl Z ddk l Z ddkl Z ddklZddk lZd efd „ƒYZd d d gZd efd„ƒYZd„Zeideƒd„Zeideƒd„Zd„Zd„Zeideƒ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__(((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRst URLParsertStaticURLParsertPkgResourcesParsercBsžeZdZhZeZhZeeed d„Zd„Z d„Z d d„Z d„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Ñ|o ddk} | idtƒnh}tiidjo|itiidƒ}n||_||_|t jo|i ddƒ}nt i |ƒ|_ |t jo|i d dƒ}nt i |ƒ|_|t jo|i ddƒ}nt i |ƒ|_|iiƒ|_|o|ii|ƒnx|iƒD]‚\} } | idƒptd| | fƒ‚n| tdƒiƒ} t| ttfƒoti| ƒ} n| |i| ¼s*   "     cCs2tidti|ƒd|ƒ}|i||ƒS(Ns%The resource at %s could not be foundtcomment(Rt HTTPNotFoundRt construct_urltwsgi_application(R,RCRDt debug_messagetexc((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRAÖs  cCswti|dtƒ}|d7}|idƒo|d|d7}ntid|dd|fgƒ}|i||ƒ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((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR;Ýs cCs3g}x¿ti|iƒD]«}tii|ƒ\}}tii|i|ƒ}||ijp| oqn||jo|i|ƒqn||ijoqn||jo|i|ƒqqW|pdSt |ƒdjoD||jo|S|di dt i |ƒdi|ƒfƒdS|dS(Nis wsgi.errorss$Ambiguous URL: %s; matches files %s s, i(RtlistdirRRtsplitextR@RtappendRR=R&RBRRR(R,RCt base_filenametpossibleRItbaseR1t full_filename((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRLìs4      cCstii|ƒo d}ntii|ƒd}|ii||iidƒƒ}|djo|S||||ƒ}|djon|S(Ntdirit*(RRtisdirR_R!RR=(R,RCRIttt constructortapp((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRMs !  cCsC|i}|i|ƒ ptd||||f‚|||(RsRRRthextabstid(R,((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyt__repr__Ns  N(RRt__doc__RqRR9RR=R2RKR>RAR;RLRMRpt classmethodRuR:R{(((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR s&2 1 0    #     cCsQ|d}|o|dtii|ƒ7}ntii|ƒ}|i||ƒS(Ns paste.urlparser.base_python_namet.(RRtbasenameRu(RtRCRIR((s3/usr/lib/python2.6/site-packages/paste/urlparser.pytmake_directoryUs  RecCs ti|ƒS(N(RtFileApp(RtRCRI((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyt make_unknown_sRfcCs\|d}tiitii|ƒƒd}|o|d|}nt||||dƒS(Ns paste.urlparser.base_python_nameiR~s wsgi.errors(RRR_Rtload_module_from_name(RCRIRt module_name((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRwds  " c Cs¾tii|ƒo ti|Stiitii|ƒdƒ}tii|ƒppyt|dƒ}Wn?t t fj o-}|i dtii|ƒ|fƒdSX|i dƒ|i ƒnd}tii|ƒo ti|Sd|joTdi|idƒd ƒ}|idƒd} t|tii|ƒ||ƒ} n|} d}zFti| tii|ƒgƒ\}} } ti||| | ƒ} Wd|dj o|i ƒnX| S(Ns __init__.pytws5Cannot write __init__.py file into directory %s (%s) s# R~iÿÿÿÿ(tsystmodulesRkRRR@tdirnameRvtopentOSErrortIOErrorRBR=tclosetsplitRƒtimpt find_moduleRw(RCRIR„terrorst init_filenametftetfpt parent_namet base_nametparenttpathnametstufftmodule((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRƒls< !   $ cCsÌt||ƒ}|pdSt|dƒo!|iot|id|iƒS|iidƒd}t||ƒo;t||ƒ}t|dƒo|iSt||ƒƒSn|did||fƒdS(NRHRSR~iÿÿÿÿs wsgi.errorss'Cound not find application or %s in %s ( RwR=thasattrRHR<RRRSRB(RtRCRIRšR–tobj((s3/usr/lib/python2.6/site-packages/paste/urlparser.pytmake_pyŽs s.pycBskeZdZd d d„Zd„ZeeƒZd„Zd„Zd„Z d d„Z d„Z d„Z RS( s‹ Like ``URLParser`` but only serves static files. ``cache_max_age``: integer specifies Cache-Control max_age in seconds cCs8|i|ƒ|_|i|p|ƒ|_||_dS(N(tnormpathRtroot_directoryt cache_max_age(R,RRŸR ((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR2¬scCstiitii|ƒƒS(N(RRtnormcasetabspath(R((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRž²sc CsÓ|iddƒ}|p|i||ƒS|djo d}nti|ƒ}|itii|i|ƒƒ}|i |i ƒp|i ||ƒStii |ƒp|i ||ƒStii |ƒo)|i|d|i d|iƒ||ƒS|idƒo'|idƒdjo|i||ƒS|idƒ}|oTti|ƒi}t|ƒ|jo+g}ti||ƒ|d|ƒdgSn|i|ƒ} |io| id |iƒ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((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRK¶s:  ! &   cCs ti|ƒS(N(RR(R,RI((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR©ÜscCswti|dtƒ}|d7}|idƒo|d|d7}ntid|dd|fgƒ}|i||ƒ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((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR;ßs cCs^tidti|ƒdd|idƒ|idƒ|i|pdfƒ}|i||ƒS(Ns%The resource at %s could not be foundRPs6SCRIPT_NAME=%r; PATH_INFO=%r; looking in %r; debug: %sR6R3s(none)(RRQRRRRRRS(R,RCRDRTRU((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRAîscCs'tid|dƒ}|i||ƒS(Ns#The trailing path %r is not allowedR3(RRQRS(R,RCRDRU((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR¦÷scCsd|ii|ifS(Ns<%s %r>(RsRR(R,((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR{üsN( RRR|R=R2Ržt staticmethodRKR©R;RAR¦R{(((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR £s    &   cCs-|dj ot|ƒ}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 ((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyt make_staticÿs cBs5eZddd„Zd„Zd„Zdd„ZRS(cCs±tdjotdƒ‚nt|ttfƒoti|ƒ|_n ||_||_|djoti ƒ}n||_ |djo |}nt i i |ƒ|_dS(Ns"This class requires pkg_resources.(t pkg_resourcesR=tNotImplementedErrorR(R)R*tget_distributionteggt resource_nametResourceManagertmanagerRRRžt root_resource(R,t egg_or_specR·R¹Rº((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR2 s       cCs d|ii|ii|ifS(Ns<%s for %s:%r>(RsRR¶t project_nameR·(R,((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR{s  c Cs |iddƒ}|p|i||ƒS|djo d}nti|ƒ}tiitii|id|ƒƒ}|i dj o%|i |i ƒ o|i ||ƒS|i i|ƒp|i ||ƒS|i i|ƒoL|i dj o |i p|i}|i|i ||id|ƒ||ƒS|idƒo'|idƒdjo|i||ƒSti|ƒ\}}|p d}ny|i i|i|ƒ} Wn;ttfj o)} tid| ƒ} | i||ƒSX|dd |fgƒti| ƒ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((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRK"s>  $ &  c Csdtidti|ƒdd|idƒ|idƒ|i|i|pdfƒ}|i||ƒ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((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyRAIs N(RRR=R2R{RKRA(((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyR s  'R4cCs*tdjotdƒ‚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·((s3/usr/lib/python2.6/site-packages/paste/urlparser.pytmake_pkg_resourcesRs c Ks»|d jo|idd ƒ}nti|ƒ}|d jo|idd ƒ}nti|ƒ}|d jo|id dƒ}nti|ƒ}th||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.((s3/usr/lib/python2.6/site-packages/paste/urlparser.pytmake_url_parser]s"   ( R|RR†RŽR¿R³t ImportErrorR=tpasteRRt paste.utilRRt httpheadersRRtobjectRt__all__R R€RpR‚RwRƒRR R²R RÉRË(((s3/usr/lib/python2.6/site-packages/paste/urlparser.pyts@     ÿ;    " \ G