#NEWLINE# def __call__( self , * args , **kargs ) : #NEWLINE# #INDENT# 'Generates a URL\n\n        All keys given to url_for are sent to the Routes Mapper instance for\n        generation except for::\n\n            anchor          specified the anchor name to be appened to the path\n            host            overrides the default (current) host if provided\n            protocol        overrides the default (current) protocol if provided\n            qualified       creates the URL with the host/port information as\n                            needed\n\n        ' #NEWLINE# anchor = kargs . get ( 'anchor' ) #NEWLINE# host = kargs . get ( 'host' ) #NEWLINE# protocol = kargs . pop ( 'protocol' , None ) #NEWLINE# qualified = kargs . pop ( 'qualified' , None ) #NEWLINE# for key in [ 'anchor' , 'host' ] : #NEWLINE# #INDENT# if kargs . get ( key ) : #NEWLINE# #INDENT# del kargs [ key ] #NEWLINE# #UNINDENT# if ( ( key + '_' ) in kargs ) : #NEWLINE# #INDENT# kargs [ key ] = kargs . pop ( ( key + '_' ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'protocol_' in kargs ) : #NEWLINE# #INDENT# kargs [ 'protocol_' ] = protocol #NEWLINE# #UNINDENT# route = None #NEWLINE# use_current = ( ( '_use_current' in kargs ) and kargs . pop ( '_use_current' ) ) #NEWLINE# static = False #NEWLINE# encoding = self . mapper . encoding #NEWLINE# url = '' #NEWLINE# more_args = ( len ( args ) > 0 ) #NEWLINE# if host : #NEWLINE# #INDENT# route = self . mapper . _routenames . get ( args [ 0 ] ) #NEWLINE# #UNINDENT# if ( ( not route ) and more_args ) : #NEWLINE# #INDENT# static = True #NEWLINE# url = args [ 0 ] #NEWLINE# if ( url . startswith ( '/' ) and self . environ . get ( 'SCRIPT_NAME' ) ) : #NEWLINE# #INDENT# url = ( self . environ . get ( 'SCRIPT_NAME' ) + url ) #NEWLINE# #UNINDENT# if static : #NEWLINE# #INDENT# if kargs : #NEWLINE# #INDENT# url += '?' #NEWLINE# query_args = [ ] #NEWLINE# for ( key , val ) in six . iteritems ( kargs ) : #NEWLINE# #INDENT# if isinstance ( val , ( list , tuple ) ) : #NEWLINE# #INDENT# for value in val : #NEWLINE# #INDENT# query_args . append ( ( '%s=%s' % ( urllib . parse . quote ( six . text_type ( key ) . encode ( encoding ) ) , urllib . parse . quote ( six . text_type ( value ) . encode ( encoding ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# query_args . append ( ( '%s=%s' % ( urllib . parse . quote ( six . text_type ( key ) . encode ( encoding ) ) , urllib . parse . quote ( six . text_type ( val ) . encode ( encoding ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# url += '&' . join ( query_args ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not static ) : #NEWLINE# #INDENT# route_args = [ ] #NEWLINE# if route : #NEWLINE# #INDENT# if self . mapper . hardcode_names : #NEWLINE# #INDENT# route_args . append ( route ) #NEWLINE# #UNINDENT# newargs = route . defaults . copy ( ) #NEWLINE# newargs . update ( kargs ) #NEWLINE# if route . filter : #NEWLINE# #INDENT# newargs = route . filter ( newargs ) #NEWLINE# #UNINDENT# if ( ( not route . static ) or ( route . static and ( not route . external ) ) ) : #NEWLINE# #INDENT# sub = newargs . get ( 'sub_domain' , None ) #NEWLINE# newargs = _subdomain_check ( newargs , self . mapper , self . environ ) #NEWLINE# if ( 'sub_domain' in route . defaults ) : #NEWLINE# #INDENT# newargs [ 'sub_domain' ] = sub #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if use_current : #NEWLINE# #INDENT# newargs = _screenargs ( kargs , self . mapper , self . environ , force_explicit = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'sub_domain' in kargs ) : #NEWLINE# #INDENT# newargs = _subdomain_check ( kargs , self . mapper , self . environ ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# newargs = kargs #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# anchor = ( anchor or newargs . pop ( '_anchor' , None ) ) #NEWLINE# host = ( host or newargs . pop ( '_host' , None ) ) #NEWLINE# if ( protocol is None ) : #NEWLINE# #INDENT# protocol = newargs . pop ( '_protocol' , None ) #NEWLINE# #UNINDENT# newargs [ '_environ' ] = self . environ #NEWLINE# url = self . mapper . generate ( * route_args , ** newargs ) #NEWLINE# #UNINDENT# if ( anchor is not None ) : #NEWLINE# #INDENT# url += ( '#' + _url_quote ( anchor , encoding ) ) #NEWLINE# #UNINDENT# if ( host or ( protocol is not None ) or qualified ) : #NEWLINE# #INDENT# if ( 'routes.cached_hostinfo' not in self . environ ) : #NEWLINE# #INDENT# cache_hostinfo ( self . environ ) #NEWLINE# #UNINDENT# hostinfo = self . environ [ 'routes.cached_hostinfo' ] #NEWLINE# if ( ( not host ) and ( not qualified ) ) : #NEWLINE# #INDENT# host = hostinfo [ 'host' ] . split ( ':' ) [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not host ) : #NEWLINE# #INDENT# host = hostinfo [ 'host' ] #NEWLINE# #UNINDENT# #UNINDENT# if ( protocol is None ) : #NEWLINE# #INDENT# protocol = hostinfo [ 'protocol' ] #NEWLINE# #UNINDENT# if ( protocol != '' ) : #NEWLINE# #INDENT# protocol += ':' #NEWLINE# #UNINDENT# if ( url is not None ) : #NEWLINE# #INDENT# if ( host [ ( - 1 ) ] != '/' ) : #NEWLINE# #INDENT# host += '/' #NEWLINE# #UNINDENT# url = ( ( ( protocol + '//' ) + host ) + url . lstrip ( '/' ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not ascii_characters ( url ) ) and ( url is not None ) ) : #NEWLINE# #INDENT# raise GenerationException ( ( 'Can only return a string, got unicode instead: %s' % url ) ) #NEWLINE# #UNINDENT# if ( url is None ) : #NEWLINE# #INDENT# raise GenerationException ( ( 'Could not generate URL. Called with args: %s %s' % ( args , kargs ) ) ) #NEWLINE# #UNINDENT# return url