Ńň ”eIc @s…dZddkZddkZdefd„ƒYZed„ZddklZddk l Z l Z l Z dd d d d gZ dS( sEProvides common classes and functions most users will want access to.i˙˙˙˙Nt_RequestConfigcBs>eZdZeiƒZd„Zd„Zd„Zd„Z RS(sÁ RequestConfig thread-local singleton The Routes RequestConfig object is a thread-local singleton that should be initialized by the web framework that is utilizing Routes. cCst|i|ƒS(N(tgetattrt_RequestConfig__shared_state(tselftname((s3/usr/lib/python2.6/site-packages/routes/__init__.pyt __getattr__ scCsA|djo!|i|ƒ|ii||ƒS|ii||ƒS(sq If the name is environ, load the wsgi envion with load_wsgi_environ and set the environ tenviron(tload_wsgi_environRt __setattr__(RRtvalue((s3/usr/lib/python2.6/site-packages/routes/__init__.pyRs  cCst|i|ƒdS(N(tdelattrR(RR((s3/usr/lib/python2.6/site-packages/routes/__init__.pyt __delattr__sc CsÚd|jp,|idƒdjp|idƒdjod|i_n d|i_y||i_Wntj onXy€d|joo|i}|d}|i|ƒ}|dj o$|d|i_|d|i_ qúd|i_d|i_ nWntj onXd |jo|d |i_ nĽd |jo|d |i_ n„|d |i_ |ddjo3|d d jo|ii d|d 7_ qÖn0|d djo|ii d|d 7_ ndS(sË Load the protocol/server info from the environ and store it. Also, match the incoming URL if there's already a mapper, and store the resulting match dict in mapper_dict. tHTTPSswsgi.url_schemethttpstHTTP_X_FORWARDED_PROTOthttpt PATH_INFOiitHTTP_X_FORWARDED_HOSTt HTTP_HOSTt SERVER_NAMEt SERVER_PORTt443t:t80N( tgetRtprotocoltmapperRtAttributeErrort routematchtNonet mapper_dicttroutethost(RRRtpathtresult((s3/usr/lib/python2.6/site-packages/routes/__init__.pyRs<#        "( t__name__t __module__t__doc__tthreadinglocaltlocalRRRR R(((s3/usr/lib/python2.6/site-packages/routes/__init__.pyRs    cCsdtƒ}y,|io|tjot|dƒƒSWn%tj ot|_t|_nXtƒS(sy Returns the Routes RequestConfig object. To get the Routes RequestConfig: >>> from routes import * >>> config = request_config() The following attributes must be set on the config object every request: mapper mapper should be a Mapper instance thats ready for use host host is the hostname of the webapp protocol protocol is the protocol of the current request mapper_dict mapper_dict should be the dict returned by mapper.match() redirect redirect should be a function that issues a redirect, and takes a url as the sole argument prefix (optional) Set if the application is moved under a URL prefix. Prefix will be stripped before matching, and prepended on generation environ (optional) Set to the WSGI environ for automatic prefix support if the webapp is underneath a 'SCRIPT_NAME' Setting the environ will use information in environ to try and populate the host/protocol/mapper_dict options if you've already set a mapper. **Using your own requst local** If you have your own request local object that you'd like to use instead of the default thread local provided by Routes, you can configure Routes to use it:: from routes import request_config() config = request_config() if hasattr(config, 'using_request_local'): config.request_local = YourLocalCallable config = request_config() Once you have configured request_config, its advisable you retrieve it again to get the object you wanted. The variable you assign to request_local is assumed to be a callable that will get the local config object you wish. This example tests for the presence of the 'using_request_local' attribute which will be present if you haven't assigned it yet. This way you can avoid repeat assignments of the request specific callable. Should you want the original object, perhaps to change the callable its using or stop this behavior, call request_config(original=True). t request_local(RR(tFalseRRtusing_request_local(toriginaltobj((s3/usr/lib/python2.6/site-packages/routes/__init__.pytrequest_configJs7  (tMapper(t redirect_toturl_fort URLGeneratorR.R0R1R/R-(R%R&tsystobjectRR)R-t routes.mapperR.t routes.utilR/R0R1t__all__(((s3/usr/lib/python2.6/site-packages/routes/__init__.pyts F @