<s> """<STR_LIT>""" <EOL> import os <EOL> import re <EOL> import logging <EOL> import traceback <EOL> import threading <EOL> import urllib <EOL> from gluon . storage import Storage , List <EOL> from gluon . http import HTTP <EOL> from gluon . fileutils import abspath , read_file <EOL> from gluon . settings import global_settings <EOL> isdir = os . path . isdir <EOL> isfile = os . path . isfile <EOL> exists = os . path . exists <EOL> pjoin = os . path . join <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> THREAD_LOCAL = threading . local ( ) <EOL> regex_at = re . compile ( r'<STR_LIT>' ) <EOL> regex_anything = re . compile ( r'<STR_LIT>' ) <EOL> regex_redirect = re . compile ( r'<STR_LIT>' ) <EOL> regex_full_url = re . compile ( <EOL> r'<STR_LIT>' ) <EOL> regex_version = re . compile ( r'<STR_LIT>' ) <EOL> regex_url = re . compile ( '<STR_LIT>' ) <EOL> regex_args = re . compile ( '<STR_LIT>' ) <EOL> def _router_default ( ) : <EOL> "<STR_LIT>" <EOL> router = Storage ( <EOL> default_application = '<STR_LIT>' , <EOL> applications = '<STR_LIT>' , <EOL> default_controller = '<STR_LIT:default>' , <EOL> controllers = '<STR_LIT>' , <EOL> default_function = '<STR_LIT:index>' , <EOL> functions = dict ( ) , <EOL> default_language = None , <EOL> languages = None , <EOL> root_static = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> map_static = None , <EOL> domains = None , <EOL> exclusive_domain = False , <EOL> map_hyphen = False , <EOL> acfe_match = r'<STR_LIT>' , <EOL> file_match = r'<STR_LIT>' , <EOL> args_match = r'<STR_LIT>' , <EOL> ) <EOL> return router <EOL> def _params_default ( app = None ) : <EOL> "<STR_LIT>" <EOL> p = Storage ( ) <EOL> p . name = app or "<STR_LIT>" <EOL> p . default_application = app or "<STR_LIT>" <EOL> p . default_controller = "<STR_LIT:default>" <EOL> p . default_function = "<STR_LIT:index>" <EOL> p . routes_app = [ ] <EOL> p . routes_in = [ ] <EOL> p . routes_out = [ ] <EOL> p . routes_onerror = [ ] <EOL> p . routes_apps_raw = [ ] <EOL> p . error_handler = None <EOL> p . error_message = '<STR_LIT>' <EOL> p . error_message_ticket = '<STR_LIT>' + ( '<STR_LIT:x>' * <NUM_LIT> ) + '<STR_LIT>' <EOL> p . routers = None <EOL> p . logging = '<STR_LIT>' <EOL> return p <EOL> params_apps = dict ( ) <EOL> params = _params_default ( app = None ) <EOL> THREAD_LOCAL . routes = params <EOL> routers = None <EOL> def log_rewrite ( string ) : <EOL> "<STR_LIT>" <EOL> if params . logging == '<STR_LIT>' : <EOL> logger . debug ( string ) <EOL> elif params . logging == '<STR_LIT>' or not params . logging : <EOL> pass <EOL> elif params . logging == '<STR_LIT>' : <EOL> print string <EOL> elif params . logging == '<STR_LIT:info>' : <EOL> logger . info ( string ) <EOL> elif params . logging == '<STR_LIT>' : <EOL> logger . warning ( string ) <EOL> elif params . logging == '<STR_LIT:error>' : <EOL> logger . error ( string ) <EOL> elif params . logging == '<STR_LIT>' : <EOL> logger . critical ( string ) <EOL> else : <EOL> logger . debug ( string ) <EOL> ROUTER_KEYS = set ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ROUTER_BASE_KEYS = set ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def fixup_missing_path_info ( environ ) : <EOL> eget = environ . get <EOL> path_info = eget ( '<STR_LIT>' ) <EOL> request_uri = eget ( '<STR_LIT>' ) <EOL> if not path_info and request_uri : <EOL> items = request_uri . split ( '<STR_LIT:?>' ) <EOL> path_info = environ [ '<STR_LIT>' ] = items [ <NUM_LIT:0> ] <EOL> environ [ '<STR_LIT>' ] = items [ <NUM_LIT:1> ] if len ( items ) > <NUM_LIT:1> else '<STR_LIT>' <EOL> elif not request_uri : <EOL> query_string = eget ( '<STR_LIT>' ) <EOL> if query_string : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' % ( path_info , query_string ) <EOL> else : <EOL> environ [ '<STR_LIT>' ] = path_info <EOL> if not eget ( '<STR_LIT>' ) : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' % ( eget ( '<STR_LIT>' ) , eget ( '<STR_LIT>' ) ) <EOL> def url_in ( request , environ ) : <EOL> "<STR_LIT>" <EOL> if routers : <EOL> return map_url_in ( request , environ ) <EOL> return regex_url_in ( request , environ ) <EOL> def url_out ( request , environ , application , controller , function , <EOL> args , other , scheme , host , port ) : <EOL> "<STR_LIT>" <EOL> if routers : <EOL> acf = map_url_out ( request , environ , application , controller , <EOL> function , args , other , scheme , host , port ) <EOL> url = '<STR_LIT>' % ( acf , other ) <EOL> else : <EOL> url = '<STR_LIT>' % ( application , controller , function , other ) <EOL> url = regex_filter_out ( url , environ ) <EOL> if host is True or ( host is None and ( scheme or port is not None ) ) : <EOL> host = request . env . http_host <EOL> if not scheme or scheme is True : <EOL> scheme = request . env . get ( '<STR_LIT>' , '<STR_LIT:http>' ) . lower ( ) if request else '<STR_LIT:http>' <EOL> if host : <EOL> host_port = host if not port else host . split ( '<STR_LIT::>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] + '<STR_LIT>' % port <EOL> url = '<STR_LIT>' % ( scheme , host_port , url ) <EOL> return url <EOL> def try_rewrite_on_error ( http_response , request , environ , ticket = None ) : <EOL> """<STR_LIT>""" <EOL> status = int ( str ( http_response . status ) . split ( ) [ <NUM_LIT:0> ] ) <EOL> if status >= <NUM_LIT> and THREAD_LOCAL . routes . routes_onerror : <EOL> keys = set ( ( '<STR_LIT>' % ( request . application , status ) , <EOL> '<STR_LIT>' % ( request . application ) , <EOL> '<STR_LIT>' % ( status ) , <EOL> '<STR_LIT>' ) ) <EOL> for ( key , uri ) in THREAD_LOCAL . routes . routes_onerror : <EOL> if key in keys : <EOL> if uri == '<STR_LIT:!>' : <EOL> return http_response , environ <EOL> elif '<STR_LIT:?>' in uri : <EOL> path_info , query_string = uri . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> query_string += '<STR_LIT:&>' <EOL> else : <EOL> path_info , query_string = uri , '<STR_LIT>' <EOL> query_string += '<STR_LIT>' % ( status , ticket , urllib . quote_plus ( <EOL> request . env . request_uri ) , request . url ) <EOL> if uri . startswith ( '<STR_LIT>' ) or uri . startswith ( '<STR_LIT>' ) : <EOL> url = path_info + '<STR_LIT:?>' + query_string <EOL> message = '<STR_LIT>' <EOL> return HTTP ( <NUM_LIT> , message % url , Location = url ) , environ <EOL> elif not environ . get ( '<STR_LIT>' , False ) : <EOL> environ [ '<STR_LIT>' ] = True <EOL> path_info = '<STR_LIT:/>' + path_info . lstrip ( '<STR_LIT:/>' ) <EOL> environ [ '<STR_LIT>' ] = path_info <EOL> environ [ '<STR_LIT>' ] = query_string <EOL> environ [ '<STR_LIT>' ] = status <EOL> return None , environ <EOL> return http_response , environ <EOL> def try_redirect_on_error ( http_object , request , ticket = None ) : <EOL> "<STR_LIT>" <EOL> status = int ( str ( http_object . status ) . split ( ) [ <NUM_LIT:0> ] ) <EOL> if status > <NUM_LIT> and THREAD_LOCAL . routes . routes_onerror : <EOL> keys = set ( ( '<STR_LIT>' % ( request . application , status ) , <EOL> '<STR_LIT>' % ( request . application ) , <EOL> '<STR_LIT>' % ( status ) , <EOL> '<STR_LIT>' ) ) <EOL> for ( key , redir ) in THREAD_LOCAL . routes . routes_onerror : <EOL> if key in keys : <EOL> if redir == '<STR_LIT:!>' : <EOL> break <EOL> elif '<STR_LIT:?>' in redir : <EOL> url = '<STR_LIT>' % ( redir , status , ticket , <EOL> urllib . quote_plus ( request . env . request_uri ) , <EOL> request . url ) <EOL> else : <EOL> url = '<STR_LIT>' % ( redir , status , ticket , <EOL> urllib . quote_plus ( request . env . request_uri ) , <EOL> request . url ) <EOL> return HTTP ( <NUM_LIT> , '<STR_LIT>' % url , Location = url ) <EOL> return http_object <EOL> def load ( routes = '<STR_LIT>' , app = None , data = None , rdict = None ) : <EOL> """<STR_LIT>""" <EOL> global params <EOL> global routers <EOL> if app is None : <EOL> global params_apps <EOL> params_apps = dict ( ) <EOL> params = _params_default ( app = None ) <EOL> THREAD_LOCAL . routes = params <EOL> routers = None <EOL> if isinstance ( rdict , dict ) : <EOL> symbols = dict ( routers = rdict ) <EOL> path = '<STR_LIT>' <EOL> else : <EOL> if data is not None : <EOL> path = '<STR_LIT>' <EOL> else : <EOL> if app is None : <EOL> path = abspath ( routes ) <EOL> else : <EOL> path = abspath ( '<STR_LIT>' , app , routes ) <EOL> if not exists ( path ) : <EOL> return <EOL> data = read_file ( path ) . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) <EOL> symbols = dict ( app = app ) <EOL> try : <EOL> exec ( data + '<STR_LIT:\n>' ) in symbols <EOL> except SyntaxError , e : <EOL> logger . error ( <EOL> '<STR_LIT>' % path <EOL> + traceback . format_exc ( ) ) <EOL> raise e <EOL> p = _params_default ( app ) <EOL> for sym in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if sym in symbols : <EOL> for items in symbols [ sym ] : <EOL> p [ sym ] . append ( compile_regex ( * items ) ) <EOL> for sym in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> if sym in symbols : <EOL> p [ sym ] = symbols [ sym ] <EOL> if '<STR_LIT>' in symbols : <EOL> p . routers = Storage ( symbols [ '<STR_LIT>' ] ) <EOL> for key in p . routers : <EOL> if isinstance ( p . routers [ key ] , dict ) : <EOL> p . routers [ key ] = Storage ( p . routers [ key ] ) <EOL> if app is None : <EOL> params = p <EOL> THREAD_LOCAL . routes = params <EOL> routers = params . routers <EOL> if isinstance ( routers , dict ) : <EOL> routers = Storage ( routers ) <EOL> if routers is not None : <EOL> router = _router_default ( ) <EOL> if routers . BASE : <EOL> router . update ( routers . BASE ) <EOL> routers . BASE = router <EOL> all_apps = [ ] <EOL> apppath = abspath ( '<STR_LIT>' ) <EOL> for appname in os . listdir ( apppath ) : <EOL> if not appname . startswith ( '<STR_LIT:.>' ) and isdir ( abspath ( apppath , appname ) ) and isdir ( abspath ( apppath , appname , '<STR_LIT>' ) ) : <EOL> all_apps . append ( appname ) <EOL> if routers : <EOL> router = Storage ( routers . BASE ) <EOL> if appname in routers : <EOL> for key in routers [ appname ] . keys ( ) : <EOL> if key in ROUTER_BASE_KEYS : <EOL> raise SyntaxError ( "<STR_LIT>" % ( key , appname ) ) <EOL> router . update ( routers [ appname ] ) <EOL> routers [ appname ] = router <EOL> if exists ( abspath ( '<STR_LIT>' , appname , routes ) ) : <EOL> load ( routes , appname ) <EOL> if routers : <EOL> load_routers ( all_apps ) <EOL> else : <EOL> params_apps [ app ] = p <EOL> if routers and p . routers : <EOL> if app in p . routers : <EOL> routers [ app ] . update ( p . routers [ app ] ) <EOL> log_rewrite ( '<STR_LIT>' % path ) <EOL> def compile_regex ( k , v , env = None ) : <EOL> """<STR_LIT>""" <EOL> k0 = k <EOL> if not k [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> k = '<STR_LIT>' % k <EOL> if not k [ - <NUM_LIT:1> ] == '<STR_LIT:$>' : <EOL> k = '<STR_LIT>' % k <EOL> if k . find ( '<STR_LIT::>' ) < <NUM_LIT:0> : <EOL> k = '<STR_LIT>' % k [ <NUM_LIT:1> : ] <EOL> if k . find ( '<STR_LIT>' ) < <NUM_LIT:0> : <EOL> i = k . find ( '<STR_LIT>' ) <EOL> if i < <NUM_LIT:0> : <EOL> raise SyntaxError ( "<STR_LIT>" % k0 ) <EOL> k = r'<STR_LIT>' % ( k [ : i ] , k [ i + <NUM_LIT:1> : ] ) <EOL> for item in regex_anything . findall ( k ) : <EOL> k = k . replace ( item , '<STR_LIT>' ) <EOL> for item in regex_at . findall ( k ) : <EOL> k = k . replace ( item , r'<STR_LIT>' % item [ <NUM_LIT:1> : ] ) <EOL> for item in regex_at . findall ( v ) : <EOL> v = v . replace ( item , r'<STR_LIT>' % item [ <NUM_LIT:1> : ] ) <EOL> return ( re . compile ( k , re . DOTALL ) , v , env or { } ) <EOL> def load_routers ( all_apps ) : <EOL> "<STR_LIT>" <EOL> for app in routers : <EOL> if app not in all_apps : <EOL> all_apps . append ( app ) <EOL> router = Storage ( routers . BASE ) <EOL> if app != '<STR_LIT>' : <EOL> keys = set ( routers [ app ] ) . intersection ( ROUTER_BASE_KEYS ) <EOL> if keys : <EOL> raise SyntaxError ( "<STR_LIT>" % ( <EOL> tuple ( keys ) , app ) ) <EOL> router . update ( routers [ app ] ) <EOL> routers [ app ] = router <EOL> router = routers [ app ] <EOL> keys = set ( router ) . difference ( ROUTER_KEYS ) <EOL> if keys : <EOL> raise SyntaxError ( "<STR_LIT>" % ( <EOL> tuple ( keys ) , app ) ) <EOL> if not router . controllers : <EOL> router . controllers = set ( ) <EOL> elif not isinstance ( router . controllers , str ) : <EOL> router . controllers = set ( router . controllers ) <EOL> if router . languages : <EOL> router . languages = set ( router . languages ) <EOL> else : <EOL> router . languages = set ( ) <EOL> if router . functions : <EOL> if isinstance ( router . functions , ( set , tuple , list ) ) : <EOL> functions = set ( router . functions ) <EOL> if isinstance ( router . default_function , str ) : <EOL> functions . add ( <EOL> router . default_function ) <EOL> router . functions = { router . default_controller : functions } <EOL> for controller in router . functions : <EOL> router . functions [ controller ] = set ( <EOL> router . functions [ controller ] ) <EOL> else : <EOL> router . functions = dict ( ) <EOL> if app != '<STR_LIT>' : <EOL> for base_only in ROUTER_BASE_KEYS : <EOL> router . pop ( base_only , None ) <EOL> if '<STR_LIT>' in router : <EOL> routers . BASE . domains [ router . domain ] = app <EOL> if isinstance ( router . controllers , str ) and router . controllers == '<STR_LIT>' : <EOL> router . controllers = set ( ) <EOL> if isdir ( abspath ( '<STR_LIT>' , app ) ) : <EOL> cpath = abspath ( '<STR_LIT>' , app , '<STR_LIT>' ) <EOL> for cname in os . listdir ( cpath ) : <EOL> if isfile ( abspath ( cpath , cname ) ) and cname . endswith ( '<STR_LIT>' ) : <EOL> router . controllers . add ( cname [ : - <NUM_LIT:3> ] ) <EOL> if router . controllers : <EOL> router . controllers . add ( '<STR_LIT>' ) <EOL> router . controllers . add ( router . default_controller ) <EOL> if isinstance ( routers . BASE . applications , str ) and routers . BASE . applications == '<STR_LIT>' : <EOL> routers . BASE . applications = list ( all_apps ) <EOL> if routers . BASE . applications : <EOL> routers . BASE . applications = set ( routers . BASE . applications ) <EOL> else : <EOL> routers . BASE . applications = set ( ) <EOL> for app in routers . keys ( ) : <EOL> router = routers [ app ] <EOL> router . name = app <EOL> router . _acfe_match = re . compile ( router . acfe_match ) <EOL> router . _file_match = re . compile ( router . file_match ) <EOL> if router . args_match : <EOL> router . _args_match = re . compile ( router . args_match ) <EOL> if router . path_prefix : <EOL> if isinstance ( router . path_prefix , str ) : <EOL> router . path_prefix = router . path_prefix . strip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) <EOL> domains = dict ( ) <EOL> if routers . BASE . domains : <EOL> for ( d , a ) in routers . BASE . domains . iteritems ( ) : <EOL> ( domain , app ) = ( d . strip ( '<STR_LIT::>' ) , a . strip ( '<STR_LIT:/>' ) ) <EOL> if '<STR_LIT::>' in domain : <EOL> ( domain , port ) = domain . split ( '<STR_LIT::>' ) <EOL> else : <EOL> port = None <EOL> if '<STR_LIT:/>' in app : <EOL> ( app , ctlr ) = app . split ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> else : <EOL> ctlr = None <EOL> if ctlr and '<STR_LIT:/>' in ctlr : <EOL> ( ctlr , fcn ) = ctlr . split ( '<STR_LIT:/>' ) <EOL> else : <EOL> fcn = None <EOL> if app not in all_apps and app not in routers : <EOL> raise SyntaxError ( "<STR_LIT>" % app ) <EOL> domains [ ( domain , port ) ] = ( app , ctlr , fcn ) <EOL> routers . BASE . domains = domains <EOL> def regex_uri ( e , regexes , tag , default = None ) : <EOL> "<STR_LIT>" <EOL> path = e [ '<STR_LIT>' ] <EOL> host = e . get ( '<STR_LIT>' , e . get ( '<STR_LIT>' , '<STR_LIT:localhost>' ) ) . lower ( ) <EOL> i = host . find ( '<STR_LIT::>' ) <EOL> if i > <NUM_LIT:0> : <EOL> host = host [ : i ] <EOL> key = '<STR_LIT>' % ( e . get ( '<STR_LIT>' , '<STR_LIT:localhost>' ) , <EOL> e . get ( '<STR_LIT>' , '<STR_LIT:http>' ) . lower ( ) , host , <EOL> e . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) , path ) <EOL> for ( regex , value , custom_env ) in regexes : <EOL> if regex . match ( key ) : <EOL> e . update ( custom_env ) <EOL> rewritten = regex . sub ( value , key ) <EOL> log_rewrite ( '<STR_LIT>' % ( tag , key , value , rewritten ) ) <EOL> return rewritten <EOL> log_rewrite ( '<STR_LIT>' % ( tag , key , default ) ) <EOL> return default <EOL> def regex_select ( env = None , app = None , request = None ) : <EOL> """<STR_LIT>""" <EOL> if app : <EOL> THREAD_LOCAL . routes = params_apps . get ( app , params ) <EOL> elif env and params . routes_app : <EOL> if routers : <EOL> map_url_in ( request , env , app = True ) <EOL> else : <EOL> app = regex_uri ( env , params . routes_app , "<STR_LIT>" ) <EOL> THREAD_LOCAL . routes = params_apps . get ( app , params ) <EOL> else : <EOL> THREAD_LOCAL . routes = params <EOL> log_rewrite ( "<STR_LIT>" % THREAD_LOCAL . routes . name ) <EOL> return app <EOL> def regex_filter_in ( e ) : <EOL> "<STR_LIT>" <EOL> routes = THREAD_LOCAL . routes <EOL> query = e . get ( '<STR_LIT>' , None ) <EOL> e [ '<STR_LIT>' ] = e [ '<STR_LIT>' ] + ( query and ( '<STR_LIT:?>' + query ) or '<STR_LIT>' ) <EOL> if routes . routes_in : <EOL> path = regex_uri ( e , routes . routes_in , <EOL> "<STR_LIT>" , e [ '<STR_LIT>' ] ) <EOL> rmatch = regex_redirect . match ( path ) <EOL> if rmatch : <EOL> raise HTTP ( int ( rmatch . group ( <NUM_LIT:1> ) ) , location = rmatch . group ( <NUM_LIT:2> ) ) <EOL> items = path . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> e [ '<STR_LIT>' ] = items [ <NUM_LIT:0> ] <EOL> if len ( items ) > <NUM_LIT:1> : <EOL> if query : <EOL> query = items [ <NUM_LIT:1> ] + '<STR_LIT:&>' + query <EOL> else : <EOL> query = items [ <NUM_LIT:1> ] <EOL> e [ '<STR_LIT>' ] = query <EOL> e [ '<STR_LIT>' ] = e [ '<STR_LIT>' ] + ( query and ( '<STR_LIT:?>' + query ) or '<STR_LIT>' ) <EOL> return e <EOL> def sluggify ( key ) : <EOL> return key . lower ( ) . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) <EOL> def invalid_url ( routes ) : <EOL> raise HTTP ( <NUM_LIT> , <EOL> routes . error_message % '<STR_LIT>' , <EOL> web2py_error = '<STR_LIT>' ) <EOL> def regex_url_in ( request , environ ) : <EOL> "<STR_LIT>" <EOL> regex_select ( env = environ , request = request ) <EOL> routes = THREAD_LOCAL . routes <EOL> if routes . routes_in : <EOL> environ = regex_filter_in ( environ ) <EOL> request . env . update ( <EOL> ( k . lower ( ) . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) , v ) for k , v in environ . iteritems ( ) ) <EOL> path = urllib . unquote ( request . env . path_info ) or '<STR_LIT:/>' <EOL> path = path . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> if path . endswith ( '<STR_LIT:/>' ) and len ( path ) > <NUM_LIT:1> : <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> match = regex_url . match ( path ) <EOL> if not match : <EOL> invalid_url ( routes ) <EOL> request . raw_args = ( match . group ( '<STR_LIT:s>' ) or '<STR_LIT>' ) <EOL> if request . raw_args . startswith ( '<STR_LIT:/>' ) : <EOL> request . raw_args = request . raw_args [ <NUM_LIT:1> : ] <EOL> if match . group ( '<STR_LIT:c>' ) == '<STR_LIT>' : <EOL> application = match . group ( '<STR_LIT:a>' ) <EOL> version , filename = None , match . group ( '<STR_LIT:z>' ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> if not filename : <EOL> raise HTTP ( <NUM_LIT> ) <EOL> items = filename . split ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> if regex_version . match ( items [ <NUM_LIT:0> ] ) : <EOL> version , filename = items <EOL> static_folder = pjoin ( request . env . applications_parent , <EOL> '<STR_LIT>' , application , '<STR_LIT>' ) <EOL> static_file = os . path . abspath ( pjoin ( static_folder , filename ) ) <EOL> if not static_file . startswith ( static_folder ) : <EOL> invalid_url ( routes ) <EOL> return ( static_file , version , environ ) <EOL> else : <EOL> request . application = match . group ( '<STR_LIT:a>' ) or routes . default_application <EOL> request . controller = match . group ( '<STR_LIT:c>' ) or routes . default_controller <EOL> request . function = match . group ( '<STR_LIT:f>' ) or routes . default_function <EOL> request . raw_extension = match . group ( '<STR_LIT:e>' ) <EOL> request . extension = request . raw_extension or '<STR_LIT:html>' <EOL> if request . application in routes . routes_apps_raw : <EOL> request . args = None <EOL> elif request . raw_args : <EOL> args = regex_args . sub ( '<STR_LIT:_>' , request . raw_args ) <EOL> request . args = List ( args . split ( '<STR_LIT:/>' ) ) <EOL> else : <EOL> request . args = List ( [ ] ) <EOL> return ( None , None , environ ) <EOL> def regex_filter_out ( url , e = None ) : <EOL> "<STR_LIT>" <EOL> if not hasattr ( THREAD_LOCAL , '<STR_LIT>' ) : <EOL> regex_select ( ) <EOL> routes = THREAD_LOCAL . routes <EOL> if routers : <EOL> return url <EOL> if routes . routes_out : <EOL> items = url . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> if e : <EOL> host = e . get ( '<STR_LIT>' , '<STR_LIT:localhost>' ) . lower ( ) <EOL> i = host . find ( '<STR_LIT::>' ) <EOL> if i > <NUM_LIT:0> : <EOL> host = host [ : i ] <EOL> items [ <NUM_LIT:0> ] = '<STR_LIT>' % ( e . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> e . get ( '<STR_LIT>' , '<STR_LIT:http>' ) . lower ( ) , host , <EOL> e . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) , items [ <NUM_LIT:0> ] ) <EOL> else : <EOL> items [ <NUM_LIT:0> ] = '<STR_LIT>' % items [ <NUM_LIT:0> ] <EOL> for ( regex , value , tmp ) in routes . routes_out : <EOL> if regex . match ( items [ <NUM_LIT:0> ] ) : <EOL> rewritten = '<STR_LIT:?>' . join ( [ regex . sub ( value , items [ <NUM_LIT:0> ] ) ] + items [ <NUM_LIT:1> : ] ) <EOL> log_rewrite ( '<STR_LIT>' % ( url , rewritten ) ) <EOL> return rewritten <EOL> log_rewrite ( '<STR_LIT>' % url ) <EOL> return url <EOL> def filter_url ( url , method = '<STR_LIT>' , remote = '<STR_LIT>' , <EOL> out = False , app = False , lang = None , <EOL> domain = ( None , None ) , env = False , scheme = None , <EOL> host = None , port = None ) : <EOL> """<STR_LIT>""" <EOL> match = regex_full_url . match ( url ) <EOL> urlscheme = match . group ( '<STR_LIT>' ) . lower ( ) <EOL> urlhost = match . group ( '<STR_LIT:host>' ) . lower ( ) <EOL> uri = match . group ( '<STR_LIT>' ) <EOL> k = uri . find ( '<STR_LIT:?>' ) <EOL> if k < <NUM_LIT:0> : <EOL> k = len ( uri ) <EOL> if isinstance ( domain , str ) : <EOL> domain = ( domain , None ) <EOL> ( path_info , query_string ) = ( uri [ : k ] , uri [ k + <NUM_LIT:1> : ] ) <EOL> path_info = urllib . unquote ( path_info ) <EOL> e = { <EOL> '<STR_LIT>' : remote , <EOL> '<STR_LIT>' : method , <EOL> '<STR_LIT>' : urlscheme , <EOL> '<STR_LIT>' : urlhost , <EOL> '<STR_LIT>' : uri , <EOL> '<STR_LIT>' : path_info , <EOL> '<STR_LIT>' : query_string , <EOL> '<STR_LIT>' : remote , <EOL> '<STR_LIT>' : method , <EOL> '<STR_LIT>' : urlscheme , <EOL> '<STR_LIT>' : urlhost <EOL> } <EOL> request = Storage ( ) <EOL> e [ "<STR_LIT>" ] = global_settings . applications_parent <EOL> request . env = Storage ( e ) <EOL> request . uri_language = lang <EOL> if app : <EOL> if routers : <EOL> return map_url_in ( request , e , app = True ) <EOL> return regex_select ( e ) <EOL> if out : <EOL> ( request . env . domain_application , <EOL> request . env . domain_controller ) = domain <EOL> items = path_info . lstrip ( '<STR_LIT:/>' ) . split ( '<STR_LIT:/>' ) <EOL> if items [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> items . pop ( ) <EOL> assert len ( items ) >= <NUM_LIT:3> , "<STR_LIT>" <EOL> a = items . pop ( <NUM_LIT:0> ) <EOL> c = items . pop ( <NUM_LIT:0> ) <EOL> f = items . pop ( <NUM_LIT:0> ) <EOL> if not routers : <EOL> return regex_filter_out ( uri , e ) <EOL> acf = map_url_out ( <EOL> request , None , a , c , f , items , None , scheme , host , port ) <EOL> if items : <EOL> url = '<STR_LIT>' % ( acf , '<STR_LIT:/>' . join ( items ) ) <EOL> if items [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> url += '<STR_LIT:/>' <EOL> else : <EOL> url = acf <EOL> if query_string : <EOL> url += '<STR_LIT:?>' + query_string <EOL> return url <EOL> ( static , version , e ) = url_in ( request , e ) <EOL> if static : <EOL> return static <EOL> result = "<STR_LIT>" % ( <EOL> request . application , request . controller , request . function ) <EOL> if request . extension and request . extension != '<STR_LIT:html>' : <EOL> result += "<STR_LIT>" % request . extension <EOL> if request . args : <EOL> result += "<STR_LIT>" % request . args <EOL> if e [ '<STR_LIT>' ] : <EOL> result += "<STR_LIT>" % e [ '<STR_LIT>' ] <EOL> if request . uri_language : <EOL> result += "<STR_LIT>" % request . uri_language <EOL> if env : <EOL> return request . env <EOL> return result <EOL> def filter_err ( status , application = '<STR_LIT>' , ticket = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> routes = THREAD_LOCAL . routes <EOL> if status > <NUM_LIT> and routes . routes_onerror : <EOL> keys = set ( ( '<STR_LIT>' % ( application , status ) , <EOL> '<STR_LIT>' % ( application ) , <EOL> '<STR_LIT>' % ( status ) , <EOL> '<STR_LIT>' ) ) <EOL> for ( key , redir ) in routes . routes_onerror : <EOL> if key in keys : <EOL> if redir == '<STR_LIT:!>' : <EOL> break <EOL> elif '<STR_LIT:?>' in redir : <EOL> url = redir + '<STR_LIT:&>' + '<STR_LIT>' % ( status , ticket ) <EOL> else : <EOL> url = redir + '<STR_LIT:?>' + '<STR_LIT>' % ( status , ticket ) <EOL> return url <EOL> return status <EOL> class MapUrlIn ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , request = None , env = None ) : <EOL> "<STR_LIT>" <EOL> self . request = request <EOL> self . env = env <EOL> self . router = None <EOL> self . application = None <EOL> self . language = None <EOL> self . controller = None <EOL> self . function = None <EOL> self . extension = '<STR_LIT:html>' <EOL> self . controllers = set ( ) <EOL> self . functions = dict ( ) <EOL> self . languages = set ( ) <EOL> self . default_language = None <EOL> self . map_hyphen = False <EOL> self . exclusive_domain = False <EOL> path = self . env [ '<STR_LIT>' ] <EOL> self . query = self . env . get ( '<STR_LIT>' , None ) <EOL> path = path . lstrip ( '<STR_LIT:/>' ) <EOL> self . env [ '<STR_LIT>' ] = '<STR_LIT:/>' + path <EOL> self . env [ '<STR_LIT>' ] = self . env [ '<STR_LIT>' ] + ( <EOL> self . query and ( '<STR_LIT:?>' + self . query ) or '<STR_LIT>' ) <EOL> if path . endswith ( '<STR_LIT:/>' ) : <EOL> path = path [ : - <NUM_LIT:1> ] <EOL> self . args = List ( path and path . split ( '<STR_LIT:/>' ) or [ ] ) <EOL> self . remote_addr = self . env . get ( '<STR_LIT>' , '<STR_LIT:localhost>' ) <EOL> self . scheme = self . env . get ( '<STR_LIT>' , '<STR_LIT:http>' ) . lower ( ) <EOL> self . method = self . env . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) <EOL> ( self . host , self . port ) = ( self . env . get ( '<STR_LIT>' ) , None ) <EOL> if not self . host : <EOL> ( self . host , self . port ) = ( <EOL> self . env . get ( '<STR_LIT>' ) , self . env . get ( '<STR_LIT>' ) ) <EOL> if not self . host : <EOL> ( self . host , self . port ) = ( '<STR_LIT:localhost>' , '<STR_LIT>' ) <EOL> if '<STR_LIT::>' in self . host : <EOL> ( self . host , self . port ) = self . host . rsplit ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> if not self . port : <EOL> self . port = '<STR_LIT>' if self . scheme == '<STR_LIT>' else '<STR_LIT>' <EOL> def map_prefix ( self ) : <EOL> "<STR_LIT>" <EOL> prefix = routers . BASE . path_prefix <EOL> if prefix : <EOL> prefixlen = len ( prefix ) <EOL> if prefixlen > len ( self . args ) : <EOL> return <EOL> for i in xrange ( prefixlen ) : <EOL> if prefix [ i ] != self . args [ i ] : <EOL> return <EOL> self . args = List ( self . args [ prefixlen : ] ) <EOL> def map_app ( self ) : <EOL> "<STR_LIT>" <EOL> base = routers . BASE <EOL> self . domain_application = None <EOL> self . domain_controller = None <EOL> self . domain_function = None <EOL> arg0 = self . harg0 <EOL> if not base . exclusive_domain and base . applications and arg0 in base . applications : <EOL> self . application = arg0 <EOL> elif not base . exclusive_domain and arg0 and not base . applications : <EOL> self . application = arg0 <EOL> elif ( self . host , self . port ) in base . domains : <EOL> ( self . application , self . domain_controller , <EOL> self . domain_function ) = base . domains [ ( self . host , self . port ) ] <EOL> self . env [ '<STR_LIT>' ] = self . application <EOL> self . env [ '<STR_LIT>' ] = self . domain_controller <EOL> self . env [ '<STR_LIT>' ] = self . domain_function <EOL> elif ( self . host , None ) in base . domains : <EOL> ( self . application , self . domain_controller , <EOL> self . domain_function ) = base . domains [ ( self . host , None ) ] <EOL> self . env [ '<STR_LIT>' ] = self . application <EOL> self . env [ '<STR_LIT>' ] = self . domain_controller <EOL> self . env [ '<STR_LIT>' ] = self . domain_function <EOL> elif base . applications and arg0 in base . applications : <EOL> self . application = arg0 <EOL> elif arg0 and not base . applications : <EOL> self . application = arg0 <EOL> else : <EOL> self . application = base . default_application or '<STR_LIT>' <EOL> self . pop_arg_if ( self . application == arg0 ) <EOL> if not base . _acfe_match . match ( self . application ) : <EOL> raise HTTP ( <EOL> <NUM_LIT> , THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = "<STR_LIT>" % self . application ) <EOL> if self . application not in routers and ( self . application != THREAD_LOCAL . routes . default_application or self . application == '<STR_LIT>' ) : <EOL> raise HTTP ( <EOL> <NUM_LIT> , THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = "<STR_LIT>" % self . application ) <EOL> log_rewrite ( "<STR_LIT>" % self . application ) <EOL> self . request . application = self . application <EOL> if self . application not in routers : <EOL> self . router = routers . BASE <EOL> else : <EOL> self . router = routers [ self . application ] <EOL> self . controllers = self . router . controllers <EOL> self . default_controller = self . domain_controller or self . router . default_controller <EOL> self . functions = self . router . functions <EOL> self . languages = self . router . languages <EOL> self . default_language = self . router . default_language <EOL> self . map_hyphen = self . router . map_hyphen <EOL> self . exclusive_domain = self . router . exclusive_domain <EOL> self . _acfe_match = self . router . _acfe_match <EOL> self . file_match = self . router . file_match <EOL> self . _file_match = self . router . _file_match <EOL> self . _args_match = self . router . _args_match <EOL> def map_root_static ( self ) : <EOL> '''<STR_LIT>''' <EOL> if len ( self . args ) == <NUM_LIT:1> and self . arg0 in self . router . root_static : <EOL> self . controller = self . request . controller = '<STR_LIT>' <EOL> root_static_file = pjoin ( self . request . env . applications_parent , <EOL> '<STR_LIT>' , self . application , <EOL> self . controller , self . arg0 ) <EOL> log_rewrite ( "<STR_LIT>" % root_static_file ) <EOL> return root_static_file , None <EOL> return None , None <EOL> def map_language ( self ) : <EOL> "<STR_LIT>" <EOL> arg0 = self . arg0 <EOL> if arg0 and self . languages and arg0 in self . languages : <EOL> self . language = arg0 <EOL> else : <EOL> self . language = self . default_language <EOL> if self . language : <EOL> log_rewrite ( "<STR_LIT>" % self . language ) <EOL> self . pop_arg_if ( self . language == arg0 ) <EOL> arg0 = self . arg0 <EOL> def map_controller ( self ) : <EOL> "<STR_LIT>" <EOL> arg0 = self . harg0 <EOL> if not arg0 or ( self . controllers and arg0 not in self . controllers ) : <EOL> self . controller = self . default_controller or '<STR_LIT>' <EOL> else : <EOL> self . controller = arg0 <EOL> self . pop_arg_if ( arg0 == self . controller ) <EOL> log_rewrite ( "<STR_LIT>" % self . controller ) <EOL> if not self . router . _acfe_match . match ( self . controller ) : <EOL> raise HTTP ( <EOL> <NUM_LIT> , THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = '<STR_LIT>' ) <EOL> def map_static ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . controller != '<STR_LIT>' : <EOL> return None , None <EOL> version = regex_version . match ( self . args ( <NUM_LIT:0> ) ) <EOL> if self . args and version : <EOL> file = '<STR_LIT:/>' . join ( self . args [ <NUM_LIT:1> : ] ) <EOL> else : <EOL> file = '<STR_LIT:/>' . join ( self . args ) <EOL> if len ( self . args ) == <NUM_LIT:0> : <EOL> bad_static = True <EOL> elif '<STR_LIT:/>' in self . file_match : <EOL> bad_static = not self . router . _file_match . match ( file ) <EOL> else : <EOL> bad_static = False <EOL> for name in self . args : <EOL> bad_static = bad_static or name in ( <EOL> '<STR_LIT>' , '<STR_LIT:.>' , '<STR_LIT:..>' ) or not self . router . _file_match . match ( name ) <EOL> if bad_static : <EOL> log_rewrite ( '<STR_LIT>' % file ) <EOL> raise HTTP ( <NUM_LIT> , <EOL> THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = '<STR_LIT>' ) <EOL> if self . language : <EOL> static_file = pjoin ( self . request . env . applications_parent , <EOL> '<STR_LIT>' , self . application , <EOL> '<STR_LIT>' , self . language , file ) <EOL> if not self . language or not isfile ( static_file ) : <EOL> static_file = pjoin ( self . request . env . applications_parent , <EOL> '<STR_LIT>' , self . application , <EOL> '<STR_LIT>' , file ) <EOL> self . extension = None <EOL> log_rewrite ( "<STR_LIT>" % static_file ) <EOL> return static_file , version <EOL> def map_function ( self ) : <EOL> "<STR_LIT>" <EOL> arg0 = self . harg0 <EOL> functions = self . functions . get ( self . controller , set ( ) ) <EOL> if isinstance ( self . router . default_function , dict ) : <EOL> default_function = self . router . default_function . get ( <EOL> self . controller , None ) <EOL> else : <EOL> default_function = self . router . default_function <EOL> default_function = self . domain_function or default_function <EOL> if not arg0 or functions and arg0 not in functions : <EOL> self . function = default_function or "<STR_LIT>" <EOL> self . pop_arg_if ( arg0 and self . function == arg0 ) <EOL> else : <EOL> func_ext = arg0 . split ( '<STR_LIT:.>' ) <EOL> if len ( func_ext ) > <NUM_LIT:1> : <EOL> self . function = func_ext [ <NUM_LIT:0> ] <EOL> self . extension = func_ext [ - <NUM_LIT:1> ] <EOL> else : <EOL> self . function = arg0 <EOL> self . pop_arg_if ( True ) <EOL> log_rewrite ( <EOL> "<STR_LIT>" % ( self . function , self . extension ) ) <EOL> if not self . router . _acfe_match . match ( self . function ) : <EOL> raise HTTP ( <EOL> <NUM_LIT> , THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = '<STR_LIT>' ) <EOL> if self . extension and not self . router . _acfe_match . match ( self . extension ) : <EOL> raise HTTP ( <EOL> <NUM_LIT> , THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = '<STR_LIT>' ) <EOL> def validate_args ( self ) : <EOL> '''<STR_LIT>''' <EOL> for arg in self . args : <EOL> if not self . router . _args_match . match ( arg ) : <EOL> raise HTTP ( <EOL> <NUM_LIT> , THREAD_LOCAL . routes . error_message % '<STR_LIT>' , <EOL> web2py_error = '<STR_LIT>' % arg ) <EOL> def sluggify ( self ) : <EOL> "<STR_LIT>" <EOL> self . request . env . update ( <EOL> ( k . lower ( ) . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) , v ) for k , v in self . env . iteritems ( ) ) <EOL> def update_request ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . request . application = self . application <EOL> self . request . controller = self . controller <EOL> self . request . function = self . function <EOL> self . request . extension = self . extension <EOL> self . request . args = self . args <EOL> if self . language : <EOL> self . request . uri_language = self . language <EOL> uri = '<STR_LIT>' % ( self . controller , self . function ) <EOL> app = self . application <EOL> if self . map_hyphen : <EOL> uri = uri . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> app = app . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if self . extension and self . extension != '<STR_LIT:html>' : <EOL> uri += '<STR_LIT:.>' + self . extension <EOL> if self . language : <EOL> uri = '<STR_LIT>' % ( self . language , uri ) <EOL> uri = '<STR_LIT>' % ( <EOL> app , <EOL> uri , <EOL> urllib . quote ( '<STR_LIT:/>' + '<STR_LIT:/>' . join ( <EOL> str ( x ) for x in self . args ) ) if self . args else '<STR_LIT>' , <EOL> ( '<STR_LIT:?>' + self . query ) if self . query else '<STR_LIT>' ) <EOL> self . env [ '<STR_LIT>' ] = uri <EOL> self . sluggify ( ) <EOL> @ property <EOL> def arg0 ( self ) : <EOL> "<STR_LIT>" <EOL> return self . args ( <NUM_LIT:0> ) <EOL> @ property <EOL> def harg0 ( self ) : <EOL> "<STR_LIT>" <EOL> if self . map_hyphen and self . args ( <NUM_LIT:0> ) : <EOL> return self . args ( <NUM_LIT:0> ) . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> return self . args ( <NUM_LIT:0> ) <EOL> def pop_arg_if ( self , dopop ) : <EOL> "<STR_LIT>" <EOL> if dopop : <EOL> self . args . pop ( <NUM_LIT:0> ) <EOL> class MapUrlOut ( object ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , request , env , application , controller , <EOL> function , args , other , scheme , host , port ) : <EOL> "<STR_LIT>" <EOL> self . default_application = routers . BASE . default_application <EOL> if application in routers : <EOL> self . router = routers [ application ] <EOL> else : <EOL> self . router = routers . BASE <EOL> self . request = request <EOL> self . env = env <EOL> self . application = application <EOL> self . controller = controller <EOL> self . is_static = ( <EOL> controller == '<STR_LIT>' or controller . startswith ( '<STR_LIT>' ) ) <EOL> self . function = function <EOL> self . args = args <EOL> self . other = other <EOL> self . scheme = scheme <EOL> self . host = host <EOL> self . port = port <EOL> self . applications = routers . BASE . applications <EOL> self . controllers = self . router . controllers <EOL> self . functions = self . router . functions . get ( self . controller , set ( ) ) <EOL> self . languages = self . router . languages <EOL> self . default_language = self . router . default_language <EOL> self . exclusive_domain = self . router . exclusive_domain <EOL> self . map_hyphen = self . router . map_hyphen <EOL> self . map_static = self . router . map_static <EOL> self . path_prefix = routers . BASE . path_prefix <EOL> self . domain_application = request and self . request . env . domain_application <EOL> self . domain_controller = request and self . request . env . domain_controller <EOL> if isinstance ( self . router . default_function , dict ) : <EOL> self . default_function = self . router . default_function . get ( <EOL> self . controller , None ) <EOL> else : <EOL> self . default_function = self . router . default_function <EOL> if ( self . router . exclusive_domain and self . domain_application and self . domain_application != self . application and not self . host ) : <EOL> raise SyntaxError ( '<STR_LIT>' ) <EOL> lang = request and request . uri_language <EOL> if lang and self . languages and lang in self . languages : <EOL> self . language = lang <EOL> else : <EOL> self . language = None <EOL> self . omit_application = False <EOL> self . omit_language = False <EOL> self . omit_controller = False <EOL> self . omit_function = False <EOL> def omit_lang ( self ) : <EOL> "<STR_LIT>" <EOL> if not self . language or self . language == self . default_language : <EOL> self . omit_language = True <EOL> def omit_acf ( self ) : <EOL> "<STR_LIT>" <EOL> router = self . router <EOL> if not self . args and self . function == self . default_function : <EOL> self . omit_function = True <EOL> if self . controller == router . default_controller : <EOL> self . omit_controller = True <EOL> if self . application == self . default_application : <EOL> self . omit_application = True <EOL> default_application = self . domain_application or self . default_application <EOL> if self . application == default_application : <EOL> self . omit_application = True <EOL> default_controller = ( ( self . application == self . domain_application ) and self . domain_controller ) or router . default_controller or '<STR_LIT>' <EOL> if self . controller == default_controller : <EOL> self . omit_controller = True <EOL> if self . functions and self . function in self . functions and self . function == self . default_function : <EOL> self . omit_function = True <EOL> if self . exclusive_domain : <EOL> applications = [ self . domain_application ] <EOL> else : <EOL> applications = self . applications <EOL> if self . omit_language : <EOL> if not applications or self . controller in applications : <EOL> self . omit_application = False <EOL> if self . omit_application : <EOL> if not applications or self . function in applications : <EOL> self . omit_controller = False <EOL> if not self . controllers or self . function in self . controllers : <EOL> self . omit_controller = False <EOL> if self . args : <EOL> if self . args [ <NUM_LIT:0> ] in self . functions or self . args [ <NUM_LIT:0> ] in self . controllers or self . args [ <NUM_LIT:0> ] in applications : <EOL> self . omit_function = False <EOL> if self . omit_controller : <EOL> if self . function in self . controllers or self . function in applications : <EOL> self . omit_controller = False <EOL> if self . omit_application : <EOL> if self . controller in applications : <EOL> self . omit_application = False <EOL> if self . is_static : <EOL> if not self . map_static : <EOL> self . omit_application = False <EOL> if self . language : <EOL> self . omit_language = False <EOL> self . omit_controller = False <EOL> self . omit_function = False <EOL> def build_acf ( self ) : <EOL> "<STR_LIT>" <EOL> acf = '<STR_LIT>' <EOL> if self . map_hyphen : <EOL> self . application = self . application . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> self . controller = self . controller . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if self . controller != '<STR_LIT>' and not self . controller . startswith ( '<STR_LIT>' ) : <EOL> self . function = self . function . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) <EOL> if not self . omit_application : <EOL> acf += '<STR_LIT:/>' + self . application <EOL> if self . is_static and self . map_static is False and not self . omit_language : <EOL> acf += '<STR_LIT:/>' + self . controller + '<STR_LIT:/>' + self . language <EOL> else : <EOL> if not self . omit_language : <EOL> acf += '<STR_LIT:/>' + self . language <EOL> if not self . omit_controller : <EOL> acf += '<STR_LIT:/>' + self . controller <EOL> if not self . omit_function : <EOL> acf += '<STR_LIT:/>' + self . function <EOL> if self . path_prefix : <EOL> acf = '<STR_LIT:/>' + '<STR_LIT:/>' . join ( self . path_prefix ) + acf <EOL> if self . args : <EOL> return acf <EOL> return acf or '<STR_LIT:/>' <EOL> def acf ( self ) : <EOL> "<STR_LIT>" <EOL> if not routers : <EOL> return None <EOL> self . omit_lang ( ) <EOL> self . omit_acf ( ) <EOL> return self . build_acf ( ) <EOL> def map_url_in ( request , env , app = False ) : <EOL> "<STR_LIT>" <EOL> THREAD_LOCAL . routes = params <EOL> map = MapUrlIn ( request = request , env = env ) <EOL> map . sluggify ( ) <EOL> map . map_prefix ( ) <EOL> map . map_app ( ) <EOL> if params . routes_app : <EOL> THREAD_LOCAL . routes = params_apps . get ( app , params ) <EOL> if app : <EOL> return map . application <EOL> root_static_file , version = map . map_root_static ( <EOL> ) <EOL> if root_static_file : <EOL> map . update_request ( ) <EOL> return ( root_static_file , version , map . env ) <EOL> if map . languages and map . map_static is False and map . arg0 == '<STR_LIT>' and map . args ( <NUM_LIT:1> ) in map . languages : <EOL> map . map_controller ( ) <EOL> map . map_language ( ) <EOL> else : <EOL> map . map_language ( ) <EOL> map . map_controller ( ) <EOL> static_file , version = map . map_static ( ) <EOL> if static_file : <EOL> map . update_request ( ) <EOL> return ( static_file , version , map . env ) <EOL> map . map_function ( ) <EOL> map . validate_args ( ) <EOL> map . update_request ( ) <EOL> return ( None , None , map . env ) <EOL> def map_url_out ( request , env , application , controller , <EOL> function , args , other , scheme , host , port ) : <EOL> '''<STR_LIT>''' <EOL> map = MapUrlOut ( request , env , application , controller , <EOL> function , args , other , scheme , host , port ) <EOL> return map . acf ( ) <EOL> def get_effective_router ( appname ) : <EOL> "<STR_LIT>" <EOL> if not routers or appname not in routers : <EOL> return None <EOL> return Storage ( routers [ appname ] ) </s>
