def url_for(endpoint, **values):
 appctx = _app_ctx_stack.top
 reqctx = _request_ctx_stack.top
 if (appctx is None):
  raise RuntimeError('Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.')
 if (reqctx is not None):
  url_adapter = reqctx.url_adapter
  blueprint_name = request.blueprint
  if (not reqctx.request._is_old_module):
   if (endpoint[:1] == '.'):
    if (blueprint_name is not None):
     endpoint = (blueprint_name + endpoint)
    else:
     endpoint = endpoint[1:]
  elif ('.' not in endpoint):
   if (blueprint_name is not None):
    endpoint = ((blueprint_name + '.') + endpoint)
  elif endpoint.startswith('.'):
   endpoint = endpoint[1:]
  external = values.pop('_external', False)
 else:
  url_adapter = appctx.url_adapter
  if (url_adapter is None):
   raise RuntimeError('Application was not able to create a URL adapter for request independent URL generation. You might be able to fix this by setting the SERVER_NAME config variable.')
  external = values.pop('_external', True)
 anchor = values.pop('_anchor', None)
 method = values.pop('_method', None)
 scheme = values.pop('_scheme', None)
 appctx.app.inject_url_defaults(endpoint, values)
 if (scheme is not None):
  if (not external):
   raise ValueError('When specifying _scheme, _external must be True')
  url_adapter.url_scheme = scheme
 try:
  rv = url_adapter.build(endpoint, values, method=method, force_external=external)
 except BuildError as error:
  values['_external'] = external
  values['_anchor'] = anchor
  values['_method'] = method
  return appctx.app.handle_url_build_error(error, endpoint, values)
 if (anchor is not None):
  rv += ('#' + url_quote(anchor))
 return rv

def url_for ( endpoint , ** values ) : appctx = _app_ctx_stack . top reqctx = _request_ctx_stack . top if ( appctx is None ) : raise RuntimeError ( 'Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.' ) if ( reqctx is not None ) : url_adapter = reqctx . url_adapter blueprint_name = request . blueprint if ( not reqctx . request . _is_old_module ) : if ( endpoint [ : 1 ] == '.' ) : if ( blueprint_name is not None ) : endpoint = ( blueprint_name + endpoint ) else : endpoint = endpoint [ 1 : ] elif ( '.' not in endpoint ) : if ( blueprint_name is not None ) : endpoint = ( ( blueprint_name + '.' ) + endpoint ) elif endpoint . startswith ( '.' ) : endpoint = endpoint [ 1 : ] external = values . pop ( '_external' , False ) else : url_adapter = appctx . url_adapter if ( url_adapter is None ) : raise RuntimeError ( 'Application was not able to create a URL adapter for request independent URL generation. You might be able to fix this by setting the SERVER_NAME config variable.' ) external = values . pop ( '_external' , True ) anchor = values . pop ( '_anchor' , None ) method = values . pop ( '_method' , None ) scheme = values . pop ( '_scheme' , None ) appctx . app . inject_url_defaults ( endpoint , values ) if ( scheme is not None ) : if ( not external ) : raise ValueError ( 'When specifying _scheme, _external must be True' ) url_adapter . url_scheme = scheme try : rv = url_adapter . build ( endpoint , values , method = method , force_external = external ) except BuildError as error : values [ '_external' ] = external values [ '_anchor' ] = anchor values [ '_method' ] = method return appctx . app . handle_url_build_error ( error , endpoint , values ) if ( anchor is not None ) : rv += ( '#' + url_quote ( anchor ) ) return rv
incomplete emulation of flasks url_for .