quart.flask_patch package

Module contents

quart.flask_patch.abort(status_or_response: Union[int, quart.wrappers.response.Response], description: Optional[str] = None, name: Optional[str] = None) → NoReturn

Raises a HTTPException with the status code or response given.

This can be used either with a status code (with optional description and name) or with a Response object. The latter allows for an abort (after response functions etc aren’t called) with a custom response.

abort(403)
abort(Response("Message"))
quart.flask_patch.after_this_request(func: Callable) → Callable

Schedule the func to be called after the current request.

This is useful in situations whereby you want an after request function for a specific route or circumstance only, for example,

def index():
    @after_this_request
    def set_cookie(response):
        response.set_cookie('special', 'value')
        return response

    ...
class quart.flask_patch.Blueprint(name: str, import_name: str, static_folder: Optional[str] = None, static_url_path: Optional[str] = None, template_folder: Optional[str] = None, url_prefix: Optional[str] = None, subdomain: Optional[str] = None, root_path: Optional[str] = None)

Bases: quart.static.PackageStatic

A blueprint is a collection of application properties.

The application properties include routes, error handlers, and before and after request functions. It is useful to produce modular code as it allows the properties to be defined in a blueprint thereby defering the addition of these properties to the app.

json_decoder

The decoder to use for routes in this blueprint, the default, None, indicates that the app encoder should be used.

json_encoder

The encoder to use for routes in this blueprint, the default, None, indicates that the app encoder should be used.

url_prefix

An additional prefix to every route rule in the blueprint.

add_app_template_filter(func: Callable, name: Optional[str] = None) → None

Add an application wide template filter.

This is designed to be used on the blueprint directly, and has the same arguments as add_template_filter(). An example usage,

def filter():
    ...

blueprint = Blueprint(__name__)
blueprint.add_app_template_filter(filter)
add_app_template_global(func: Callable, name: Optional[str] = None) → None

Add an application wide template global.

This is designed to be used on the blueprint directly, and has the same arguments as add_template_global(). An example usage,

def global():
    ...

blueprint = Blueprint(__name__)
blueprint.add_app_template_global(global)
add_app_template_test(func: Callable, name: Optional[str] = None) → None

Add an application wide template test.

This is designed to be used on the blueprint directly, and has the same arguments as add_template_test(). An example usage,

def test():
    ...

blueprint = Blueprint(__name__)
blueprint.add_app_template_test(test)
add_url_rule(path: str, endpoint: Optional[str] = None, view_func: Optional[Callable] = None, methods: Optional[Iterable[str]] = None, defaults: Optional[dict] = None, host: Optional[str] = None, subdomain: Optional[str] = None, *, provide_automatic_options: Optional[bool] = None, is_websocket: bool = False, strict_slashes: bool = True) → None

Add a route/url rule to the blueprint.

This is designed to be used on the blueprint directly, and has the same arguments as add_url_rule(). An example usage,

def route():
    ...

blueprint = Blueprint(__name__)
blueprint.add_url_rule('/', route)
add_websocket(path: str, endpoint: Optional[str] = None, view_func: Optional[Callable] = None, defaults: Optional[dict] = None, host: Optional[str] = None, subdomain: Optional[str] = None, *, strict_slashes: bool = True) → None

Add a websocket rule to the blueprint.

This is designed to be used on the blueprint directly, and has the same arguments as add_websocket(). An example usage,

def route():
    ...

blueprint = Blueprint(__name__)
blueprint.add_websocket('/', route)
after_app_request(func: Callable) → Callable

Add a after request function to the app.

This is designed to be used as a decorator, and has the same arguments as after_request(). It applies to all requests to the app this blueprint is registered on. An example usage,

blueprint = Blueprint(__name__)
@blueprint.after_app_request
def after():
    ...
after_app_websocket(func: Callable) → Callable

Add an after websocket function to the App.

This is designed to be used as a decorator, and has the same arguments as after_websocket(). It applies to all requests to the ppe this blueprint is registerd on. An example usage,

blueprint = Blueprint(__name__)
@blueprint.after_app_websocket
def after():
    ...
after_request(func: Callable) → Callable

Add an after request function to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as after_request(). It applies only to requests that are routed to an endpoint in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.after_request
def after():
    ...
after_websocket(func: Callable) → Callable

Add an after websocket function to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as after_websocket(). It applies only to requests that are routed to an endpoint in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.after_websocket
def after():
    ...
app_context_processor(func: Callable) → Callable

Add a context processor function to the app.

This is designed to be used as a decorator, and has the same arguments as context_processor(). This will add context to all templates rendered. An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_context_processor
def processor():
    ...
app_errorhandler(error: Union[Type[Exception], int]) → Callable

Add an error handler function to the App.

This is designed to be used as a decorator, and has the same arguments as errorhandler(). It applies only to all errors. An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_errorhandler(404)
def not_found():
    ...
app_template_filter(name: Optional[str] = None) → Callable

Add an application wide template filter.

This is designed to be used as a decorator, and has the same arguments as template_filter(). An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_template_filter()
def filter(value):
    ...
app_template_global(name: Optional[str] = None) → Callable

Add an application wide template global.

This is designed to be used as a decorator, and has the same arguments as template_global(). An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_template_global()
def global(value):
    ...
app_template_test(name: Optional[str] = None) → Callable

Add an application wide template test.

This is designed to be used as a decorator, and has the same arguments as template_test(). An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_template_test()
def test(value):
    ...
app_url_defaults(func: Callable) → Callable

Add a url default preprocessor.

This is designed to be used as a decorator, and has the same arguments as url_defaults(). This will apply to all urls. An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_url_defaults
def default(endpoint, values):
    ...
app_url_value_preprocessor(func: Callable) → Callable

Add a url value preprocessor.

This is designed to be used as a decorator, and has the same arguments as app_url_value_preprocessor(). This will apply to all URLs. An example usage,

blueprint = Blueprint(__name__)
@blueprint.app_url_value_preprocessor
def processor(endpoint, view_args):
    ...
before_app_first_request(func: Callable) → Callable

Add a before request first function to the app.

This is designed to be used as a decorator, and has the same arguments as before_first_request(). It is triggered before the first request to the app this blueprint is registered on. An example usage,

blueprint = Blueprint(__name__)
@blueprint.before_app_first_request
def before_first():
    ...
before_app_request(func: Callable) → Callable

Add a before request function to the app.

This is designed to be used as a decorator, and has the same arguments as before_request(). It applies to all requests to the app this blueprint is registered on. An example usage,

blueprint = Blueprint(__name__)
@blueprint.before_app_request
def before():
    ...
before_app_websocket(func: Callable) → Callable

Add a before request websocket to the App.

This is designed to be used as a decorator, and has the same arguments as before_websocket(). It applies to all requests to the app this blueprint is registered on. An example usage,

blueprint = Blueprint(__name__)
@blueprint.before_app_websocket
def before():
    ...
before_request(func: Callable) → Callable

Add a before request function to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as before_request(). It applies only to requests that are routed to an endpoint in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.before_request
def before():
    ...
before_websocket(func: Callable) → Callable

Add a before request websocket to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as before_websocket(). It applies only to requests that are routed to an endpoint in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.before_websocket
def before():
    ...
context_processor(func: Callable) → Callable

Add a context processor function to this blueprint.

This is designed to be used as a decorator, and has the same arguments as context_processor(). This will add context to all templates rendered in this blueprint’s routes. An example usage,

blueprint = Blueprint(__name__)
@blueprint.context_processor
def processor():
    ...
endpoint(endpoint: str) → Callable

Add an endpoint to the blueprint.

This is designed to be used as a decorator, and has the same arguments as endpoint(). An example usage,

blueprint = Blueprint(__name__)
@blueprint.endpoint('index')
def index():
    ...
errorhandler(error: Union[Type[Exception], int]) → Callable

Add an error handler function to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as errorhandler(). It applies only to errors that originate in routes in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.errorhandler(404)
def not_found():
    ...
json_decoder = None
json_encoder = None
make_setup_state(app: Quart, first_registration: bool, *, url_prefix: Optional[str] = None) → BlueprintSetupState

Return a blueprint setup state instance.

Parameters
  • first_registration – True if this is the first registration of this blueprint on the app.

  • url_prefix – An optional prefix to all rules

record(func: Callable[[BlueprintSetupState], Callable]) → None

Used to register a deferred action.

record_once(func: Callable[[BlueprintSetupState], Callable]) → None

Used to register a deferred action that happens only once.

register(app: Quart, first_registration: bool, *, url_prefix: Optional[str] = None) → None

Register this blueprint on the app given.

register_error_handler(error: Union[Type[Exception], int], func: Callable) → None

Add an error handler function to the blueprint.

This is designed to be used on the blueprint directly, and has the same arguments as register_error_handler(). An example usage,

def not_found():
    ...

blueprint = Blueprint(__name__)
blueprint.register_error_handler(404, not_found)
route(path: str, methods: Optional[List[str]] = None, endpoint: Optional[str] = None, defaults: Optional[dict] = None, host: Optional[str] = None, subdomain: Optional[str] = None, *, provide_automatic_options: Optional[bool] = None, strict_slashes: bool = True) → Callable

Add a route to the blueprint.

This is designed to be used as a decorator, and has the same arguments as route(). An example usage,

blueprint = Blueprint(__name__)
@blueprint.route('/')
def route():
    ...
teardown_app_request(func: Callable) → Callable

Add a teardown request function to the app.

This is designed to be used as a decorator, and has the same arguments as teardown_request(). It applies to all requests to the app this blueprint is registered on. An example usage,

blueprint = Blueprint(__name__)
@blueprint.teardown_app_request
def teardown():
    ...
teardown_request(func: Callable) → Callable

Add a teardown request function to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as teardown_request(). It applies only to requests that are routed to an endpoint in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.teardown_request
def teardown():
    ...
teardown_websocket(func: Callable) → Callable

Add a teardown websocket function to the Blueprint.

This is designed to be used as a decorator, and has the same arguments as teardown_websocket(). It applies only to requests that are routed to an endpoint in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.teardown_websocket
def teardown():
    ...
url_defaults(func: Callable) → Callable

Add a url default preprocessor.

This is designed to be used as a decorator, and has the same arguments as url_defaults(). This will apply to urls in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.url_defaults
def default(endpoint, values):
    ...
url_value_preprocessor(func: Callable) → Callable

Add a url value preprocessor.

This is designed to be used as a decorator, and has the same arguments as url_value_preprocessor(). This will apply to urls in this blueprint. An example usage,

blueprint = Blueprint(__name__)
@blueprint.url_value_preprocessor
def processor(endpoint, view_args):
    ...
websocket(path: str, endpoint: Optional[str] = None, defaults: Optional[dict] = None, host: Optional[str] = None, subdomain: Optional[str] = None, *, strict_slashes: bool = True) → Callable

Add a websocket to the blueprint.

This is designed to be used as a decorator, and has the same arguments as websocket(). An example usage,

blueprint = Blueprint(__name__)
@blueprint.websocket('/')
async def route():
    ...
class quart.flask_patch.Config(root_path: Union[bytes, str, os.PathLike], defaults: Optional[dict] = None)

Bases: dict

Extends a standard Python dictionary with additional load (from) methods.

Note that the convention (as enforced when loading) is that configuration keys are upper case. Whilst you can set lower case keys it is not recommended.

from_envvar(variable_name: str, silent: bool = False) → None

Load the configuration from a location specified in the environment.

This will load a cfg file using from_pyfile() from the location specified in the environment, for example the two blocks below are equivalent.

app.config.from_envvar('CONFIG')
filename = os.environ['CONFIG']
app.config.from_pyfile(filename)
from_json(filename: str, silent: bool = False) → None

Load the configuration values from a JSON formatted file.

This allows configuration to be loaded as so

app.config.from_json('config.json')
Parameters
  • filename – The filename which when appended to root_path gives the path to the file.

  • silent – If True any errors will fail silently.

from_mapping(mapping: Optional[Mapping[str, Any]] = None, **kwargs: Any) → None

Load the configuration values from a mapping.

This allows either a mapping to be directly passed or as keyword arguments, for example,

config = {'FOO': 'bar'}
app.config.from_mapping(config)
app.config.form_mapping(FOO='bar')
Parameters
  • mapping – Optionally a mapping object.

  • kwargs – Optionally a collection of keyword arguments to form a mapping.

from_object(instance: Union[object, str]) → None

Load the configuration from a Python object.

This can be used to reference modules or objects within modules for example,

app.config.from_object('module')
app.config.from_object('module.instance')
from module import instance
app.config.from_object(instance)

are valid.

Parameters

instance – Either a str referencing a python object or the object itself.

from_pyfile(filename: str, silent: bool = False) → None

Load the configuration from a Python cfg or py file.

See Python’s ConfigParser docs for details on the cfg format. It is a common practice to load the defaults from the source using the from_object() and then override with a cfg or py file, for example

app.config.from_object('config_module')
app.config.from_pyfile('production.cfg')
Parameters

filename – The filename which when appended to root_path gives the path to the file

from_toml(filename: str, silent: bool = False) → None

Load the configuration values from a TOML formatted file.

This allows configuration to be loaded as so

app.config.from_toml('config.toml')
Parameters
  • filename – The filename which when appended to root_path gives the path to the file.

  • silent – If True any errors will fail silently.

get_namespace(namespace: str, lowercase: bool = True, trim_namespace: bool = True) → Dict[str, Any]

Return a dictionary of keys within a namespace.

A namespace is considered to be a key prefix, for example the keys FOO_A, FOO_BAR, FOO_B are all within the FOO namespace. This method would return a dictionary with these keys and values present.

config = {'FOO_A': 'a', 'FOO_BAR': 'bar', 'BAR': False}
app.config.from_mapping(config)
assert app.config.get_namespace('FOO_') == {'a': 'a', 'bar': 'bar'}
Parameters
  • namespace – The namespace itself (should be uppercase).

  • lowercase – Lowercase the keys in the returned dictionary.

  • trim_namespace – Remove the namespace from the returned keys.

quart.flask_patch.copy_current_request_context(func: Callable) → Callable

Share the current request context with the function decorated.

The request context is local per task and hence will not be available in any other task. This decorator can be used to make the context available,

@copy_current_request_context
async def within_context() -> None:
    method = request.method
    ...
quart.flask_patch.escape(s) → markup

Convert the characters &, <, >, ‘, and ” in string s to HTML-safe sequences. Use this if you need to display text that might contain such characters in HTML. Marks return value as markup string.

quart.flask_patch.flash(*args: Any, **kwargs: Any) → Any
quart.flask_patch.Flask

alias of quart.app.Quart

quart.flask_patch.get_flashed_messages(with_categories: bool = False, category_filter: List[str] = []) → Union[List[str], List[Tuple[str, str]]]

Retrieve the flashed messages stored in the session.

This is mostly useful in templates where it is exposed as a global function, for example

<ul>
{% for message in get_flashed_messages() %}
  <li>{{ message }}</li>
{% endfor %}
</ul>

Note that caution is required for usage of category_filter as all messages will be popped, but only those matching the filter returned. See flash() for message creation.

quart.flask_patch.get_template_attribute(template_name: str, attribute: str) → Any

Load a attribute from a template.

This is useful in Python code in order to use attributes in templates.

Parameters
  • template_name – To load the attribute from.

  • attribute – The attribute name to load

quart.flask_patch.has_app_context() → bool

Check if execution is within an app context.

This allows a controlled way to act if there is an app context available, or silently not act if not. For example,

if has_app_context():
    log.info("Executing in %s context", current_app.name)

See also has_request_context()

quart.flask_patch.has_request_context() → bool

Check if execution is within a request context.

This allows a controlled way to act if there is a request context available, or silently not act if not. For example,

if has_request_context():
    log.info("Request endpoint %s", request.endpoint)

See also has_app_context().

quart.flask_patch.jsonify(*args: Any, **kwargs: Any) → Response
quart.flask_patch.make_response(*args: Any, **kwargs: Any) → Any
class quart.flask_patch.Markup

Bases: str

A string that is ready to be safely inserted into an HTML or XML document, either because it was escaped or because it was marked safe.

Passing an object to the constructor converts it to text and wraps it to mark it safe without escaping. To escape the text, use the escape() class method instead.

>>> Markup('Hello, <em>World</em>!')
Markup('Hello, <em>World</em>!')
>>> Markup(42)
Markup('42')
>>> Markup.escape('Hello, <em>World</em>!')
Markup('Hello &lt;em&gt;World&lt;/em&gt;!')

This implements the __html__() interface that some frameworks use. Passing an object that implements __html__() will wrap the output of that method, marking it safe.

>>> class Foo:
...     def __html__(self):
...         return '<a href="/foo">foo</a>'
...
>>> Markup(Foo())
Markup('<a href="/foo">foo</a>')

This is a subclass of the text type (str in Python 3, unicode in Python 2). It has the same methods as that type, but all methods escape their arguments and return a Markup instance.

>>> Markup('<em>%s</em>') % 'foo & bar'
Markup('<em>foo &amp; bar</em>')
>>> Markup('<em>Hello</em> ') + '<foo>'
Markup('<em>Hello</em> &lt;foo&gt;')
capitalize(*args, **kwargs)

Return a capitalized version of the string.

More specifically, make the first character have upper case and the rest lower case.

center(*args, **kwargs)

Return a centered string of length width.

Padding is done using the specified fill character (default is a space).

classmethod escape(s)

Escape a string. Calls escape() and ensures that for subclasses the correct type is returned.

expandtabs(*args, **kwargs)

Return a copy where all tab characters are expanded using spaces.

If tabsize is not given, a tab size of 8 characters is assumed.

format(*args, **kwargs) → str

Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).

join(seq)

Concatenate any number of strings.

The string whose method is called is inserted in between each given string. The result is returned as a new string.

Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

ljust(*args, **kwargs)

Return a left-justified string of length width.

Padding is done using the specified fill character (default is a space).

lower(*args, **kwargs)

Return a copy of the string converted to lowercase.

lstrip(*args, **kwargs)

Return a copy of the string with leading whitespace removed.

If chars is given and not None, remove characters in chars instead.

partition(sep)

Partition the string into three parts using the given separator.

This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

replace(*args, **kwargs)

Return a copy with all occurrences of substring old replaced by new.

count

Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are replaced.

rjust(*args, **kwargs)

Return a right-justified string of length width.

Padding is done using the specified fill character (default is a space).

rpartition(sep)

Partition the string into three parts using the given separator.

This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

rsplit(*args, **kwargs)

Return a list of the words in the string, using sep as the delimiter string.

sep

The delimiter according which to split the string. None (the default value) means split according to any whitespace, and discard empty strings from the result.

maxsplit

Maximum number of splits to do. -1 (the default value) means no limit.

Splits are done starting at the end of the string and working to the front.

rstrip(*args, **kwargs)

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

split(*args, **kwargs)

Return a list of the words in the string, using sep as the delimiter string.

sep

The delimiter according which to split the string. None (the default value) means split according to any whitespace, and discard empty strings from the result.

maxsplit

Maximum number of splits to do. -1 (the default value) means no limit.

splitlines(*args, **kwargs)

Return a list of the lines in the string, breaking at line boundaries.

Line breaks are not included in the resulting list unless keepends is given and true.

strip(*args, **kwargs)

Return a copy of the string with leading and trailing whitespace remove.

If chars is given and not None, remove characters in chars instead.

striptags()

unescape() the markup, remove tags, and normalize whitespace to single spaces.

>>> Markup('Main &raquo;        <em>About</em>').striptags()
'Main » About'
swapcase(*args, **kwargs)

Convert uppercase characters to lowercase and lowercase characters to uppercase.

title(*args, **kwargs)

Return a version of the string where each word is titlecased.

More specifically, words start with uppercased characters and all remaining cased characters have lower case.

translate(*args, **kwargs)

Replace each character in the string using the given translation table.

table

Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

unescape()

Convert escaped markup back into a text string. This replaces HTML entities with the characters they represent.

>>> Markup('Main &raquo; <em>About</em>').unescape()
'Main » <em>About</em>'
upper(*args, **kwargs)

Return a copy of the string converted to uppercase.

zfill(*args, **kwargs)

Pad a numeric string with zeros on the left, to fill a field of the given width.

The string is never truncated.

quart.flask_patch.redirect(location: str, status_code: int = 302) → Response
quart.flask_patch.render_template(*args: Any, **kwargs: Any) → Any
quart.flask_patch.render_template_string(*args: Any, **kwargs: Any) → Any
class quart.flask_patch.Request(method: str, scheme: str, path: str, query_string: bytes, headers: quart.datastructures.CIMultiDict, root_path: str, http_version: str, *, max_content_length: Optional[int] = None, body_timeout: Optional[int] = None, send_push_promise: Callable[[str, quart.datastructures.Headers], Awaitable[None]])

Bases: quart.wrappers._base.BaseRequestWebsocket, quart.wrappers._base.JSONMixin

This class represents a request.

It can be subclassed and the subclassed used in preference by replacing the request_class with your subclass.

body_class

The class to store the body data within.

body_class

alias of Body

property content_encoding
property content_length
property content_md5
property content_type
property data
property files

The parsed files.

This will return an empty multidict unless the request mimetype was enctype="multipart/form-data" and the method POST, PUT, or PATCH.

property form

The parsed form encoded data.

Note file data is present in the files.

async get_data(raw: bool = True) → AnyStr

The request body data.

async send_push_promise(path: str) → None
property values
class quart.flask_patch.Response(response: Union[quart.wrappers.response.ResponseBody, AnyStr, Iterable], status: Optional[int] = None, headers: Union[dict, quart.datastructures.CIMultiDict, quart.datastructures.Headers, None] = None, mimetype: Optional[str] = None, content_type: Optional[str] = None)

Bases: quart.wrappers._base._BaseRequestResponse, quart.wrappers._base.JSONMixin

This class represents a response.

It can be subclassed and the subclassed used in preference by replacing the response_class with your subclass.

automatically_set_content_length

If False the content length header must be provided.

default_status

The status code to use if not provided.

default_mimetype

The mimetype to use if not provided.

implicit_sequence_conversion

Implicitly convert the response to a iterable in the get_data method, to allow multiple iterations.

property accept_ranges
property access_control
async add_etag(overwrite: bool = False, weak: bool = False) → None
property age
property allow
automatically_set_content_length = True
property cache_control
property content_encoding
property content_language
property content_length
property content_location
property content_md5
property content_range
property content_security_policy
property content_security_policy_report_only
property content_type
data_body_class

alias of DataBody

property date
default_mimetype = 'text/html'
default_status = 200

Delete a cookie (set to expire immediately).

property expires
file_body_class

alias of FileBody

async freeze() → None

Freeze this object ready for pickling.

async get_data(raw: bool = True) → AnyStr

Return the body data.

get_etag() → Tuple[Optional[str], Optional[bool]]
implicit_sequence_conversion = True
io_body_class

alias of IOBody

iterable_body_class

alias of IterableBody

property last_modified
property location
async make_conditional(request_range: quart.datastructures.Range, max_partial_size: Optional[int] = None) → None

Make the response conditional to the

Parameters
  • request_range – The range as requested by the request.

  • max_partial_size – The maximum length the server is willing to serve in a single response. Defaults to unlimited.

property referrer
property retry_after

Set a cookie in the response headers.

The arguments are the standard cookie morsels and this is a wrapper around the stdlib SimpleCookie code.

set_data(data: AnyStr) → None

Set the response data.

This will encode using the charset.

set_etag(etag: str, weak: bool = False) → None
property vary
quart.flask_patch.safe_join(directory: Union[bytes, str, os.PathLike], *paths: Union[bytes, str, os.PathLike]) → pathlib.Path

Safely join the paths to the known directory to return a full path.

Raises
  • NotFound – if the full path does not share a commonprefix with

  • the directory.

quart.flask_patch.send_file(*args: Any, **kwargs: Any) → Any
quart.flask_patch.send_from_directory(*args: Any, **kwargs: Any) → Any
quart.flask_patch.stream_with_context(func: Callable) → Callable

Share the current request context with a generator.

This allows the request context to be accessed within a streaming generator, for example,

@app.route('/')
def index() -> AsyncGenerator[bytes, None]:
    @stream_with_context
    async def generator() -> bytes:
        yield request.method.encode()
        yield b' '
        yield request.path.encode()

    return generator()
quart.flask_patch.url_for(endpoint: str, *, _anchor: Optional[str] = None, _external: Optional[bool] = None, _method: Optional[str] = None, _scheme: Optional[str] = None, **values: Any) → str

Return the url for a specific endpoint.

This is most useful in templates and redirects to create a URL that can be used in the browser.

Parameters
  • endpoint – The endpoint to build a url for, if prefixed with . it targets endpoint’s in the current blueprint.

  • _anchor – Additional anchor text to append (i.e. #text).

  • _external – Return an absolute url for external (to app) usage.

  • _method – The method to consider alongside the endpoint.

  • _scheme – A specific scheme to use.

  • values – The values to build into the URL, as specified in the endpoint rule.