Ńņ ÷Ń{Ic @s³ddkZddkZddkZddkZeidjoddklZnddkl Z ddk l Z l Z l Z ddklZd„Zdefd „ƒYZdS( i’’’’Ns2.4(t ImmutableSet(trequest_config(tcontroller_scantMatchExceptiontRoutesException(tRoutecCs@|idƒo|d}n|idƒo|d }n|S(s8Remove slashes from the beginning and end of a part/URL.t/ii’’’’(t startswithtendswith(tname((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt strip_slashess tMappercBs°eZdZeeeeed„Zd„Zd„Z d„Z e ee e ƒZ d„Z d„Zd„Zed„Zd „Zd „Zd „Zd „Zd „Zd„ZRS(s|Mapper handles URL generation and URL recognition in a web application. Mapper is built handling dictionary's. It is assumed that the web application will handle the dictionary returned by URL recognition to dispatch appropriately. URL generation is done by passing keyword parameters into the generate function, a URL is then returned. cCsg|_h|_h|_h|_t|_t|_d|_t i ƒ|_ ||_ ||_ ||_d|_h|_t|_t|_t|_g|_d|_||_d|_d|_t|_t|_tiƒ|_|otƒ}||_ ndS(sv Create a new Mapper instance All keyword arguments are optional. ``controller_scan`` Function reference that will be used to return a list of valid controllers used during URL matching. If ``directory`` keyword arg is present, it will be passed into the function during its call. This option defaults to a function that will scan a directory for controllers. ``directory`` Passed into controller_scan for the directory to scan. It should be an absolute path if using the default ``controller_scan`` function. ``always_scan`` Whether or not the ``controller_scan`` function should be run during every URL match. This is typically a good idea during development so the server won't need to be restarted anytime a controller is added. ``register`` Boolean used to determine if the Mapper should use ``request_config`` to register itself as the mapper. Since it's done on a thread-local basis, this is typically best used during testing though it won't hurt in other cases. ``explicit`` Boolean used to determine if routes should be connected with implicit defaults of:: {'controller':'content','action':'index','id':None} When set to True, these defaults will not be added to route connections and ``url_for`` will not use Route memory. Additional attributes that may be set after mapper initialization (ie, map.ATTRIBUTE = 'something'): ``encoding`` Used to indicate alternative encoding/decoding systems to use with both incoming URL's, and during Route generation when passed a Unicode string. Defaults to 'utf-8'. ``decode_errors`` How to handle errors in the encoding, generally ignoring any chars that don't convert should be sufficient. Defaults to 'ignore'. ``minimization`` Boolean used to indicate whether or not Routes should minimize URL's and the generated URL's, or require every part where it appears in the path. Defaults to True. ``hardcode_names`` Whether or not Named Routes result in the default options for the route being used *or* if they actually force url generation to use the route. Defaults to False. s[^\.\/]+?\.[^\.\/]+sutf-8tignoreN(!t matchlisttmaxkeystminkeysturlcachetFalset _created_regst _created_genstNonetprefixtthreadinglocaltlocaltreq_datat directoryt always_scanRt _regprefixt _routenamestdebugt append_slasht sub_domainstsub_domains_ignoret domain_matchtexplicittencodingt decode_errorstTruethardcode_namest minimizationt threadingtLocktcreate_regs_lockRtmapper(tselfRRRtregisterR"tconfig((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt__init__#s6?                       cCs)y|iiSWntj odSXdS(N(RtenvirontAttributeErrorR(R,((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt_envget~scCs||i_dS(N(RR0(R,tenv((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt_envsetƒscCs |i`dS(N(RR0(R,((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt_envdel…scOs‡d}t|ƒdjo|d}|d}nd|jo|i|d    / cOs6|iiƒz|i||ŽWd|iiƒXdS(sPAtomically creates regular expressions for all connected routes N(R*tacquiret _create_regstrelease(R,R<tkwargs((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt create_regsēs cCsÆ|djo0|io|i|iƒ}q=|iƒ}nx;|iiƒD]*\}}x|D]}|i|ƒq`WqMW|ioti|idƒ|_ nt |_ dS(s4Creates regular expressions for all connected routess(.*)N( RRRRt iteritemst makeregexpRtretcompileRR%R(R,RPRAtvalR?((s1/usr/lib/python2.6/site-packages/routes/mapper.pyRUńs    c Csœ|i o|io|iƒn|iptdƒ‚n|io|iƒng}|ioTti|i|ƒo-ti |id|ƒ}|p d}qµq¹dd|fSn|i }|i }|i }|i}|i}x¦|iD]›}|io.|o |itd|dtƒƒqšqšn|i|||||ƒ} |o&|itd|dt| ƒƒƒn| o| ||fSqšWdd|fS(sInternal Route matcher Matches a URL against a route, and returns a tuple of the match dict and the route object if a match is successfull, otherwise it returns empty. For internal use only. s:You must generate the regular expressions before matching.s\1RR?R:tregexpN(RRRXRRRR[tmatchRtsubRR0RR R!RR R:R;tdictR%tbool( R,turltmatchlogR0RR R!RR?R_((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt_matchs>             &cCsb|ptdƒ‚n|i|ƒ}|io|d|d|dfS|do |dSdS(sīMatch a URL against against one of the routes contained. Will return None if no valid match is found. .. code-block:: python resultdict = m.match('/joe/sixpack') s;No URL provided, the minimum URL necessary to match is "/".iiiN(RReRR(R,Rctresult((s1/usr/lib/python2.6/site-packages/routes/mapper.pyR_0s    cCsU|i|ƒ}|io|d|d|dfS|do|d|dfSdS(s5Match a URL against against one of the routes contained. Will return None if no valid match is found, otherwise a result dict and a route object is returned. .. code-block:: python resultdict, route_obj = m.match('/joe/sixpack') iiiN(ReRR(R,RcRf((s1/usr/lib/python2.6/site-packages/routes/mapper.pyt routematchEs   c sŚ|ip|iƒn|iot|d/:_id". If ``parent_resource`` is supplied and ``name_prefix`` isn't, ``name_prefix`` will be generated from ``parent_resource`` as "_". Example:: >>> from routes.util import url_for >>> m = Mapper() >>> m.resource('location', 'locations', ... parent_resource=dict(member_name='region', ... collection_name='regions')) >>> # path_prefix is "regions/:region_id" >>> # name prefix is "region_" >>> url_for('region_locations', region_id=13) '/regions/13/locations' >>> url_for('region_new_location', region_id=13) '/regions/13/locations/new' >>> url_for('region_location', region_id=13, id=60) '/regions/13/locations/60' >>> url_for('region_edit_location', region_id=13, id=60) '/regions/13/locations/60/edit' Overriding generated ``path_prefix``:: >>> m = Mapper() >>> m.resource('location', 'locations', ... parent_resource=dict(member_name='region', ... collection_name='regions'), ... path_prefix='areas/:area_id') >>> # name prefix is "region_" >>> url_for('region_locations', area_id=51) '/areas/51/locations' Overriding generated ``name_prefix``:: >>> m = Mapper() >>> m.resource('location', 'locations', ... parent_resource=dict(member_name='region', ... collection_name='regions'), ... name_prefix='') >>> # path_prefix is "regions/:region_id" >>> url_for('locations', region_id=51) '/regions/51/locations' t collectiontmembertnewt path_prefixt name_prefixtparent_resources %s/:%s_idtcollection_namet member_names%s_RmtGETteditcSs@x9|iƒD]+\}}|i|iƒgƒi|ƒq W|S(siSwap the keys and values in the dict, and uppercase the values from the dict during the swap.(RYRKtupperR;(tdcttnewdctRAR]((s1/usr/lib/python2.6/site-packages/routes/mapper.pytswaps #tPOSTitcreatetPUTtupdatetDELETEtdeleteRs/news/:(id)RCt _member_namet_collection_namet_parent_resourcecs;ˆiƒ}ˆdjoh|iƒgd6|ds