neulab/docprompting-conala huggingface dataset:
class flask.blueprints.BlueprintSetupState(blueprint, app, options, first_registration)  
Temporary holder object for registering a blueprint with the application. An instance of this class is created by the make_setup_state() method and later passed to all register callback functions.  Parameters 
 
blueprint (Blueprint) –  
app (Flask) –  
options (Any) –  
first_registration (bool) –    Return type 
None    
add_url_rule(rule, endpoint=None, view_func=None, **options)  
A helper method to register a rule (and optionally a view function) to the application. The endpoint is automatically prefixed with the blueprint’s name.  Parameters 
 
rule (str) –  
endpoint (Optional[str]) –  
view_func (Optional[Callable]) –  
options (Any) –    Return type 
None   
  
app  
a reference to the current application 
  
blueprint  
a reference to the blueprint that created this setup state. 
  
first_registration  
as blueprints can be registered multiple times with the application and not everything wants to be registered multiple times on it, this attribute can be used to figure out if the blueprint was registered in the past already. 
  
options  
a dictionary with all options that were passed to the register_blueprint() method. 
  
subdomain  
The subdomain that the blueprint should be active for, None otherwise. 
  
url_defaults  
A dictionary with URL defaults that is added to each and every URL that was defined with the blueprint. 
  
url_prefix  
The prefix that should be used for all URLs defined on the blueprint.
add_url_rule(rule, endpoint=None, view_func=None, **options)  
A helper method to register a rule (and optionally a view function) to the application. The endpoint is automatically prefixed with the blueprint’s name.  Parameters 
 
rule (str) –  
endpoint (Optional[str]) –  
view_func (Optional[Callable]) –  
options (Any) –    Return type 
None
first_registration  
as blueprints can be registered multiple times with the application and not everything wants to be registered multiple times on it, this attribute can be used to figure out if the blueprint was registered in the past already.
url_defaults  
A dictionary with URL defaults that is added to each and every URL that was defined with the blueprint.
Caching When your application runs slow, throw some caches in. Well, at least it’s the easiest way to speed up things. What does a cache do? Say you have a function that takes some time to complete but the results would still be good enough if they were 5 minutes old. So then the idea is that you actually put the result of that calculation into a cache for some time. Flask itself does not provide caching for you, but Flask-Caching, an extension for Flask does. Flask-Caching supports various backends, and it is even possible to develop your own caching backend.
CGI If all other deployment methods do not work, CGI will work for sure. CGI is supported by all major servers but usually has a sub-optimal performance. This is also the way you can use a Flask application on Google’s App Engine, where execution happens in a CGI-like environment.  Watch Out Please make sure in advance that any app.run() calls you might have in your application file are inside an if __name__ ==
'__main__': block or moved to a separate file. Just make sure it’s not called because this will always start a local WSGI server which we do not want if we deploy that application to CGI / app engine. With CGI, you will also have to make sure that your code does not contain any print statements, or that sys.stdout is overridden by something that doesn’t write into the HTTP response.  Creating a .cgi file First you need to create the CGI application file. Let’s call it yourapplication.cgi: #!/usr/bin/python
from wsgiref.handlers import CGIHandler
from yourapplication import app

CGIHandler().run(app)
 Server Setup Usually there are two ways to configure the server. Either just copy the .cgi into a cgi-bin (and use mod_rewrite or something similar to rewrite the URL) or let the server point to the file directly. In Apache for example you can put something like this into the config: ScriptAlias /app /path/to/the/application.cgi
 On shared webhosting, though, you might not have access to your Apache config. In this case, a file called .htaccess, sitting in the public directory you want your app to be available, works too but the ScriptAlias directive won’t work in that case: RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f # Don't interfere with static files
RewriteRule ^(.*)$ /path/to/the/application.cgi/$1 [L]
 For more information consult the documentation of your webserver.
from_envvar(variable_name, silent=False)  
Loads a configuration from an environment variable pointing to a configuration file. This is basically just a shortcut with nicer error messages for this line of code: app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
  Parameters 
 
variable_name (str) – name of the environment variable 
silent (bool) – set to True if you want silent failure for missing files.   Returns 
bool. True if able to load config, False otherwise.  Return type 
bool
from_file(filename, load, silent=False)  
Update the values in the config from a file that is loaded using the load parameter. The loaded data is passed to the from_mapping() method. import toml
app.config.from_file("config.toml", load=toml.load)
  Parameters 
 
filename (str) – The path to the data file. This can be an absolute path or relative to the config root path. 
load (Callable[[Reader], Mapping] where Reader implements a read method.) – A callable that takes a file handle and returns a mapping of loaded data from the file. 
silent (bool) – Ignore the file if it doesn’t exist.   Return type 
bool    New in version 2.0.
from_mapping(mapping=None, **kwargs)  
Updates the config like update() ignoring items with non-upper keys.  Changelog New in version 0.11.   Parameters 
 
mapping (Optional[Mapping[str, Any]]) –  
kwargs (Any) –    Return type 
bool
from_object(obj)  
Updates the values from the given object. An object can be of one of the following two types:  a string: in this case the object with that name will be imported an actual object reference: that object is used directly  Objects are usually either modules or classes. from_object() loads only the uppercase attributes of the module/class. A dict object will not work with from_object() because the keys of a dict are not attributes of the dict class. Example of module-based configuration: app.config.from_object('yourapplication.default_config')
from yourapplication import default_config
app.config.from_object(default_config)
 Nothing is done to the object before loading. If the object is a class and has @property attributes, it needs to be instantiated before being passed to this method. You should not use this function to load the actual configuration but rather configuration defaults. The actual config should be loaded with from_pyfile() and ideally from a location not within the package because the package might be installed system wide. See Development / Production for an example of class-based configuration using from_object().  Parameters 
obj (Union[object, str]) – an import name or object  Return type 
None
from_pyfile(filename, silent=False)  
Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the from_object() function.  Parameters 
 
filename (str) – the filename of the config. This can either be an absolute filename or a filename relative to the root path. 
silent (bool) – set to True if you want silent failure for missing files.   Return type 
bool    Changelog New in version 0.7: silent parameter.
get_namespace(namespace, lowercase=True, trim_namespace=True)  
Returns a dictionary containing a subset of configuration options that match the specified namespace/prefix. Example usage: app.config['IMAGE_STORE_TYPE'] = 'fs'
app.config['IMAGE_STORE_PATH'] = '/var/app/images'
app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
image_store_config = app.config.get_namespace('IMAGE_STORE_')
 The resulting dictionary image_store_config would look like: {
    'type': 'fs',
    'path': '/var/app/images',
    'base_url': 'http://img.website.com'
}
 This is often useful when configuration options map directly to keyword arguments in functions or class constructors.  Parameters 
 
namespace (str) – a configuration namespace 
lowercase (bool) – a flag indicating if the keys of the resulting dictionary should be lowercase 
trim_namespace (bool) – a flag indicating if the keys of the resulting dictionary should not include the namespace   Return type 
Dict[str, Any]    Changelog New in version 0.11.
flask.copy_current_request_context(f)  
A helper function that decorates a function to retain the current request context. This is useful when working with greenlets. The moment the function is decorated a copy of the request context is created and then pushed when the function is called. The current session is also included in the copied request context. Example: import gevent
from flask import copy_current_request_context

@app.route('/')
def index():
    @copy_current_request_context
    def do_some_work():
        # do some work here, it can access flask.request or
        # flask.session like you would otherwise in the view function.
        ...
    gevent.spawn(do_some_work)
    return 'Regular response'
  Changelog New in version 0.10.   Parameters 
f (Callable) –   Return type 
Callable
DEBUG  
Whether debug mode is enabled. When using flask run to start the development server, an interactive debugger will be shown for unhandled exceptions, and the server will be reloaded when code changes. The debug attribute maps to this config key. This is enabled when ENV is 'development' and is overridden by the FLASK_DEBUG environment variable. It may not behave as expected if set in code. Do not enable debug mode when deploying in production. Default: True if ENV is 'development', or False otherwise.
flask.json.dump(obj, fp, app=None, **kwargs)  
Serialize an object to JSON written to a file object. Takes the same arguments as the built-in json.dump(), with some defaults from application configuration.  Parameters 
 
obj (Any) – Object to serialize to JSON. 
fp (IO[str]) – File object to write JSON to. 
app (Optional[Flask]) – Use this app’s config instead of the active app context or defaults. 
kwargs (Any) – Extra arguments passed to json.dump().   Return type 
None    Changed in version 2.0: Writing to a binary file, and the encoding argument, is deprecated and will be removed in Flask 2.1.
flask.json.dumps(obj, app=None, **kwargs)  
Serialize an object to a string of JSON. Takes the same arguments as the built-in json.dumps(), with some defaults from application configuration.  Parameters 
 
obj (Any) – Object to serialize to JSON. 
app (Optional[Flask]) – Use this app’s config instead of the active app context or defaults. 
kwargs (Any) – Extra arguments passed to json.dumps().   Return type 
str    Changed in version 2.0: encoding is deprecated and will be removed in Flask 2.1.   Changelog Changed in version 1.0.3: app can be passed directly, rather than requiring an app context for configuration.
ENV  
What environment the app is running in. Flask and extensions may enable behaviors based on the environment, such as enabling debug mode. The env attribute maps to this config key. This is set by the FLASK_ENV environment variable and may not behave as expected if set in code. Do not enable development when deploying in production. Default: 'production'  Changelog New in version 1.0.
flask.escape()  
Replace the characters &, <, >, ', and " in the string with HTML-safe sequences. Use this if you need to display text that might contain such characters in HTML. If the object has an __html__ method, it is called and the return value is assumed to already be safe for HTML.  Parameters 
s – An object to be converted to a string and escaped.  Returns 
A Markup string with the escaped text.
EXPLAIN_TEMPLATE_LOADING  
Log debugging information tracing how a template file was loaded. This can be useful to figure out why a template was not loaded or the wrong file appears to be loaded. Default: False
Extensions Extensions are extra packages that add functionality to a Flask application. For example, an extension might add support for sending email or connecting to a database. Some extensions add entire new frameworks to help build certain types of applications, like a REST API. Finding Extensions Flask extensions are usually named “Flask-Foo” or “Foo-Flask”. You can search PyPI for packages tagged with Framework :: Flask. Using Extensions Consult each extension’s documentation for installation, configuration, and usage instructions. Generally, extensions pull their own configuration from app.config and are passed an application instance during initialization. For example, an extension called “Flask-Foo” might be used like this: from flask_foo import Foo

foo = Foo()

app = Flask(__name__)
app.config.update(
    FOO_BAR='baz',
    FOO_SPAM='eggs',
)

foo.init_app(app)
 Building Extensions While the PyPI contains many Flask extensions, you may not find an extension that fits your need. If this is the case, you can create your own. Read Flask Extension Development to develop your own Flask extension.
flask.flash(message, category='message')  
Flashes a message to the next request. In order to remove the flashed message from the session and to display it to the user, the template has to call get_flashed_messages().  Changelog Changed in version 0.3: category parameter added.   Parameters 
 
message (str) – the message to be flashed. 
category (str) – the category for the message. The following values are recommended: 'message' for any kind of message, 'error' for errors, 'info' for information messages and 'warning' for warnings. However any kind of string can be used as category.   Return type 
None
add_template_filter(f, name=None)  
Register a custom template filter. Works exactly like the template_filter() decorator.  Parameters 
 
name (Optional[str]) – the optional name of the filter, otherwise the function name will be used. 
f (Callable[[Any], str]) –    Return type 
None
add_template_global(f, name=None)  
Register a custom template global function. Works exactly like the template_global() decorator.  Changelog New in version 0.10.   Parameters 
 
name (Optional[str]) – the optional name of the global function, otherwise the function name will be used. 
f (Callable[[], Any]) –    Return type 
None
add_template_test(f, name=None)  
Register a custom template test. Works exactly like the template_test() decorator.  Changelog New in version 0.10.   Parameters 
 
name (Optional[str]) – the optional name of the test, otherwise the function name will be used. 
f (Callable[[Any], bool]) –    Return type 
None
add_url_rule(rule, endpoint=None, view_func=None, provide_automatic_options=None, **options)  
Register a rule for routing incoming requests and building URLs. The route() decorator is a shortcut to call this with the view_func argument. These are equivalent: @app.route("/")
def index():
    ...
 def index():
    ...

app.add_url_rule("/", view_func=index)
 See URL Route Registrations. The endpoint name for the route defaults to the name of the view function if the endpoint parameter isn’t passed. An error will be raised if a function has already been registered for the endpoint. The methods parameter defaults to ["GET"]. HEAD is always added automatically, and OPTIONS is added automatically by default. view_func does not necessarily need to be passed, but if the rule should participate in routing an endpoint name must be associated with a view function at some point with the endpoint() decorator. app.add_url_rule("/", endpoint="index")

@app.endpoint("index")
def index():
    ...
 If view_func has a required_methods attribute, those methods are added to the passed and automatic methods. If it has a provide_automatic_methods attribute, it is used as the default if the parameter is not passed.  Parameters 
 
rule (str) – The URL rule string. 
endpoint (Optional[str]) – The endpoint name to associate with the rule and view function. Used when routing and building URLs. Defaults to view_func.__name__. 
view_func (Optional[Callable]) – The view function to associate with the endpoint name. 
provide_automatic_options (Optional[bool]) – Add the OPTIONS method and respond to OPTIONS requests automatically. 
options (Any) – Extra options passed to the Rule object.   Return type 
None
flask.appcontext_popped  
This signal is sent when an application context is popped. The sender is the application. This usually falls in line with the appcontext_tearing_down signal.  Changelog New in version 0.10.
flask.appcontext_pushed  
This signal is sent when an application context is pushed. The sender is the application. This is usually useful for unittests in order to temporarily hook in information. For instance it can be used to set a resource early onto the g object. Example usage: from contextlib import contextmanager
from flask import appcontext_pushed

@contextmanager
def user_set(app, user):
    def handler(sender, **kwargs):
        g.user = user
    with appcontext_pushed.connected_to(handler, app):
        yield
 And in the testcode: def test_user_me(self):
    with user_set(app, 'john'):
        c = app.test_client()
        resp = c.get('/users/me')
        assert resp.data == 'username=john'
  Changelog New in version 0.10.
flask.appcontext_tearing_down  
This signal is sent when the app context is tearing down. This is always called, even if an exception is caused. Currently functions listening to this signal are called after the regular teardown handlers, but this is not something you can rely on. Example subscriber: def close_db_connection(sender, **extra):
    session.close()

from flask import appcontext_tearing_down
appcontext_tearing_down.connect(close_db_connection, app)
 This will also be passed an exc keyword argument that has a reference to the exception that caused the teardown if there was one.
app_context()  
Create an AppContext. Use as a with block to push the context, which will make current_app point at this application. An application context is automatically pushed by RequestContext.push() when handling a request, and when running a CLI command. Use this to manually create a context outside of these situations. with app.app_context():
    init_db()
 See The Application Context.  Changelog New in version 0.9.   Return type 
flask.ctx.AppContext
app_ctx_globals_class  
alias of flask.ctx._AppCtxGlobals
async_to_sync(func)  
Return a sync function that will run the coroutine function. result = app.async_to_sync(func)(*args, **kwargs)
 Override this method to change how the app converts async code to be synchronously callable.  New in version 2.0.   Parameters 
func (Callable[[...], Coroutine]) –   Return type 
Callable[[…], Any]
auto_find_instance_path()  
Tries to locate the instance path if it was not provided to the constructor of the application class. It will basically calculate the path to a folder named instance next to your main file or the package.  Changelog New in version 0.8.   Return type 
str
before_first_request(f)  
Registers a function to be run before the first request to this instance of the application. The function will be called without any arguments and its return value is ignored.  Changelog New in version 0.8.   Parameters 
f (Callable[[], None]) –   Return type 
Callable[[], None]
before_first_request_funcs: t.List[BeforeRequestCallable]  
A list of functions that will be called at the beginning of the first request to this instance. To register a function, use the before_first_request() decorator.  Changelog New in version 0.8.
blueprints: t.Dict[str, ‘Blueprint’]  
Maps registered blueprint names to blueprint objects. The dict retains the order the blueprints were registered in. Blueprints can be registered multiple times, this dict does not track how often they were attached.  Changelog New in version 0.7.
flask.cli.run_command = <Command run>  
Run a local development server. This server is for development purposes only. It does not provide the stability, security, or performance of production WSGI servers. The reloader and debugger are enabled by default if FLASK_ENV=development or FLASK_DEBUG=1.  Parameters 
 
args (Any) –  
kwargs (Any) –    Return type 
Any
flask.cli.shell_command = <Command shell>  
Run an interactive Python shell in the context of a given Flask application. The application will populate the default namespace of this shell according to its configuration. This is useful for executing small snippets of management code without having to manually configure the application.  Parameters 
 
args (Any) –  
kwargs (Any) –    Return type 
Any
config  
The configuration dictionary as Config. This behaves exactly like a regular dictionary but supports additional methods to load a config from files.
create_global_jinja_loader()  
Creates the loader for the Jinja2 environment. Can be used to override just the loader and keeping the rest unchanged. It’s discouraged to override this function. Instead one should override the jinja_loader() function instead. The global loader dispatches between the loaders of the application and the individual blueprints.  Changelog New in version 0.7.   Return type 
flask.templating.DispatchingJinjaLoader
create_jinja_environment()  
Create the Jinja environment based on jinja_options and the various Jinja-related methods of the app. Changing jinja_options after this will have no effect. Also adds Flask-related globals and filters to the environment.  Changelog Changed in version 0.11: Environment.auto_reload set in accordance with TEMPLATES_AUTO_RELOAD configuration option.   New in version 0.5.   Return type 
flask.templating.Environment
create_url_adapter(request)  
Creates a URL adapter for the given request. The URL adapter is created at a point where the request context is not yet set up so the request is passed explicitly.  Changelog Changed in version 1.0: SERVER_NAME no longer implicitly enables subdomain matching. Use subdomain_matching instead.   Changed in version 0.9: This can now also be called without a request object when the URL adapter is created for the application context.   New in version 0.6.   Parameters 
request (Optional[flask.wrappers.Request]) –   Return type 
Optional[werkzeug.routing.MapAdapter]
flask.current_app  
A proxy to the application handling the current request. This is useful to access the application without needing to import it, or if it can’t be imported, such as when using the application factory pattern or in blueprints and extensions. This is only available when an application context is pushed. This happens automatically during requests and CLI commands. It can be controlled manually with app_context(). This is a proxy. See Notes On Proxies for more information.
default_config = {'APPLICATION_ROOT': '/', 'DEBUG': None, 'ENV': None, 'EXPLAIN_TEMPLATE_LOADING': False, 'JSONIFY_MIMETYPE': 'application/json', 'JSONIFY_PRETTYPRINT_REGULAR': False, 'JSON_AS_ASCII': True, 'JSON_SORT_KEYS': True, 'MAX_CONTENT_LENGTH': None, 'MAX_COOKIE_SIZE': 4093, 'PERMANENT_SESSION_LIFETIME': datetime.timedelta(days=31), 'PREFERRED_URL_SCHEME': 'http', 'PRESERVE_CONTEXT_ON_EXCEPTION': None, 'PROPAGATE_EXCEPTIONS': None, 'SECRET_KEY': None, 'SEND_FILE_MAX_AGE_DEFAULT': None, 'SERVER_NAME': None, 'SESSION_COOKIE_DOMAIN': None, 'SESSION_COOKIE_HTTPONLY': True, 'SESSION_COOKIE_NAME': 'session', 'SESSION_COOKIE_PATH': None, 'SESSION_COOKIE_SAMESITE': None, 'SESSION_COOKIE_SECURE': False, 'SESSION_REFRESH_EACH_REQUEST': True, 'TEMPLATES_AUTO_RELOAD': None, 'TESTING': False, 'TRAP_BAD_REQUEST_ERRORS': None, 'TRAP_HTTP_EXCEPTIONS': False, 'USE_X_SENDFILE': False}  
Default configuration parameters.