Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
QMTechDaughterboard.__init__
(self, io_standard)
because the board can be used with FPGAs core boards from different vendors, the constructor needs the vendor specific IOStandard
because the board can be used with FPGAs core boards from different vendors, the constructor needs the vendor specific IOStandard
def __init__(self, io_standard) -> None: """ because the board can be used with FPGAs core boards from different vendors, the constructor needs the vendor specific IOStandard """ self.io = [ ("serial", 0, Subsignal("rx", Pins("J2:15")), ...
[ "def", "__init__", "(", "self", ",", "io_standard", ")", "->", "None", ":", "self", ".", "io", "=", "[", "(", "\"serial\"", ",", "0", ",", "Subsignal", "(", "\"rx\"", ",", "Pins", "(", "\"J2:15\"", ")", ")", ",", "Subsignal", "(", "\"tx\"", ",", "P...
[ 9, 4 ]
[ 82, 9 ]
python
en
['en', 'error', 'th']
False
create_model
(architecture, classes_num)
Create a model Args: architecture(dict): architecture information, name(such as ResNet50) is needed image(variable): model input variable classes_num(int): num of classes Returns: out(variable): model output variable
Create a model
def create_model(architecture, classes_num): """ Create a model Args: architecture(dict): architecture information, name(such as ResNet50) is needed image(variable): model input variable classes_num(int): num of classes Returns: out(variable): model output v...
[ "def", "create_model", "(", "architecture", ",", "classes_num", ")", ":", "name", "=", "architecture", "[", "\"name\"", "]", "params", "=", "architecture", ".", "get", "(", "\"params\"", ",", "{", "}", ")", "return", "architectures", ".", "__dict__", "[", ...
[ 38, 0 ]
[ 53, 72 ]
python
en
['en', 'error', 'th']
False
create_loss
(feeds, out, architecture, classes_num=1000, epsilon=None, use_mix=False, use_distillation=False)
Create a loss for optimization, such as: 1. CrossEnotry loss 2. CrossEnotry loss with label smoothing 3. CrossEnotry loss with mix(mixup, cutmix, fmix) 4. CrossEnotry loss with label smoothing and (mixup, cutmix, fmix) 5. GoogLeNet loss Args: out(variable): mode...
Create a loss for optimization, such as: 1. CrossEnotry loss 2. CrossEnotry loss with label smoothing 3. CrossEnotry loss with mix(mixup, cutmix, fmix) 4. CrossEnotry loss with label smoothing and (mixup, cutmix, fmix) 5. GoogLeNet loss
def create_loss(feeds, out, architecture, classes_num=1000, epsilon=None, use_mix=False, use_distillation=False): """ Create a loss for optimization, such as: 1. CrossEnotry loss 2. CrossEnotry loss w...
[ "def", "create_loss", "(", "feeds", ",", "out", ",", "architecture", ",", "classes_num", "=", "1000", ",", "epsilon", "=", "None", ",", "use_mix", "=", "False", ",", "use_distillation", "=", "False", ")", ":", "if", "architecture", "[", "\"name\"", "]", ...
[ 56, 0 ]
[ 102, 40 ]
python
en
['en', 'error', 'th']
False
create_metric
(out, label, architecture, topk=5, classes_num=1000, use_distillation=False, mode="train")
Create measures of model accuracy, such as top1 and top5 Args: out(variable): model output variable feeds(dict): dict of model input variables(included label) topk(int): usually top5 classes_num(int): num of classes use_distillation(bool): whether to use distillation tr...
Create measures of model accuracy, such as top1 and top5
def create_metric(out, label, architecture, topk=5, classes_num=1000, use_distillation=False, mode="train"): """ Create measures of model accuracy, such as top1 and top5 Args: out(variable): ...
[ "def", "create_metric", "(", "out", ",", "label", ",", "architecture", ",", "topk", "=", "5", ",", "classes_num", "=", "1000", ",", "use_distillation", "=", "False", ",", "mode", "=", "\"train\"", ")", ":", "if", "architecture", "[", "\"name\"", "]", "==...
[ 105, 0 ]
[ 155, 17 ]
python
en
['en', 'error', 'th']
False
create_fetchs
(feeds, net, config, mode="train")
Create fetchs as model outputs(included loss and measures), will call create_loss and create_metric(if use_mix). Args: out(variable): model output variable feeds(dict): dict of model input variables. If use mix_up, it will not include label. architecture(dict): architec...
Create fetchs as model outputs(included loss and measures), will call create_loss and create_metric(if use_mix).
def create_fetchs(feeds, net, config, mode="train"): """ Create fetchs as model outputs(included loss and measures), will call create_loss and create_metric(if use_mix). Args: out(variable): model output variable feeds(dict): dict of model input variables. If use mix_up, it ...
[ "def", "create_fetchs", "(", "feeds", ",", "net", ",", "config", ",", "mode", "=", "\"train\"", ")", ":", "architecture", "=", "config", ".", "ARCHITECTURE", "topk", "=", "config", ".", "topk", "classes_num", "=", "config", ".", "classes_num", "epsilon", "...
[ 158, 0 ]
[ 200, 17 ]
python
en
['en', 'error', 'th']
False
create_optimizer
(config, parameter_list=None)
Create an optimizer using config, usually including learning rate and regularization. Args: config(dict): such as { 'LEARNING_RATE': {'function': 'Cosine', 'params': {'lr': 0.1} }, 'OPTIMIZER': {'func...
Create an optimizer using config, usually including learning rate and regularization.
def create_optimizer(config, parameter_list=None): """ Create an optimizer using config, usually including learning rate and regularization. Args: config(dict): such as { 'LEARNING_RATE': {'function': 'Cosine', 'params': {'lr': 0.1} ...
[ "def", "create_optimizer", "(", "config", ",", "parameter_list", "=", "None", ")", ":", "# create learning_rate instance", "lr_config", "=", "config", "[", "'LEARNING_RATE'", "]", "lr_config", "[", "'params'", "]", ".", "update", "(", "{", "'epochs'", ":", "conf...
[ 203, 0 ]
[ 238, 38 ]
python
en
['en', 'error', 'th']
False
run
(dataloader, config, net, optimizer=None, lr_scheduler=None, epoch=0, mode='train')
Feed data to the model and fetch the measures and loss Args: dataloader(paddle dataloader): exe(): program(): fetchs(dict): dict of measures and the loss epoch(int): epoch of training or validation model(str): log only Returns:
Feed data to the model and fetch the measures and loss
def run(dataloader, config, net, optimizer=None, lr_scheduler=None, epoch=0, mode='train'): """ Feed data to the model and fetch the measures and loss Args: dataloader(paddle dataloader): exe(): program(): fetchs(dict): dict of...
[ "def", "run", "(", "dataloader", ",", "config", ",", "net", ",", "optimizer", "=", "None", ",", "lr_scheduler", "=", "None", ",", "epoch", "=", "0", ",", "mode", "=", "'train'", ")", ":", "print_interval", "=", "config", ".", "get", "(", "\"print_inter...
[ 254, 0 ]
[ 375, 38 ]
python
en
['en', 'error', 'th']
False
make_signed_jwt
(signer, payload, key_id=None)
Make a signed JWT. See http://self-issued.info/docs/draft-jones-json-web-token.html. Args: signer: crypt.Signer, Cryptographic signer. payload: dict, Dictionary of data to convert to JSON and then sign. key_id: string, (Optional) Key ID header. Returns: string, The JWT for...
Make a signed JWT.
def make_signed_jwt(signer, payload, key_id=None): """Make a signed JWT. See http://self-issued.info/docs/draft-jones-json-web-token.html. Args: signer: crypt.Signer, Cryptographic signer. payload: dict, Dictionary of data to convert to JSON and then sign. key_id: string, (Optional...
[ "def", "make_signed_jwt", "(", "signer", ",", "payload", ",", "key_id", "=", "None", ")", ":", "header", "=", "{", "'typ'", ":", "'JWT'", ",", "'alg'", ":", "'RS256'", "}", "if", "key_id", "is", "not", "None", ":", "header", "[", "'kid'", "]", "=", ...
[ 73, 0 ]
[ 101, 30 ]
python
en
['en', 'da', 'en']
True
_verify_signature
(message, signature, certs)
Verifies signed content using a list of certificates. Args: message: string or bytes, The message to verify. signature: string or bytes, The signature on the message. certs: iterable, certificates in PEM format. Raises: AppIdentityError: If none of the certificates can verify t...
Verifies signed content using a list of certificates.
def _verify_signature(message, signature, certs): """Verifies signed content using a list of certificates. Args: message: string or bytes, The message to verify. signature: string or bytes, The signature on the message. certs: iterable, certificates in PEM format. Raises: A...
[ "def", "_verify_signature", "(", "message", ",", "signature", ",", "certs", ")", ":", "for", "pem", "in", "certs", ":", "verifier", "=", "Verifier", ".", "from_string", "(", "pem", ",", "is_x509_cert", "=", "True", ")", "if", "verifier", ".", "verify", "...
[ 104, 0 ]
[ 122, 53 ]
python
en
['en', 'en', 'en']
True
_check_audience
(payload_dict, audience)
Checks audience field from a JWT payload. Does nothing if the passed in ``audience`` is null. Args: payload_dict: dict, A dictionary containing a JWT payload. audience: string or NoneType, an audience to check for in the JWT payload. Raises: AppIdentityError: If ...
Checks audience field from a JWT payload.
def _check_audience(payload_dict, audience): """Checks audience field from a JWT payload. Does nothing if the passed in ``audience`` is null. Args: payload_dict: dict, A dictionary containing a JWT payload. audience: string or NoneType, an audience to check for in the JWT...
[ "def", "_check_audience", "(", "payload_dict", ",", "audience", ")", ":", "if", "audience", "is", "None", ":", "return", "audience_in_payload", "=", "payload_dict", ".", "get", "(", "'aud'", ")", "if", "audience_in_payload", "is", "None", ":", "raise", "AppIde...
[ 125, 0 ]
[ 150, 57 ]
python
en
['en', 'en', 'en']
True
_verify_time_range
(payload_dict)
Verifies the issued at and expiration from a JWT payload. Makes sure the current time (in UTC) falls between the issued at and expiration for the JWT (with some skew allowed for via ``CLOCK_SKEW_SECS``). Args: payload_dict: dict, A dictionary containing a JWT payload. Raises: AppI...
Verifies the issued at and expiration from a JWT payload.
def _verify_time_range(payload_dict): """Verifies the issued at and expiration from a JWT payload. Makes sure the current time (in UTC) falls between the issued at and expiration for the JWT (with some skew allowed for via ``CLOCK_SKEW_SECS``). Args: payload_dict: dict, A dictionary contai...
[ "def", "_verify_time_range", "(", "payload_dict", ")", ":", "# Get the current time to use throughout.", "now", "=", "int", "(", "time", ".", "time", "(", ")", ")", "# Make sure issued at and expiration are in the payload.", "issued_at", "=", "payload_dict", ".", "get", ...
[ 153, 0 ]
[ 203, 39 ]
python
en
['en', 'en', 'en']
True
verify_signed_jwt_with_certs
(jwt, certs, audience=None)
Verify a JWT against public certs. See http://self-issued.info/docs/draft-jones-json-web-token.html. Args: jwt: string, A JWT. certs: dict, Dictionary where values of public keys in PEM format. audience: string, The audience, 'aud', that this JWT should contain. If No...
Verify a JWT against public certs.
def verify_signed_jwt_with_certs(jwt, certs, audience=None): """Verify a JWT against public certs. See http://self-issued.info/docs/draft-jones-json-web-token.html. Args: jwt: string, A JWT. certs: dict, Dictionary where values of public keys in PEM format. audience: string, The au...
[ "def", "verify_signed_jwt_with_certs", "(", "jwt", ",", "certs", ",", "audience", "=", "None", ")", ":", "jwt", "=", "_helpers", ".", "_to_bytes", "(", "jwt", ")", "if", "jwt", ".", "count", "(", "b'.'", ")", "!=", "2", ":", "raise", "AppIdentityError", ...
[ 206, 0 ]
[ 249, 23 ]
python
en
['en', 'fr', 'en']
True
EmailBackend.open
(self)
Ensure an open connection to the email server. Return whether or not a new connection was required (True or False) or None if an exception passed silently.
Ensure an open connection to the email server. Return whether or not a new connection was required (True or False) or None if an exception passed silently.
def open(self): """ Ensure an open connection to the email server. Return whether or not a new connection was required (True or False) or None if an exception passed silently. """ if self.connection: # Nothing to do if the connection is already open. ...
[ "def", "open", "(", "self", ")", ":", "if", "self", ".", "connection", ":", "# Nothing to do if the connection is already open.", "return", "False", "# If local_hostname is not specified, socket.getfqdn() gets used.", "# For performance, we use the cached FQDN for local_hostname.", "...
[ 40, 4 ]
[ 72, 21 ]
python
en
['en', 'error', 'th']
False
EmailBackend.close
(self)
Close the connection to the email server.
Close the connection to the email server.
def close(self): """Close the connection to the email server.""" if self.connection is None: return try: try: self.connection.quit() except (ssl.SSLError, smtplib.SMTPServerDisconnected): # This happens when calling quit() on a ...
[ "def", "close", "(", "self", ")", ":", "if", "self", ".", "connection", "is", "None", ":", "return", "try", ":", "try", ":", "self", ".", "connection", ".", "quit", "(", ")", "except", "(", "ssl", ".", "SSLError", ",", "smtplib", ".", "SMTPServerDisc...
[ 74, 4 ]
[ 91, 34 ]
python
en
['en', 'en', 'en']
True
EmailBackend.send_messages
(self, email_messages)
Send one or more EmailMessage objects and return the number of email messages sent.
Send one or more EmailMessage objects and return the number of email messages sent.
def send_messages(self, email_messages): """ Send one or more EmailMessage objects and return the number of email messages sent. """ if not email_messages: return 0 with self._lock: new_conn_created = self.open() if not self.connection ...
[ "def", "send_messages", "(", "self", ",", "email_messages", ")", ":", "if", "not", "email_messages", ":", "return", "0", "with", "self", ".", "_lock", ":", "new_conn_created", "=", "self", ".", "open", "(", ")", "if", "not", "self", ".", "connection", "o...
[ 93, 4 ]
[ 113, 23 ]
python
en
['en', 'error', 'th']
False
EmailBackend._send
(self, email_message)
A helper method that does the actual sending.
A helper method that does the actual sending.
def _send(self, email_message): """A helper method that does the actual sending.""" if not email_message.recipients(): return False encoding = email_message.encoding or settings.DEFAULT_CHARSET from_email = sanitize_address(email_message.from_email, encoding) recipien...
[ "def", "_send", "(", "self", ",", "email_message", ")", ":", "if", "not", "email_message", ".", "recipients", "(", ")", ":", "return", "False", "encoding", "=", "email_message", ".", "encoding", "or", "settings", ".", "DEFAULT_CHARSET", "from_email", "=", "s...
[ 115, 4 ]
[ 129, 19 ]
python
en
['en', 'en', 'en']
True
setupmethod
(f)
Wraps a method so that it performs a check in debug mode if the first request was already handled.
Wraps a method so that it performs a check in debug mode if the first request was already handled.
def setupmethod(f): """Wraps a method so that it performs a check in debug mode if the first request was already handled. """ def wrapper_func(self, *args, **kwargs): if self.debug and self._got_first_request: raise AssertionError('A setup function was called after the ' ...
[ "def", "setupmethod", "(", "f", ")", ":", "def", "wrapper_func", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "debug", "and", "self", ".", "_got_first_request", ":", "raise", "AssertionError", "(", "'A setup functi...
[ 50, 0 ]
[ 64, 42 ]
python
en
['en', 'en', 'en']
True
Flask.name
(self)
The name of the application. This is usually the import name with the difference that it's guessed from the run file if the import name is main. This name is used as a display name when Flask needs the name of the application. It can be set and overridden to change the value. ...
The name of the application. This is usually the import name with the difference that it's guessed from the run file if the import name is main. This name is used as a display name when Flask needs the name of the application. It can be set and overridden to change the value.
def name(self): """The name of the application. This is usually the import name with the difference that it's guessed from the run file if the import name is main. This name is used as a display name when Flask needs the name of the application. It can be set and overridden to...
[ "def", "name", "(", "self", ")", ":", "if", "self", ".", "import_name", "==", "'__main__'", ":", "fn", "=", "getattr", "(", "sys", ".", "modules", "[", "'__main__'", "]", ",", "'__file__'", ",", "None", ")", "if", "fn", "is", "None", ":", "return", ...
[ 562, 4 ]
[ 576, 31 ]
python
en
['en', 'en', 'en']
True
Flask.propagate_exceptions
(self)
Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration value in case it's set, otherwise a sensible default is returned. .. versionadded:: 0.7
Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration value in case it's set, otherwise a sensible default is returned.
def propagate_exceptions(self): """Returns the value of the ``PROPAGATE_EXCEPTIONS`` configuration value in case it's set, otherwise a sensible default is returned. .. versionadded:: 0.7 """ rv = self.config['PROPAGATE_EXCEPTIONS'] if rv is not None: return r...
[ "def", "propagate_exceptions", "(", "self", ")", ":", "rv", "=", "self", ".", "config", "[", "'PROPAGATE_EXCEPTIONS'", "]", "if", "rv", "is", "not", "None", ":", "return", "rv", "return", "self", ".", "testing", "or", "self", ".", "debug" ]
[ 579, 4 ]
[ 588, 41 ]
python
en
['en', 'en', 'en']
True
Flask.preserve_context_on_exception
(self)
Returns the value of the ``PRESERVE_CONTEXT_ON_EXCEPTION`` configuration value in case it's set, otherwise a sensible default is returned. .. versionadded:: 0.7
Returns the value of the ``PRESERVE_CONTEXT_ON_EXCEPTION`` configuration value in case it's set, otherwise a sensible default is returned.
def preserve_context_on_exception(self): """Returns the value of the ``PRESERVE_CONTEXT_ON_EXCEPTION`` configuration value in case it's set, otherwise a sensible default is returned. .. versionadded:: 0.7 """ rv = self.config['PRESERVE_CONTEXT_ON_EXCEPTION'] if r...
[ "def", "preserve_context_on_exception", "(", "self", ")", ":", "rv", "=", "self", ".", "config", "[", "'PRESERVE_CONTEXT_ON_EXCEPTION'", "]", "if", "rv", "is", "not", "None", ":", "return", "rv", "return", "self", ".", "debug" ]
[ 591, 4 ]
[ 601, 25 ]
python
en
['en', 'en', 'en']
True
Flask.logger
(self)
A :class:`logging.Logger` object for this application. The default configuration is to log to stderr if the application is in debug mode. This logger can be used to (surprise) log messages. Here some examples:: app.logger.debug('A value for debugging') app.logger.warni...
A :class:`logging.Logger` object for this application. The default configuration is to log to stderr if the application is in debug mode. This logger can be used to (surprise) log messages. Here some examples::
def logger(self): """A :class:`logging.Logger` object for this application. The default configuration is to log to stderr if the application is in debug mode. This logger can be used to (surprise) log messages. Here some examples:: app.logger.debug('A value for debugging')...
[ "def", "logger", "(", "self", ")", ":", "if", "self", ".", "_logger", "and", "self", ".", "_logger", ".", "name", "==", "self", ".", "logger_name", ":", "return", "self", ".", "_logger", "with", "_logger_lock", ":", "if", "self", ".", "_logger", "and",...
[ 604, 4 ]
[ 623, 21 ]
python
en
['en', 'en', 'en']
True
Flask.jinja_env
(self)
The Jinja2 environment used to load templates.
The Jinja2 environment used to load templates.
def jinja_env(self): """The Jinja2 environment used to load templates.""" return self.create_jinja_environment()
[ "def", "jinja_env", "(", "self", ")", ":", "return", "self", ".", "create_jinja_environment", "(", ")" ]
[ 626, 4 ]
[ 628, 46 ]
python
en
['en', 'en', 'en']
True
Flask.got_first_request
(self)
This attribute is set to ``True`` if the application started handling the first request. .. versionadded:: 0.8
This attribute is set to ``True`` if the application started handling the first request.
def got_first_request(self): """This attribute is set to ``True`` if the application started handling the first request. .. versionadded:: 0.8 """ return self._got_first_request
[ "def", "got_first_request", "(", "self", ")", ":", "return", "self", ".", "_got_first_request" ]
[ 631, 4 ]
[ 637, 38 ]
python
en
['en', 'en', 'en']
True
Flask.make_config
(self, instance_relative=False)
Used to create the config attribute by the Flask constructor. The `instance_relative` parameter is passed in from the constructor of Flask (there named `instance_relative_config`) and indicates if the config should be relative to the instance path or the root path of the application. ...
Used to create the config attribute by the Flask constructor. The `instance_relative` parameter is passed in from the constructor of Flask (there named `instance_relative_config`) and indicates if the config should be relative to the instance path or the root path of the application.
def make_config(self, instance_relative=False): """Used to create the config attribute by the Flask constructor. The `instance_relative` parameter is passed in from the constructor of Flask (there named `instance_relative_config`) and indicates if the config should be relative to the ins...
[ "def", "make_config", "(", "self", ",", "instance_relative", "=", "False", ")", ":", "root_path", "=", "self", ".", "root_path", "if", "instance_relative", ":", "root_path", "=", "self", ".", "instance_path", "return", "self", ".", "config_class", "(", "root_p...
[ 639, 4 ]
[ 651, 64 ]
python
en
['en', 'en', 'en']
True
Flask.auto_find_instance_path
(self)
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. .. versionadded:: 0.8
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.
def auto_find_instance_path(self): """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. .. versionadded:: 0.8 "...
[ "def", "auto_find_instance_path", "(", "self", ")", ":", "prefix", ",", "package_path", "=", "find_package", "(", "self", ".", "import_name", ")", "if", "prefix", "is", "None", ":", "return", "os", ".", "path", ".", "join", "(", "package_path", ",", "'inst...
[ 653, 4 ]
[ 664, 67 ]
python
en
['en', 'en', 'en']
True
Flask.open_instance_resource
(self, resource, mode='rb')
Opens a resource from the application's instance folder (:attr:`instance_path`). Otherwise works like :meth:`open_resource`. Instance resources can also be opened for writing. :param resource: the name of the resource. To access resources within subfolders us...
Opens a resource from the application's instance folder (:attr:`instance_path`). Otherwise works like :meth:`open_resource`. Instance resources can also be opened for writing.
def open_instance_resource(self, resource, mode='rb'): """Opens a resource from the application's instance folder (:attr:`instance_path`). Otherwise works like :meth:`open_resource`. Instance resources can also be opened for writing. :param resource: the name of the resource. ...
[ "def", "open_instance_resource", "(", "self", ",", "resource", ",", "mode", "=", "'rb'", ")", ":", "return", "open", "(", "os", ".", "path", ".", "join", "(", "self", ".", "instance_path", ",", "resource", ")", ",", "mode", ")" ]
[ 666, 4 ]
[ 676, 69 ]
python
en
['en', 'en', 'en']
True
Flask.create_jinja_environment
(self)
Creates the Jinja2 environment based on :attr:`jinja_options` and :meth:`select_jinja_autoescape`. Since 0.7 this also adds the Jinja2 globals and filters after initialization. Override this function to customize the behavior. .. versionadded:: 0.5 .. versionchanged:: 0.11 ...
Creates the Jinja2 environment based on :attr:`jinja_options` and :meth:`select_jinja_autoescape`. Since 0.7 this also adds the Jinja2 globals and filters after initialization. Override this function to customize the behavior.
def create_jinja_environment(self): """Creates the Jinja2 environment based on :attr:`jinja_options` and :meth:`select_jinja_autoescape`. Since 0.7 this also adds the Jinja2 globals and filters after initialization. Override this function to customize the behavior. .. versiona...
[ "def", "create_jinja_environment", "(", "self", ")", ":", "options", "=", "dict", "(", "self", ".", "jinja_options", ")", "if", "'autoescape'", "not", "in", "options", ":", "options", "[", "'autoescape'", "]", "=", "self", ".", "select_jinja_autoescape", "if",...
[ 678, 4 ]
[ 710, 17 ]
python
en
['en', 'et', 'en']
True
Flask.create_global_jinja_loader
(self)
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 :meth:`jinja_loader` function instead. The global loader dispatches between the loaders o...
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 :meth:`jinja_loader` function instead.
def create_global_jinja_loader(self): """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 :meth:`jinja_loader` function instead. T...
[ "def", "create_global_jinja_loader", "(", "self", ")", ":", "return", "DispatchingJinjaLoader", "(", "self", ")" ]
[ 712, 4 ]
[ 723, 43 ]
python
en
['en', 'en', 'en']
True
Flask.init_jinja_globals
(self)
Deprecated. Used to initialize the Jinja2 globals. .. versionadded:: 0.5 .. versionchanged:: 0.7 This method is deprecated with 0.7. Override :meth:`create_jinja_environment` instead.
Deprecated. Used to initialize the Jinja2 globals.
def init_jinja_globals(self): """Deprecated. Used to initialize the Jinja2 globals. .. versionadded:: 0.5 .. versionchanged:: 0.7 This method is deprecated with 0.7. Override :meth:`create_jinja_environment` instead. """
[ "def", "init_jinja_globals", "(", "self", ")", ":" ]
[ 725, 4 ]
[ 732, 11 ]
python
en
['en', 'en', 'en']
True
Flask.select_jinja_autoescape
(self, filename)
Returns ``True`` if autoescaping should be active for the given template name. If no template name is given, returns `True`. .. versionadded:: 0.5
Returns ``True`` if autoescaping should be active for the given template name. If no template name is given, returns `True`.
def select_jinja_autoescape(self, filename): """Returns ``True`` if autoescaping should be active for the given template name. If no template name is given, returns `True`. .. versionadded:: 0.5 """ if filename is None: return True return filename.endswith(('...
[ "def", "select_jinja_autoescape", "(", "self", ",", "filename", ")", ":", "if", "filename", "is", "None", ":", "return", "True", "return", "filename", ".", "endswith", "(", "(", "'.html'", ",", "'.htm'", ",", "'.xml'", ",", "'.xhtml'", ")", ")" ]
[ 734, 4 ]
[ 742, 69 ]
python
en
['en', 'en', 'en']
True
Flask.update_template_context
(self, context)
Update the template context with some commonly used variables. This injects request, session, config and g into the template context as well as everything template context processors want to inject. Note that the as of Flask 0.6, the original values in the context will not be overridden...
Update the template context with some commonly used variables. This injects request, session, config and g into the template context as well as everything template context processors want to inject. Note that the as of Flask 0.6, the original values in the context will not be overridden...
def update_template_context(self, context): """Update the template context with some commonly used variables. This injects request, session, config and g into the template context as well as everything template context processors want to inject. Note that the as of Flask 0.6, the origin...
[ "def", "update_template_context", "(", "self", ",", "context", ")", ":", "funcs", "=", "self", ".", "template_context_processors", "[", "None", "]", "reqctx", "=", "_request_ctx_stack", ".", "top", "if", "reqctx", "is", "not", "None", ":", "bp", "=", "reqctx...
[ 744, 4 ]
[ 767, 32 ]
python
en
['en', 'en', 'en']
True
Flask.make_shell_context
(self)
Returns the shell context for an interactive shell for this application. This runs all the registered shell context processors. .. versionadded:: 0.11
Returns the shell context for an interactive shell for this application. This runs all the registered shell context processors.
def make_shell_context(self): """Returns the shell context for an interactive shell for this application. This runs all the registered shell context processors. .. versionadded:: 0.11 """ rv = {'app': self, 'g': g} for processor in self.shell_context_processors:...
[ "def", "make_shell_context", "(", "self", ")", ":", "rv", "=", "{", "'app'", ":", "self", ",", "'g'", ":", "g", "}", "for", "processor", "in", "self", ".", "shell_context_processors", ":", "rv", ".", "update", "(", "processor", "(", ")", ")", "return",...
[ 769, 4 ]
[ 779, 17 ]
python
en
['en', 'en', 'en']
True
Flask.run
(self, host=None, port=None, debug=None, **options)
Runs the application on a local development server. Do not use ``run()`` in a production setting. It is not intended to meet security and performance requirements for a production server. Instead, see :ref:`deployment` for WSGI server recommendations. If the :attr:`debug` flag is set t...
Runs the application on a local development server.
def run(self, host=None, port=None, debug=None, **options): """Runs the application on a local development server. Do not use ``run()`` in a production setting. It is not intended to meet security and performance requirements for a production server. Instead, see :ref:`deployment` for W...
[ "def", "run", "(", "self", ",", "host", "=", "None", ",", "port", "=", "None", ",", "debug", "=", "None", ",", "*", "*", "options", ")", ":", "from", "werkzeug", ".", "serving", "import", "run_simple", "if", "host", "is", "None", ":", "host", "=", ...
[ 781, 4 ]
[ 845, 43 ]
python
en
['en', 'en', 'en']
True
Flask.test_client
(self, use_cookies=True, **kwargs)
Creates a test client for this application. For information about unit testing head over to :ref:`testing`. Note that if you are testing for assertions or exceptions in your application code, you must set ``app.testing = True`` in order for the exceptions to propagate to the test clien...
Creates a test client for this application. For information about unit testing head over to :ref:`testing`.
def test_client(self, use_cookies=True, **kwargs): """Creates a test client for this application. For information about unit testing head over to :ref:`testing`. Note that if you are testing for assertions or exceptions in your application code, you must set ``app.testing = True`` in o...
[ "def", "test_client", "(", "self", ",", "use_cookies", "=", "True", ",", "*", "*", "kwargs", ")", ":", "cls", "=", "self", ".", "test_client_class", "if", "cls", "is", "None", ":", "from", "flask", ".", "testing", "import", "FlaskClient", "as", "cls", ...
[ 847, 4 ]
[ 901, 80 ]
python
en
['en', 'en', 'en']
True
Flask.open_session
(self, request)
Creates or opens a new session. Default implementation stores all session data in a signed cookie. This requires that the :attr:`secret_key` is set. Instead of overriding this method we recommend replacing the :class:`session_interface`. :param request: an instance of :attr:`request_...
Creates or opens a new session. Default implementation stores all session data in a signed cookie. This requires that the :attr:`secret_key` is set. Instead of overriding this method we recommend replacing the :class:`session_interface`.
def open_session(self, request): """Creates or opens a new session. Default implementation stores all session data in a signed cookie. This requires that the :attr:`secret_key` is set. Instead of overriding this method we recommend replacing the :class:`session_interface`. :p...
[ "def", "open_session", "(", "self", ",", "request", ")", ":", "return", "self", ".", "session_interface", ".", "open_session", "(", "self", ",", "request", ")" ]
[ 903, 4 ]
[ 911, 65 ]
python
en
['en', 'en', 'en']
True
Flask.save_session
(self, session, response)
Saves the session if it needs updates. For the default implementation, check :meth:`open_session`. Instead of overriding this method we recommend replacing the :class:`session_interface`. :param session: the session to be saved (a :class:`~werkzeug.contrib.securecookie...
Saves the session if it needs updates. For the default implementation, check :meth:`open_session`. Instead of overriding this method we recommend replacing the :class:`session_interface`.
def save_session(self, session, response): """Saves the session if it needs updates. For the default implementation, check :meth:`open_session`. Instead of overriding this method we recommend replacing the :class:`session_interface`. :param session: the session to be saved (a ...
[ "def", "save_session", "(", "self", ",", "session", ",", "response", ")", ":", "return", "self", ".", "session_interface", ".", "save_session", "(", "self", ",", "session", ",", "response", ")" ]
[ 913, 4 ]
[ 923, 75 ]
python
en
['en', 'en', 'en']
True
Flask.make_null_session
(self)
Creates a new instance of a missing session. Instead of overriding this method we recommend replacing the :class:`session_interface`. .. versionadded:: 0.7
Creates a new instance of a missing session. Instead of overriding this method we recommend replacing the :class:`session_interface`.
def make_null_session(self): """Creates a new instance of a missing session. Instead of overriding this method we recommend replacing the :class:`session_interface`. .. versionadded:: 0.7 """ return self.session_interface.make_null_session(self)
[ "def", "make_null_session", "(", "self", ")", ":", "return", "self", ".", "session_interface", ".", "make_null_session", "(", "self", ")" ]
[ 925, 4 ]
[ 931, 61 ]
python
en
['en', 'en', 'en']
True
Flask.register_blueprint
(self, blueprint, **options)
Registers a blueprint on the application. .. versionadded:: 0.7
Registers a blueprint on the application.
def register_blueprint(self, blueprint, **options): """Registers a blueprint on the application. .. versionadded:: 0.7 """ first_registration = False if blueprint.name in self.blueprints: assert self.blueprints[blueprint.name] is blueprint, \ 'A bluep...
[ "def", "register_blueprint", "(", "self", ",", "blueprint", ",", "*", "*", "options", ")", ":", "first_registration", "=", "False", "if", "blueprint", ".", "name", "in", "self", ".", "blueprints", ":", "assert", "self", ".", "blueprints", "[", "blueprint", ...
[ 934, 4 ]
[ 950, 61 ]
python
en
['en', 'en', 'en']
True
Flask.iter_blueprints
(self)
Iterates over all blueprints by the order they were registered. .. versionadded:: 0.11
Iterates over all blueprints by the order they were registered.
def iter_blueprints(self): """Iterates over all blueprints by the order they were registered. .. versionadded:: 0.11 """ return iter(self._blueprint_order)
[ "def", "iter_blueprints", "(", "self", ")", ":", "return", "iter", "(", "self", ".", "_blueprint_order", ")" ]
[ 952, 4 ]
[ 957, 42 ]
python
en
['en', 'en', 'en']
True
Flask.add_url_rule
(self, rule, endpoint=None, view_func=None, **options)
Connects a URL rule. Works exactly like the :meth:`route` decorator. If a view_func is provided it will be registered with the endpoint. Basically this example:: @app.route('/') def index(): pass Is equivalent to the following:: d...
Connects a URL rule. Works exactly like the :meth:`route` decorator. If a view_func is provided it will be registered with the endpoint.
def add_url_rule(self, rule, endpoint=None, view_func=None, **options): """Connects a URL rule. Works exactly like the :meth:`route` decorator. If a view_func is provided it will be registered with the endpoint. Basically this example:: @app.route('/') def ind...
[ "def", "add_url_rule", "(", "self", ",", "rule", ",", "endpoint", "=", "None", ",", "view_func", "=", "None", ",", "*", "*", "options", ")", ":", "if", "endpoint", "is", "None", ":", "endpoint", "=", "_endpoint_from_view_func", "(", "view_func", ")", "op...
[ 960, 4 ]
[ 1051, 53 ]
python
en
['en', 'en', 'en']
True
Flask.route
(self, rule, **options)
A decorator that is used to register a view function for a given URL rule. This does the same thing as :meth:`add_url_rule` but is intended for decorator usage:: @app.route('/') def index(): return 'Hello World' For more information refer to :ref:`url-r...
A decorator that is used to register a view function for a given URL rule. This does the same thing as :meth:`add_url_rule` but is intended for decorator usage::
def route(self, rule, **options): """A decorator that is used to register a view function for a given URL rule. This does the same thing as :meth:`add_url_rule` but is intended for decorator usage:: @app.route('/') def index(): return 'Hello World' ...
[ "def", "route", "(", "self", ",", "rule", ",", "*", "*", "options", ")", ":", "def", "decorator", "(", "f", ")", ":", "endpoint", "=", "options", ".", "pop", "(", "'endpoint'", ",", "None", ")", "self", ".", "add_url_rule", "(", "rule", ",", "endpo...
[ 1053, 4 ]
[ 1081, 24 ]
python
en
['en', 'en', 'en']
True
Flask.endpoint
(self, endpoint)
A decorator to register a function as an endpoint. Example:: @app.endpoint('example.endpoint') def example(): return "example" :param endpoint: the name of the endpoint
A decorator to register a function as an endpoint. Example::
def endpoint(self, endpoint): """A decorator to register a function as an endpoint. Example:: @app.endpoint('example.endpoint') def example(): return "example" :param endpoint: the name of the endpoint """ def decorator(f): se...
[ "def", "endpoint", "(", "self", ",", "endpoint", ")", ":", "def", "decorator", "(", "f", ")", ":", "self", ".", "view_functions", "[", "endpoint", "]", "=", "f", "return", "f", "return", "decorator" ]
[ 1084, 4 ]
[ 1097, 24 ]
python
en
['en', 'en', 'en']
True
Flask._get_exc_class_and_code
(exc_class_or_code)
Ensure that we register only exceptions as handler keys
Ensure that we register only exceptions as handler keys
def _get_exc_class_and_code(exc_class_or_code): """Ensure that we register only exceptions as handler keys""" if isinstance(exc_class_or_code, integer_types): exc_class = default_exceptions[exc_class_or_code] else: exc_class = exc_class_or_code assert issubclass(...
[ "def", "_get_exc_class_and_code", "(", "exc_class_or_code", ")", ":", "if", "isinstance", "(", "exc_class_or_code", ",", "integer_types", ")", ":", "exc_class", "=", "default_exceptions", "[", "exc_class_or_code", "]", "else", ":", "exc_class", "=", "exc_class_or_code...
[ 1100, 4 ]
[ 1112, 34 ]
python
en
['en', 'en', 'en']
True
Flask.errorhandler
(self, code_or_exception)
A decorator that is used to register a function given an error code. Example:: @app.errorhandler(404) def page_not_found(error): return 'This page does not exist', 404 You can also register handlers for arbitrary exceptions:: @app.errorhandler(Data...
A decorator that is used to register a function given an error code. Example::
def errorhandler(self, code_or_exception): """A decorator that is used to register a function given an error code. Example:: @app.errorhandler(404) def page_not_found(error): return 'This page does not exist', 404 You can also register handlers for arbi...
[ "def", "errorhandler", "(", "self", ",", "code_or_exception", ")", ":", "def", "decorator", "(", "f", ")", ":", "self", ".", "_register_error_handler", "(", "None", ",", "code_or_exception", ",", "f", ")", "return", "f", "return", "decorator" ]
[ 1115, 4 ]
[ 1160, 24 ]
python
en
['en', 'en', 'en']
True
Flask.register_error_handler
(self, code_or_exception, f)
Alternative error attach function to the :meth:`errorhandler` decorator that is more straightforward to use for non decorator usage. .. versionadded:: 0.7
Alternative error attach function to the :meth:`errorhandler` decorator that is more straightforward to use for non decorator usage.
def register_error_handler(self, code_or_exception, f): """Alternative error attach function to the :meth:`errorhandler` decorator that is more straightforward to use for non decorator usage. .. versionadded:: 0.7 """ self._register_error_handler(None, code_or_exception,...
[ "def", "register_error_handler", "(", "self", ",", "code_or_exception", ",", "f", ")", ":", "self", ".", "_register_error_handler", "(", "None", ",", "code_or_exception", ",", "f", ")" ]
[ 1162, 4 ]
[ 1169, 64 ]
python
en
['en', 'de', 'en']
True
Flask._register_error_handler
(self, key, code_or_exception, f)
:type key: None|str :type code_or_exception: int|T<=Exception :type f: callable
:type key: None|str :type code_or_exception: int|T<=Exception :type f: callable
def _register_error_handler(self, key, code_or_exception, f): """ :type key: None|str :type code_or_exception: int|T<=Exception :type f: callable """ if isinstance(code_or_exception, HTTPException): # old broken behavior raise ValueError( 'Tri...
[ "def", "_register_error_handler", "(", "self", ",", "key", ",", "code_or_exception", ",", "f", ")", ":", "if", "isinstance", "(", "code_or_exception", ",", "HTTPException", ")", ":", "# old broken behavior", "raise", "ValueError", "(", "'Tried to register a handler fo...
[ 1172, 4 ]
[ 1187, 31 ]
python
en
['en', 'error', 'th']
False
Flask.template_filter
(self, name=None)
A decorator that is used to register custom template filter. You can specify a name for the filter, otherwise the function name will be used. Example:: @app.template_filter() def reverse(s): return s[::-1] :param name: the optional name of the filter, otherwis...
A decorator that is used to register custom template filter. You can specify a name for the filter, otherwise the function name will be used. Example::
def template_filter(self, name=None): """A decorator that is used to register custom template filter. You can specify a name for the filter, otherwise the function name will be used. Example:: @app.template_filter() def reverse(s): return s[::-1] :para...
[ "def", "template_filter", "(", "self", ",", "name", "=", "None", ")", ":", "def", "decorator", "(", "f", ")", ":", "self", ".", "add_template_filter", "(", "f", ",", "name", "=", "name", ")", "return", "f", "return", "decorator" ]
[ 1190, 4 ]
[ 1205, 24 ]
python
en
['en', 'en', 'en']
True
Flask.add_template_filter
(self, f, name=None)
Register a custom template filter. Works exactly like the :meth:`template_filter` decorator. :param name: the optional name of the filter, otherwise the function name will be used.
Register a custom template filter. Works exactly like the :meth:`template_filter` decorator.
def add_template_filter(self, f, name=None): """Register a custom template filter. Works exactly like the :meth:`template_filter` decorator. :param name: the optional name of the filter, otherwise the function name will be used. """ self.jinja_env.filters[n...
[ "def", "add_template_filter", "(", "self", ",", "f", ",", "name", "=", "None", ")", ":", "self", ".", "jinja_env", ".", "filters", "[", "name", "or", "f", ".", "__name__", "]", "=", "f" ]
[ 1208, 4 ]
[ 1215, 54 ]
python
en
['en', 'en', 'en']
True
Flask.template_test
(self, name=None)
A decorator that is used to register custom template test. You can specify a name for the test, otherwise the function name will be used. Example:: @app.template_test() def is_prime(n): if n == 2: return True for i in range(2, int(math.c...
A decorator that is used to register custom template test. You can specify a name for the test, otherwise the function name will be used. Example::
def template_test(self, name=None): """A decorator that is used to register custom template test. You can specify a name for the test, otherwise the function name will be used. Example:: @app.template_test() def is_prime(n): if n == 2: return ...
[ "def", "template_test", "(", "self", ",", "name", "=", "None", ")", ":", "def", "decorator", "(", "f", ")", ":", "self", ".", "add_template_test", "(", "f", ",", "name", "=", "name", ")", "return", "f", "return", "decorator" ]
[ 1218, 4 ]
[ 1240, 24 ]
python
en
['en', 'en', 'en']
True
Flask.add_template_test
(self, f, name=None)
Register a custom template test. Works exactly like the :meth:`template_test` decorator. .. versionadded:: 0.10 :param name: the optional name of the test, otherwise the function name will be used.
Register a custom template test. Works exactly like the :meth:`template_test` decorator.
def add_template_test(self, f, name=None): """Register a custom template test. Works exactly like the :meth:`template_test` decorator. .. versionadded:: 0.10 :param name: the optional name of the test, otherwise the function name will be used. """ ...
[ "def", "add_template_test", "(", "self", ",", "f", ",", "name", "=", "None", ")", ":", "self", ".", "jinja_env", ".", "tests", "[", "name", "or", "f", ".", "__name__", "]", "=", "f" ]
[ 1243, 4 ]
[ 1252, 52 ]
python
en
['en', 'en', 'en']
True
Flask.template_global
(self, name=None)
A decorator that is used to register a custom template global function. You can specify a name for the global function, otherwise the function name will be used. Example:: @app.template_global() def double(n): return 2 * n .. versionadded:: 0.10 ...
A decorator that is used to register a custom template global function. You can specify a name for the global function, otherwise the function name will be used. Example::
def template_global(self, name=None): """A decorator that is used to register a custom template global function. You can specify a name for the global function, otherwise the function name will be used. Example:: @app.template_global() def double(n): retu...
[ "def", "template_global", "(", "self", ",", "name", "=", "None", ")", ":", "def", "decorator", "(", "f", ")", ":", "self", ".", "add_template_global", "(", "f", ",", "name", "=", "name", ")", "return", "f", "return", "decorator" ]
[ 1255, 4 ]
[ 1272, 24 ]
python
en
['en', 'en', 'en']
True
Flask.add_template_global
(self, f, name=None)
Register a custom template global function. Works exactly like the :meth:`template_global` decorator. .. versionadded:: 0.10 :param name: the optional name of the global function, otherwise the function name will be used.
Register a custom template global function. Works exactly like the :meth:`template_global` decorator.
def add_template_global(self, f, name=None): """Register a custom template global function. Works exactly like the :meth:`template_global` decorator. .. versionadded:: 0.10 :param name: the optional name of the global function, otherwise the function name will be u...
[ "def", "add_template_global", "(", "self", ",", "f", ",", "name", "=", "None", ")", ":", "self", ".", "jinja_env", ".", "globals", "[", "name", "or", "f", ".", "__name__", "]", "=", "f" ]
[ 1275, 4 ]
[ 1284, 54 ]
python
en
['en', 'en', 'en']
True
Flask.before_request
(self, f)
Registers a function to run before each request. The function will be called without any arguments. If the function returns a non-None value, it's handled as if it was the return value from the view and further request handling is stopped.
Registers a function to run before each request.
def before_request(self, f): """Registers a function to run before each request. The function will be called without any arguments. If the function returns a non-None value, it's handled as if it was the return value from the view and further request handling is stopped. ...
[ "def", "before_request", "(", "self", ",", "f", ")", ":", "self", ".", "before_request_funcs", ".", "setdefault", "(", "None", ",", "[", "]", ")", ".", "append", "(", "f", ")", "return", "f" ]
[ 1287, 4 ]
[ 1296, 16 ]
python
en
['en', 'en', 'en']
True
Flask.before_first_request
(self, 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. .. versionadded:: 0.8
Registers a function to be run before the first request to this instance of the application.
def before_first_request(self, 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. .. versionadded:: 0.8 """ self.before_first_requ...
[ "def", "before_first_request", "(", "self", ",", "f", ")", ":", "self", ".", "before_first_request_funcs", ".", "append", "(", "f", ")", "return", "f" ]
[ 1299, 4 ]
[ 1309, 16 ]
python
en
['en', 'en', 'en']
True
Flask.after_request
(self, f)
Register a function to be run after each request. Your function must take one parameter, an instance of :attr:`response_class` and return a new response object or the same (see :meth:`process_response`). As of Flask 0.7 this function might not be executed at the end of the requ...
Register a function to be run after each request.
def after_request(self, f): """Register a function to be run after each request. Your function must take one parameter, an instance of :attr:`response_class` and return a new response object or the same (see :meth:`process_response`). As of Flask 0.7 this function might not be ...
[ "def", "after_request", "(", "self", ",", "f", ")", ":", "self", ".", "after_request_funcs", ".", "setdefault", "(", "None", ",", "[", "]", ")", ".", "append", "(", "f", ")", "return", "f" ]
[ 1312, 4 ]
[ 1323, 16 ]
python
en
['en', 'en', 'en']
True
Flask.teardown_request
(self, f)
Register a function to be run at the end of each request, regardless of whether there was an exception or not. These functions are executed when the request context is popped, even if not an actual request was performed. Example:: ctx = app.test_request_context() ...
Register a function to be run at the end of each request, regardless of whether there was an exception or not. These functions are executed when the request context is popped, even if not an actual request was performed.
def teardown_request(self, f): """Register a function to be run at the end of each request, regardless of whether there was an exception or not. These functions are executed when the request context is popped, even if not an actual request was performed. Example:: ...
[ "def", "teardown_request", "(", "self", ",", "f", ")", ":", "self", ".", "teardown_request_funcs", ".", "setdefault", "(", "None", ",", "[", "]", ")", ".", "append", "(", "f", ")", "return", "f" ]
[ 1326, 4 ]
[ 1362, 16 ]
python
en
['en', 'en', 'en']
True
Flask.teardown_appcontext
(self, f)
Registers a function to be called when the application context ends. These functions are typically also called when the request context is popped. Example:: ctx = app.app_context() ctx.push() ... ctx.pop() When ``ctx.pop()`` is executed...
Registers a function to be called when the application context ends. These functions are typically also called when the request context is popped.
def teardown_appcontext(self, f): """Registers a function to be called when the application context ends. These functions are typically also called when the request context is popped. Example:: ctx = app.app_context() ctx.push() ... ctx....
[ "def", "teardown_appcontext", "(", "self", ",", "f", ")", ":", "self", ".", "teardown_appcontext_funcs", ".", "append", "(", "f", ")", "return", "f" ]
[ 1365, 4 ]
[ 1393, 16 ]
python
en
['en', 'en', 'en']
True
Flask.context_processor
(self, f)
Registers a template context processor function.
Registers a template context processor function.
def context_processor(self, f): """Registers a template context processor function.""" self.template_context_processors[None].append(f) return f
[ "def", "context_processor", "(", "self", ",", "f", ")", ":", "self", ".", "template_context_processors", "[", "None", "]", ".", "append", "(", "f", ")", "return", "f" ]
[ 1396, 4 ]
[ 1399, 16 ]
python
en
['en', 'en', 'en']
True
Flask.shell_context_processor
(self, f)
Registers a shell context processor function. .. versionadded:: 0.11
Registers a shell context processor function.
def shell_context_processor(self, f): """Registers a shell context processor function. .. versionadded:: 0.11 """ self.shell_context_processors.append(f) return f
[ "def", "shell_context_processor", "(", "self", ",", "f", ")", ":", "self", ".", "shell_context_processors", ".", "append", "(", "f", ")", "return", "f" ]
[ 1402, 4 ]
[ 1408, 16 ]
python
en
['en', 'en', 'en']
True
Flask.url_value_preprocessor
(self, f)
Registers a function as URL value preprocessor for all view functions of the application. It's called before the view functions are called and can modify the url values provided.
Registers a function as URL value preprocessor for all view functions of the application. It's called before the view functions are called and can modify the url values provided.
def url_value_preprocessor(self, f): """Registers a function as URL value preprocessor for all view functions of the application. It's called before the view functions are called and can modify the url values provided. """ self.url_value_preprocessors.setdefault(None, []).append...
[ "def", "url_value_preprocessor", "(", "self", ",", "f", ")", ":", "self", ".", "url_value_preprocessors", ".", "setdefault", "(", "None", ",", "[", "]", ")", ".", "append", "(", "f", ")", "return", "f" ]
[ 1411, 4 ]
[ 1417, 16 ]
python
en
['en', 'en', 'en']
True
Flask.url_defaults
(self, f)
Callback function for URL defaults for all view functions of the application. It's called with the endpoint and values and should update the values passed in place.
Callback function for URL defaults for all view functions of the application. It's called with the endpoint and values and should update the values passed in place.
def url_defaults(self, f): """Callback function for URL defaults for all view functions of the application. It's called with the endpoint and values and should update the values passed in place. """ self.url_default_functions.setdefault(None, []).append(f) return f
[ "def", "url_defaults", "(", "self", ",", "f", ")", ":", "self", ".", "url_default_functions", ".", "setdefault", "(", "None", ",", "[", "]", ")", ".", "append", "(", "f", ")", "return", "f" ]
[ 1420, 4 ]
[ 1426, 16 ]
python
en
['en', 'en', 'en']
True
Flask._find_error_handler
(self, e)
Finds a registered error handler for the request’s blueprint. Otherwise falls back to the app, returns None if not a suitable handler is found.
Finds a registered error handler for the request’s blueprint. Otherwise falls back to the app, returns None if not a suitable handler is found.
def _find_error_handler(self, e): """Finds a registered error handler for the request’s blueprint. Otherwise falls back to the app, returns None if not a suitable handler is found. """ exc_class, code = self._get_exc_class_and_code(type(e)) def find_handler(handler_map):...
[ "def", "_find_error_handler", "(", "self", ",", "e", ")", ":", "exc_class", ",", "code", "=", "self", ".", "_get_exc_class_and_code", "(", "type", "(", "e", ")", ")", "def", "find_handler", "(", "handler_map", ")", ":", "if", "not", "handler_map", ":", "...
[ 1428, 4 ]
[ 1453, 68 ]
python
en
['en', 'da', 'en']
True
Flask.handle_http_exception
(self, e)
Handles an HTTP exception. By default this will invoke the registered error handlers and fall back to returning the exception as response. .. versionadded:: 0.3
Handles an HTTP exception. By default this will invoke the registered error handlers and fall back to returning the exception as response.
def handle_http_exception(self, e): """Handles an HTTP exception. By default this will invoke the registered error handlers and fall back to returning the exception as response. .. versionadded:: 0.3 """ # Proxy exceptions don't have error codes. We want to always retu...
[ "def", "handle_http_exception", "(", "self", ",", "e", ")", ":", "# Proxy exceptions don't have error codes. We want to always return", "# those unchanged as errors", "if", "e", ".", "code", "is", "None", ":", "return", "e", "handler", "=", "self", ".", "_find_error_ha...
[ 1455, 4 ]
[ 1470, 25 ]
python
en
['en', 'en', 'en']
True
Flask.trap_http_exception
(self, e)
Checks if an HTTP exception should be trapped or not. By default this will return ``False`` for all exceptions except for a bad request key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``. This is called ...
Checks if an HTTP exception should be trapped or not. By default this will return ``False`` for all exceptions except for a bad request key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
def trap_http_exception(self, e): """Checks if an HTTP exception should be trapped or not. By default this will return ``False`` for all exceptions except for a bad request key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS``...
[ "def", "trap_http_exception", "(", "self", ",", "e", ")", ":", "if", "self", ".", "config", "[", "'TRAP_HTTP_EXCEPTIONS'", "]", ":", "return", "True", "if", "self", ".", "config", "[", "'TRAP_BAD_REQUEST_ERRORS'", "]", ":", "return", "isinstance", "(", "e", ...
[ 1472, 4 ]
[ 1490, 20 ]
python
en
['en', 'en', 'en']
True
Flask.handle_user_exception
(self, e)
This method is called whenever an exception occurs that should be handled. A special case are :class:`~werkzeug.exception.HTTPException`\s which are forwarded by this function to the :meth:`handle_http_exception` method. This function will either return a response value or reraise the ...
This method is called whenever an exception occurs that should be handled. A special case are :class:`~werkzeug.exception.HTTPException`\s which are forwarded by this function to the :meth:`handle_http_exception` method. This function will either return a response value or reraise the ...
def handle_user_exception(self, e): """This method is called whenever an exception occurs that should be handled. A special case are :class:`~werkzeug.exception.HTTPException`\s which are forwarded by this function to the :meth:`handle_http_exception` method. This function will...
[ "def", "handle_user_exception", "(", "self", ",", "e", ")", ":", "exc_type", ",", "exc_value", ",", "tb", "=", "sys", ".", "exc_info", "(", ")", "assert", "exc_value", "is", "e", "# ensure not to trash sys.exc_info() at that point in case someone", "# wants the traceb...
[ 1492, 4 ]
[ 1517, 25 ]
python
en
['en', 'en', 'en']
True
Flask.handle_exception
(self, e)
Default exception handling that kicks in when an exception occurs that is not caught. In debug mode the exception will be re-raised immediately, otherwise it is logged and the handler for a 500 internal server error is used. If no such handler exists, a default 500 internal server erro...
Default exception handling that kicks in when an exception occurs that is not caught. In debug mode the exception will be re-raised immediately, otherwise it is logged and the handler for a 500 internal server error is used. If no such handler exists, a default 500 internal server erro...
def handle_exception(self, e): """Default exception handling that kicks in when an exception occurs that is not caught. In debug mode the exception will be re-raised immediately, otherwise it is logged and the handler for a 500 internal server error is used. If no such handler ...
[ "def", "handle_exception", "(", "self", ",", "e", ")", ":", "exc_type", ",", "exc_value", ",", "tb", "=", "sys", ".", "exc_info", "(", ")", "got_request_exception", ".", "send", "(", "self", ",", "exception", "=", "e", ")", "handler", "=", "self", ".",...
[ 1519, 4 ]
[ 1546, 73 ]
python
en
['en', 'en', 'en']
True
Flask.log_exception
(self, exc_info)
Logs an exception. This is called by :meth:`handle_exception` if debugging is disabled and right before the handler is called. The default implementation logs the exception as error on the :attr:`logger`. .. versionadded:: 0.8
Logs an exception. This is called by :meth:`handle_exception` if debugging is disabled and right before the handler is called. The default implementation logs the exception as error on the :attr:`logger`.
def log_exception(self, exc_info): """Logs an exception. This is called by :meth:`handle_exception` if debugging is disabled and right before the handler is called. The default implementation logs the exception as error on the :attr:`logger`. .. versionadded:: 0.8 """ ...
[ "def", "log_exception", "(", "self", ",", "exc_info", ")", ":", "self", ".", "logger", ".", "error", "(", "'Exception on %s [%s]'", "%", "(", "request", ".", "path", ",", "request", ".", "method", ")", ",", "exc_info", "=", "exc_info", ")" ]
[ 1548, 4 ]
[ 1559, 29 ]
python
en
['en', 'en', 'en']
True
Flask.raise_routing_exception
(self, request)
Exceptions that are recording during routing are reraised with this method. During debug we are not reraising redirect requests for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising a different error instead to help debug situations. :internal:
Exceptions that are recording during routing are reraised with this method. During debug we are not reraising redirect requests for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising a different error instead to help debug situations.
def raise_routing_exception(self, request): """Exceptions that are recording during routing are reraised with this method. During debug we are not reraising redirect requests for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising a different error instead to help debug sit...
[ "def", "raise_routing_exception", "(", "self", ",", "request", ")", ":", "if", "not", "self", ".", "debug", "or", "not", "isinstance", "(", "request", ".", "routing_exception", ",", "RequestRedirect", ")", "or", "request", ".", "method", "in", "(", "'GET'", ...
[ 1561, 4 ]
[ 1575, 46 ]
python
en
['en', 'en', 'en']
True
Flask.dispatch_request
(self)
Does the request dispatching. Matches the URL and returns the return value of the view or error handler. This does not have to be a response object. In order to convert the return value to a proper response object, call :func:`make_response`. .. versionchanged:: 0.7 This n...
Does the request dispatching. Matches the URL and returns the return value of the view or error handler. This does not have to be a response object. In order to convert the return value to a proper response object, call :func:`make_response`.
def dispatch_request(self): """Does the request dispatching. Matches the URL and returns the return value of the view or error handler. This does not have to be a response object. In order to convert the return value to a proper response object, call :func:`make_response`. .....
[ "def", "dispatch_request", "(", "self", ")", ":", "req", "=", "_request_ctx_stack", ".", "top", ".", "request", "if", "req", ".", "routing_exception", "is", "not", "None", ":", "self", ".", "raise_routing_exception", "(", "req", ")", "rule", "=", "req", "....
[ 1577, 4 ]
[ 1597, 66 ]
python
en
['en', 'en', 'en']
True
Flask.full_dispatch_request
(self)
Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling. .. versionadded:: 0.7
Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling.
def full_dispatch_request(self): """Dispatches the request and on top of that performs request pre and postprocessing as well as HTTP exception catching and error handling. .. versionadded:: 0.7 """ self.try_trigger_before_first_request_functions() try: ...
[ "def", "full_dispatch_request", "(", "self", ")", ":", "self", ".", "try_trigger_before_first_request_functions", "(", ")", "try", ":", "request_started", ".", "send", "(", "self", ")", "rv", "=", "self", ".", "preprocess_request", "(", ")", "if", "rv", "is", ...
[ 1599, 4 ]
[ 1614, 40 ]
python
en
['en', 'en', 'en']
True
Flask.finalize_request
(self, rv, from_error_handler=False)
Given the return value from a view function this finalizes the request by converting it into a response and invoking the postprocessing functions. This is invoked for both normal request dispatching as well as error handlers. Because this means that it might be called as a result of a ...
Given the return value from a view function this finalizes the request by converting it into a response and invoking the postprocessing functions. This is invoked for both normal request dispatching as well as error handlers.
def finalize_request(self, rv, from_error_handler=False): """Given the return value from a view function this finalizes the request by converting it into a response and invoking the postprocessing functions. This is invoked for both normal request dispatching as well as error handlers. ...
[ "def", "finalize_request", "(", "self", ",", "rv", ",", "from_error_handler", "=", "False", ")", ":", "response", "=", "self", ".", "make_response", "(", "rv", ")", "try", ":", "response", "=", "self", ".", "process_response", "(", "response", ")", "reques...
[ 1616, 4 ]
[ 1638, 23 ]
python
en
['en', 'en', 'en']
True
Flask.try_trigger_before_first_request_functions
(self)
Called before each request and will ensure that it triggers the :attr:`before_first_request_funcs` and only exactly once per application instance (which means process usually). :internal:
Called before each request and will ensure that it triggers the :attr:`before_first_request_funcs` and only exactly once per application instance (which means process usually).
def try_trigger_before_first_request_functions(self): """Called before each request and will ensure that it triggers the :attr:`before_first_request_funcs` and only exactly once per application instance (which means process usually). :internal: """ if self._got_first_req...
[ "def", "try_trigger_before_first_request_functions", "(", "self", ")", ":", "if", "self", ".", "_got_first_request", ":", "return", "with", "self", ".", "_before_request_lock", ":", "if", "self", ".", "_got_first_request", ":", "return", "for", "func", "in", "self...
[ 1640, 4 ]
[ 1654, 42 ]
python
en
['en', 'en', 'en']
True
Flask.make_default_options_response
(self)
This method is called to create the default ``OPTIONS`` response. This can be changed through subclassing to change the default behavior of ``OPTIONS`` responses. .. versionadded:: 0.7
This method is called to create the default ``OPTIONS`` response. This can be changed through subclassing to change the default behavior of ``OPTIONS`` responses.
def make_default_options_response(self): """This method is called to create the default ``OPTIONS`` response. This can be changed through subclassing to change the default behavior of ``OPTIONS`` responses. .. versionadded:: 0.7 """ adapter = _request_ctx_stack.top.url_a...
[ "def", "make_default_options_response", "(", "self", ")", ":", "adapter", "=", "_request_ctx_stack", ".", "top", ".", "url_adapter", "if", "hasattr", "(", "adapter", ",", "'allowed_methods'", ")", ":", "methods", "=", "adapter", ".", "allowed_methods", "(", ")",...
[ 1656, 4 ]
[ 1677, 17 ]
python
en
['en', 'en', 'en']
True
Flask.should_ignore_error
(self, error)
This is called to figure out if an error should be ignored or not as far as the teardown system is concerned. If this function returns ``True`` then the teardown handlers will not be passed the error. .. versionadded:: 0.10
This is called to figure out if an error should be ignored or not as far as the teardown system is concerned. If this function returns ``True`` then the teardown handlers will not be passed the error.
def should_ignore_error(self, error): """This is called to figure out if an error should be ignored or not as far as the teardown system is concerned. If this function returns ``True`` then the teardown handlers will not be passed the error. .. versionadded:: 0.10 """ ...
[ "def", "should_ignore_error", "(", "self", ",", "error", ")", ":", "return", "False" ]
[ 1679, 4 ]
[ 1687, 20 ]
python
en
['en', 'en', 'en']
True
Flask.make_response
(self, rv)
Converts the return value from a view function to a real response object that is an instance of :attr:`response_class`. The following types are allowed for `rv`: .. tabularcolumns:: |p{3.5cm}|p{9.5cm}| ======================= =========================================== :attr:`...
Converts the return value from a view function to a real response object that is an instance of :attr:`response_class`.
def make_response(self, rv): """Converts the return value from a view function to a real response object that is an instance of :attr:`response_class`. The following types are allowed for `rv`: .. tabularcolumns:: |p{3.5cm}|p{9.5cm}| ======================= ===================...
[ "def", "make_response", "(", "self", ",", "rv", ")", ":", "status_or_headers", "=", "headers", "=", "None", "if", "isinstance", "(", "rv", ",", "tuple", ")", ":", "rv", ",", "status_or_headers", ",", "headers", "=", "rv", "+", "(", "None", ",", ")", ...
[ 1689, 4 ]
[ 1749, 17 ]
python
en
['en', 'en', 'en']
True
Flask.create_url_adapter
(self, 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. .. versionadded:: 0.6 .. versionchanged:: 0.9 This can now also be called without a request object when the ...
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.
def create_url_adapter(self, 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. .. versionadded:: 0.6 .. versionchanged:: 0.9 This can now a...
[ "def", "create_url_adapter", "(", "self", ",", "request", ")", ":", "if", "request", "is", "not", "None", ":", "return", "self", ".", "url_map", ".", "bind_to_environ", "(", "request", ".", "environ", ",", "server_name", "=", "self", ".", "config", "[", ...
[ 1751, 4 ]
[ 1771, 63 ]
python
en
['en', 'en', 'en']
True
Flask.inject_url_defaults
(self, endpoint, values)
Injects the URL defaults for the given endpoint directly into the values dictionary passed. This is used internally and automatically called on URL building. .. versionadded:: 0.7
Injects the URL defaults for the given endpoint directly into the values dictionary passed. This is used internally and automatically called on URL building.
def inject_url_defaults(self, endpoint, values): """Injects the URL defaults for the given endpoint directly into the values dictionary passed. This is used internally and automatically called on URL building. .. versionadded:: 0.7 """ funcs = self.url_default_functions...
[ "def", "inject_url_defaults", "(", "self", ",", "endpoint", ",", "values", ")", ":", "funcs", "=", "self", ".", "url_default_functions", ".", "get", "(", "None", ",", "(", ")", ")", "if", "'.'", "in", "endpoint", ":", "bp", "=", "endpoint", ".", "rspli...
[ 1773, 4 ]
[ 1785, 34 ]
python
en
['en', 'en', 'en']
True
Flask.handle_url_build_error
(self, error, endpoint, values)
Handle :class:`~werkzeug.routing.BuildError` on :meth:`url_for`.
Handle :class:`~werkzeug.routing.BuildError` on :meth:`url_for`.
def handle_url_build_error(self, error, endpoint, values): """Handle :class:`~werkzeug.routing.BuildError` on :meth:`url_for`. """ exc_type, exc_value, tb = sys.exc_info() for handler in self.url_build_error_handlers: try: rv = handler(error, endpoint, values)...
[ "def", "handle_url_build_error", "(", "self", ",", "error", ",", "endpoint", ",", "values", ")", ":", "exc_type", ",", "exc_value", ",", "tb", "=", "sys", ".", "exc_info", "(", ")", "for", "handler", "in", "self", ".", "url_build_error_handlers", ":", "try...
[ 1787, 4 ]
[ 1805, 19 ]
python
de
['en', 'de', 'nl']
False
Flask.preprocess_request
(self)
Called before the actual request dispatching and will call each :meth:`before_request` decorated function, passing no arguments. If any of these functions returns a value, it's handled as if it was the return value from the view and further request handling is stopped. T...
Called before the actual request dispatching and will call each :meth:`before_request` decorated function, passing no arguments. If any of these functions returns a value, it's handled as if it was the return value from the view and further request handling is stopped.
def preprocess_request(self): """Called before the actual request dispatching and will call each :meth:`before_request` decorated function, passing no arguments. If any of these functions returns a value, it's handled as if it was the return value from the view and further ...
[ "def", "preprocess_request", "(", "self", ")", ":", "bp", "=", "_request_ctx_stack", ".", "top", ".", "request", ".", "blueprint", "funcs", "=", "self", ".", "url_value_preprocessors", ".", "get", "(", "None", ",", "(", ")", ")", "if", "bp", "is", "not",...
[ 1807, 4 ]
[ 1832, 25 ]
python
en
['en', 'en', 'en']
True
Flask.process_response
(self, response)
Can be overridden in order to modify the response object before it's sent to the WSGI server. By default this will call all the :meth:`after_request` decorated functions. .. versionchanged:: 0.5 As of Flask 0.5 the functions registered for after request execution are call...
Can be overridden in order to modify the response object before it's sent to the WSGI server. By default this will call all the :meth:`after_request` decorated functions.
def process_response(self, response): """Can be overridden in order to modify the response object before it's sent to the WSGI server. By default this will call all the :meth:`after_request` decorated functions. .. versionchanged:: 0.5 As of Flask 0.5 the functions registere...
[ "def", "process_response", "(", "self", ",", "response", ")", ":", "ctx", "=", "_request_ctx_stack", ".", "top", "bp", "=", "ctx", ".", "request", ".", "blueprint", "funcs", "=", "ctx", ".", "_after_request_functions", "if", "bp", "is", "not", "None", "and...
[ 1834, 4 ]
[ 1858, 23 ]
python
en
['en', 'en', 'en']
True
Flask.do_teardown_request
(self, exc=_sentinel)
Called after the actual request dispatching and will call every as :meth:`teardown_request` decorated function. This is not actually called by the :class:`Flask` object itself but is always triggered when the request context is popped. That way we have a tighter control over certain re...
Called after the actual request dispatching and will call every as :meth:`teardown_request` decorated function. This is not actually called by the :class:`Flask` object itself but is always triggered when the request context is popped. That way we have a tighter control over certain re...
def do_teardown_request(self, exc=_sentinel): """Called after the actual request dispatching and will call every as :meth:`teardown_request` decorated function. This is not actually called by the :class:`Flask` object itself but is always triggered when the request context is popped. T...
[ "def", "do_teardown_request", "(", "self", ",", "exc", "=", "_sentinel", ")", ":", "if", "exc", "is", "_sentinel", ":", "exc", "=", "sys", ".", "exc_info", "(", ")", "[", "1", "]", "funcs", "=", "reversed", "(", "self", ".", "teardown_request_funcs", "...
[ 1860, 4 ]
[ 1879, 48 ]
python
en
['en', 'en', 'en']
True
Flask.do_teardown_appcontext
(self, exc=_sentinel)
Called when an application context is popped. This works pretty much the same as :meth:`do_teardown_request` but for the application context. .. versionadded:: 0.9
Called when an application context is popped. This works pretty much the same as :meth:`do_teardown_request` but for the application context.
def do_teardown_appcontext(self, exc=_sentinel): """Called when an application context is popped. This works pretty much the same as :meth:`do_teardown_request` but for the application context. .. versionadded:: 0.9 """ if exc is _sentinel: exc = sys.exc_inf...
[ "def", "do_teardown_appcontext", "(", "self", ",", "exc", "=", "_sentinel", ")", ":", "if", "exc", "is", "_sentinel", ":", "exc", "=", "sys", ".", "exc_info", "(", ")", "[", "1", "]", "for", "func", "in", "reversed", "(", "self", ".", "teardown_appcont...
[ 1881, 4 ]
[ 1892, 51 ]
python
en
['en', 'en', 'en']
True
Flask.app_context
(self)
Binds the application only. For as long as the application is bound to the current context the :data:`flask.current_app` points to that application. An application context is automatically created when a request context is pushed if necessary. Example usage:: with app.app...
Binds the application only. For as long as the application is bound to the current context the :data:`flask.current_app` points to that application. An application context is automatically created when a request context is pushed if necessary.
def app_context(self): """Binds the application only. For as long as the application is bound to the current context the :data:`flask.current_app` points to that application. An application context is automatically created when a request context is pushed if necessary. Example...
[ "def", "app_context", "(", "self", ")", ":", "return", "AppContext", "(", "self", ")" ]
[ 1894, 4 ]
[ 1907, 31 ]
python
en
['en', 'en', 'en']
True
Flask.request_context
(self, environ)
Creates a :class:`~flask.ctx.RequestContext` from the given environment and binds it to the current context. This must be used in combination with the ``with`` statement because the request is only bound to the current context for the duration of the ``with`` block. Example usage:: ...
Creates a :class:`~flask.ctx.RequestContext` from the given environment and binds it to the current context. This must be used in combination with the ``with`` statement because the request is only bound to the current context for the duration of the ``with`` block.
def request_context(self, environ): """Creates a :class:`~flask.ctx.RequestContext` from the given environment and binds it to the current context. This must be used in combination with the ``with`` statement because the request is only bound to the current context for the duration of t...
[ "def", "request_context", "(", "self", ",", "environ", ")", ":", "return", "RequestContext", "(", "self", ",", "environ", ")" ]
[ 1909, 4 ]
[ 1937, 44 ]
python
en
['en', 'en', 'en']
True
Flask.test_request_context
(self, *args, **kwargs)
Creates a WSGI environment from the given values (see :class:`werkzeug.test.EnvironBuilder` for more information, this function accepts the same arguments).
Creates a WSGI environment from the given values (see :class:`werkzeug.test.EnvironBuilder` for more information, this function accepts the same arguments).
def test_request_context(self, *args, **kwargs): """Creates a WSGI environment from the given values (see :class:`werkzeug.test.EnvironBuilder` for more information, this function accepts the same arguments). """ from flask.testing import make_test_environ_builder builder...
[ "def", "test_request_context", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "from", "flask", ".", "testing", "import", "make_test_environ_builder", "builder", "=", "make_test_environ_builder", "(", "self", ",", "*", "args", ",", "*", "*"...
[ 1939, 4 ]
[ 1949, 27 ]
python
en
['en', 'en', 'en']
True
Flask.wsgi_app
(self, environ, start_response)
The actual WSGI application. This is not implemented in `__call__` so that middlewares can be applied without losing a reference to the class. So instead of doing this:: app = MyMiddleware(app) It's a better idea to do this instead:: app.wsgi_app = MyMiddleware(app.w...
The actual WSGI application. This is not implemented in `__call__` so that middlewares can be applied without losing a reference to the class. So instead of doing this::
def wsgi_app(self, environ, start_response): """The actual WSGI application. This is not implemented in `__call__` so that middlewares can be applied without losing a reference to the class. So instead of doing this:: app = MyMiddleware(app) It's a better idea to do this ...
[ "def", "wsgi_app", "(", "self", ",", "environ", ",", "start_response", ")", ":", "ctx", "=", "self", ".", "request_context", "(", "environ", ")", "ctx", ".", "push", "(", ")", "error", "=", "None", "try", ":", "try", ":", "response", "=", "self", "."...
[ 1951, 4 ]
[ 1992, 31 ]
python
en
['en', 'en', 'en']
True
Flask.__call__
(self, environ, start_response)
Shortcut for :attr:`wsgi_app`.
Shortcut for :attr:`wsgi_app`.
def __call__(self, environ, start_response): """Shortcut for :attr:`wsgi_app`.""" return self.wsgi_app(environ, start_response)
[ "def", "__call__", "(", "self", ",", "environ", ",", "start_response", ")", ":", "return", "self", ".", "wsgi_app", "(", "environ", ",", "start_response", ")" ]
[ 1994, 4 ]
[ 1996, 53 ]
python
en
['en', 'sv', 'en']
True
extract_resources
(taxonomy_filepath)
Reads a .json representing a taxonomy and returns a data structure representing their hierarchical relationship :param taxonomy_file: a string representing a path to a .json file :return: Node representing root of taxonomic tree
Reads a .json representing a taxonomy and returns a data structure representing their hierarchical relationship :param taxonomy_file: a string representing a path to a .json file :return: Node representing root of taxonomic tree
def extract_resources(taxonomy_filepath): """ Reads a .json representing a taxonomy and returns a data structure representing their hierarchical relationship :param taxonomy_file: a string representing a path to a .json file :return: Node representing root of taxonomic tree """ try: ...
[ "def", "extract_resources", "(", "taxonomy_filepath", ")", ":", "try", ":", "with", "open", "(", "taxonomy_filepath", ",", "'r'", ")", "as", "fp", ":", "json_str", "=", "fp", ".", "read", "(", ")", "json_data", "=", "json", ".", "loads", "(", "json_str",...
[ 50, 0 ]
[ 66, 15 ]
python
en
['en', 'error', 'th']
False
read_users
(users_fp)
Reads a .csv from @user_fp representing users into a list of dictionaries, each elt of which represents a user :param user_fp: a .csv file where each line represents a user :return: a list of dictionaries
Reads a .csv from
def read_users(users_fp): """ Reads a .csv from @user_fp representing users into a list of dictionaries, each elt of which represents a user :param user_fp: a .csv file where each line represents a user :return: a list of dictionaries """ users = [] with open(users_fp, 'r') as fp: ...
[ "def", "read_users", "(", "users_fp", ")", ":", "users", "=", "[", "]", "with", "open", "(", "users_fp", ",", "'r'", ")", "as", "fp", ":", "fields", "=", "fp", ".", "readline", "(", ")", ".", "rstrip", "(", ")", ".", "split", "(", "\",\"", ")", ...
[ 69, 0 ]
[ 82, 16 ]
python
en
['en', 'error', 'th']
False
sleep_then_publish_burst
(burst, publisher, topic_path)
:param burst: a list of dictionaries, each representing an event :param num_events_counter: an instance of Value shared by all processes to track the number of published events :param publisher: a PubSub publisher :param topic_path: a topic path for PubSub :return:
def sleep_then_publish_burst(burst, publisher, topic_path): """ :param burst: a list of dictionaries, each representing an event :param num_events_counter: an instance of Value shared by all processes to track the number of published events :param publisher: a PubSub publisher :param topic_path...
[ "def", "sleep_then_publish_burst", "(", "burst", ",", "publisher", ",", "topic_path", ")", ":", "sleep_secs", "=", "random", ".", "uniform", "(", "0", ",", "max_lag_millis", "/", "1000", ")", "time", ".", "sleep", "(", "sleep_secs", ")", "publish_burst", "("...
[ 84, 0 ]
[ 96, 47 ]
python
en
['en', 'error', 'th']
False
publish_burst
(burst, publisher, topic_path)
Publishes and prints each event :param burst: a list of dictionaries, each representing an event :param num_events_counter: an instance of Value shared by all processes to track the number of published events :param publisher: a PubSub publisher :param topic_path: a topic path for PubSub :r...
Publishes and prints each event :param burst: a list of dictionaries, each representing an event :param num_events_counter: an instance of Value shared by all processes to track the number of published events :param publisher: a PubSub publisher :param topic_path: a topic path for PubSub :r...
def publish_burst(burst, publisher, topic_path): """ Publishes and prints each event :param burst: a list of dictionaries, each representing an event :param num_events_counter: an instance of Value shared by all processes to track the number of published events :param publisher: a PubSub publish...
[ "def", "publish_burst", "(", "burst", ",", "publisher", ",", "topic_path", ")", ":", "for", "event_dict", "in", "burst", ":", "json_str", "=", "json", ".", "dumps", "(", "event_dict", ")", "data", "=", "json_str", ".", "encode", "(", "'utf-8'", ")", "pub...
[ 98, 0 ]
[ 111, 83 ]
python
en
['en', 'error', 'th']
False
create_user_process
(user, root)
Code for continuously-running process representing a user publishing events to pubsub :param user: a dictionary representing characteristics of the user :param root: an instance of AnyNode representing the home page of a website :param num_events_counter: a variable shared among all processes used ...
Code for continuously-running process representing a user publishing events to pubsub :param user: a dictionary representing characteristics of the user :param root: an instance of AnyNode representing the home page of a website :param num_events_counter: a variable shared among all processes used ...
def create_user_process(user, root): """ Code for continuously-running process representing a user publishing events to pubsub :param user: a dictionary representing characteristics of the user :param root: an instance of AnyNode representing the home page of a website :param num_events_counter:...
[ "def", "create_user_process", "(", "user", ",", "root", ")", ":", "publisher", "=", "pubsub_v1", ".", "PublisherClient", "(", ")", "topic_path", "=", "publisher", ".", "topic_path", "(", "project_id", ",", "topic_name", ")", "user", "[", "'page'", "]", "=", ...
[ 113, 0 ]
[ 145, 43 ]
python
en
['en', 'error', 'th']
False
generate_event
(user)
Returns a dictionary representing an event :param user: :return:
Returns a dictionary representing an event :param user: :return:
def generate_event(user): """ Returns a dictionary representing an event :param user: :return: """ user['page'] = get_next_page(user) uri = str(user['page'].name) event_time = datetime.now(tz=timezone.utc) current_time_str = event_time.strftime('%Y-%m-%dT%H:%M:%S.%fZ') file_size_...
[ "def", "generate_event", "(", "user", ")", ":", "user", "[", "'page'", "]", "=", "get_next_page", "(", "user", ")", "uri", "=", "str", "(", "user", "[", "'page'", "]", ".", "name", ")", "event_time", "=", "datetime", ".", "now", "(", "tz", "=", "ti...
[ 147, 0 ]
[ 163, 46 ]
python
en
['en', 'error', 'th']
False
get_next_page
(user)
Consults the user's representation of the web site taxonomy to determine the next page that they visit :param user: :return:
Consults the user's representation of the web site taxonomy to determine the next page that they visit :param user: :return:
def get_next_page(user): """ Consults the user's representation of the web site taxonomy to determine the next page that they visit :param user: :return: """ possible_next_pages = [user['page']] if not user['page'].is_leaf: possible_next_pages += list(user['page'].children) if (u...
[ "def", "get_next_page", "(", "user", ")", ":", "possible_next_pages", "=", "[", "user", "[", "'page'", "]", "]", "if", "not", "user", "[", "'page'", "]", ".", "is_leaf", ":", "possible_next_pages", "+=", "list", "(", "user", "[", "'page'", "]", ".", "c...
[ 165, 0 ]
[ 177, 20 ]
python
en
['en', 'error', 'th']
False
ItemAttributeKNN.__init__
(self, train_file=None, test_file=None, output_file=None, metadata_file=None, similarity_file=None, k_neighbors=30, as_similar_first=True, metadata_as_binary=False, metadata_similarity_sep='\t', similarity_metric="cosine", sep='\t', output_sep='\t')
Item Attribute KNN for Rating Prediction This algorithm predicts a rank for each user based on the similar items that he/her consumed, using a metadata or similarity pre-computed file Usage:: >> ItemAttributeKNN(train, test, similarity_file=sim_matrix, as_similar_first=Tr...
Item Attribute KNN for Rating Prediction
def __init__(self, train_file=None, test_file=None, output_file=None, metadata_file=None, similarity_file=None, k_neighbors=30, as_similar_first=True, metadata_as_binary=False, metadata_similarity_sep='\t', similarity_metric="cosine", sep='\t', output_sep='\t'): """ Ite...
[ "def", "__init__", "(", "self", ",", "train_file", "=", "None", ",", "test_file", "=", "None", ",", "output_file", "=", "None", ",", "metadata_file", "=", "None", ",", "similarity_file", "=", "None", ",", "k_neighbors", "=", "30", ",", "as_similar_first", ...
[ 23, 4 ]
[ 91, 62 ]
python
en
['en', 'error', 'th']
False
ItemAttributeKNN.init_model
(self)
Method to fit the model. Create and calculate a similarity matrix by metadata file or a pre-computed similarity matrix
Method to fit the model. Create and calculate a similarity matrix by metadata file or a pre-computed similarity matrix
def init_model(self): """ Method to fit the model. Create and calculate a similarity matrix by metadata file or a pre-computed similarity matrix """ self.similar_items = defaultdict(list) # Set the value for k if self.k_neighbors is None: self.k_nei...
[ "def", "init_model", "(", "self", ")", ":", "self", ".", "similar_items", "=", "defaultdict", "(", "list", ")", "# Set the value for k", "if", "self", ".", "k_neighbors", "is", "None", ":", "self", ".", "k_neighbors", "=", "int", "(", "np", ".", "sqrt", ...
[ 93, 4 ]
[ 153, 109 ]
python
en
['en', 'error', 'th']
False
_match_vcs_scheme
(url: str)
Look for VCS schemes in the URL. Returns the matched VCS scheme, or None if there's no match.
Look for VCS schemes in the URL.
def _match_vcs_scheme(url: str) -> Optional[str]: """Look for VCS schemes in the URL. Returns the matched VCS scheme, or None if there's no match. """ for scheme in vcs.schemes: if url.lower().startswith(scheme) and url[len(scheme)] in '+:': return scheme return None
[ "def", "_match_vcs_scheme", "(", "url", ":", "str", ")", "->", "Optional", "[", "str", "]", ":", "for", "scheme", "in", "vcs", ".", "schemes", ":", "if", "url", ".", "lower", "(", ")", ".", "startswith", "(", "scheme", ")", "and", "url", "[", "len"...
[ 48, 0 ]
[ 56, 15 ]
python
en
['en', 'en', 'en']
True
_ensure_html_header
(response: Response)
Check the Content-Type header to ensure the response contains HTML. Raises `_NotHTML` if the content type is not text/html.
Check the Content-Type header to ensure the response contains HTML.
def _ensure_html_header(response: Response) -> None: """Check the Content-Type header to ensure the response contains HTML. Raises `_NotHTML` if the content type is not text/html. """ content_type = response.headers.get("Content-Type", "") if not content_type.lower().startswith("text/html"): ...
[ "def", "_ensure_html_header", "(", "response", ":", "Response", ")", "->", "None", ":", "content_type", "=", "response", ".", "headers", ".", "get", "(", "\"Content-Type\"", ",", "\"\"", ")", "if", "not", "content_type", ".", "lower", "(", ")", ".", "start...
[ 66, 0 ]
[ 73, 61 ]
python
en
['en', 'en', 'en']
True
_ensure_html_response
(url: str, session: PipSession)
Send a HEAD request to the URL, and ensure the response contains HTML. Raises `_NotHTTP` if the URL is not available for a HEAD request, or `_NotHTML` if the content type is not text/html.
Send a HEAD request to the URL, and ensure the response contains HTML.
def _ensure_html_response(url: str, session: PipSession) -> None: """Send a HEAD request to the URL, and ensure the response contains HTML. Raises `_NotHTTP` if the URL is not available for a HEAD request, or `_NotHTML` if the content type is not text/html. """ scheme, netloc, path, query, fragment...
[ "def", "_ensure_html_response", "(", "url", ":", "str", ",", "session", ":", "PipSession", ")", "->", "None", ":", "scheme", ",", "netloc", ",", "path", ",", "query", ",", "fragment", "=", "urllib", ".", "parse", ".", "urlsplit", "(", "url", ")", "if",...
[ 80, 0 ]
[ 93, 29 ]
python
en
['en', 'en', 'en']
True
_get_html_response
(url: str, session: PipSession)
Access an HTML page with GET, and return the response. This consists of three parts: 1. If the URL looks suspiciously like an archive, send a HEAD first to check the Content-Type is HTML, to avoid downloading a large file. Raise `_NotHTTP` if the content type cannot be determined, or `_No...
Access an HTML page with GET, and return the response.
def _get_html_response(url: str, session: PipSession) -> Response: """Access an HTML page with GET, and return the response. This consists of three parts: 1. If the URL looks suspiciously like an archive, send a HEAD first to check the Content-Type is HTML, to avoid downloading a large file. ...
[ "def", "_get_html_response", "(", "url", ":", "str", ",", "session", ":", "PipSession", ")", "->", "Response", ":", "if", "is_archive_file", "(", "Link", "(", "url", ")", ".", "filename", ")", ":", "_ensure_html_response", "(", "url", ",", "session", "=", ...
[ 96, 0 ]
[ 143, 15 ]
python
en
['en', 'en', 'en']
True