def regex_uri(e, regexes, tag, default=None):
 path = e['PATH_INFO']
 host = e.get('HTTP_HOST', e.get('SERVER_NAME', 'localhost')).lower()
 i = host.find(':')
 if (i > 0):
  host = host[:i]
 key = ('%s:%s://%s:%s %s' % (e.get('REMOTE_ADDR', 'localhost'), e.get('wsgi.url_scheme', 'http').lower(), host, e.get('REQUEST_METHOD', 'get').lower(), path))
 for (regex, value, custom_env) in regexes:
  if regex.match(key):
   e.update(custom_env)
   rewritten = regex.sub(value, key)
   log_rewrite(('%s: [%s] [%s] -> %s' % (tag, key, value, rewritten)))
   return rewritten
 log_rewrite(('%s: [%s] -> %s (not rewritten)' % (tag, key, default)))
 return default

def regex_uri ( e , regexes , tag , default = None ) : path = e [ 'PATH_INFO' ] host = e . get ( 'HTTP_HOST' , e . get ( 'SERVER_NAME' , 'localhost' ) ) . lower ( ) i = host . find ( ':' ) if ( i > 0 ) : host = host [ : i ] key = ( '%s:%s://%s:%s %s' % ( e . get ( 'REMOTE_ADDR' , 'localhost' ) , e . get ( 'wsgi.url_scheme' , 'http' ) . lower ( ) , host , e . get ( 'REQUEST_METHOD' , 'get' ) . lower ( ) , path ) ) for ( regex , value , custom_env ) in regexes : if regex . match ( key ) : e . update ( custom_env ) rewritten = regex . sub ( value , key ) log_rewrite ( ( '%s: [%s] [%s] -> %s' % ( tag , key , value , rewritten ) ) ) return rewritten log_rewrite ( ( '%s: [%s] -> %s (not rewritten)' % ( tag , key , default ) ) ) return default
filters incoming uri against a list of regexes .