docs: `True, False and None`

This commit is contained in:
defuz 2014-11-05 06:04:58 +03:00
parent 6dbb015b43
commit 8284217593
19 changed files with 99 additions and 99 deletions

10
CHANGES
View file

@ -12,9 +12,9 @@ Version 1.0
additional keyword arguments to the constructor of additional keyword arguments to the constructor of
:attr:`flask.Flask.test_client_class`. :attr:`flask.Flask.test_client_class`.
- Added ``SESSION_REFRESH_EACH_REQUEST`` config key that controls the - Added ``SESSION_REFRESH_EACH_REQUEST`` config key that controls the
set-cookie behavior. If set to `True` a permanent session will be set-cookie behavior. If set to ``True`` a permanent session will be
refreshed each request and get their lifetime extended, if set to refreshed each request and get their lifetime extended, if set to
`False` it will only be modified if the session actually modifies. ``False`` it will only be modified if the session actually modifies.
Non permanent sessions are not affected by this and will always Non permanent sessions are not affected by this and will always
expire if the browser window closes. expire if the browser window closes.
- Made Flask support custom JSON mimetypes for incoming data. - Made Flask support custom JSON mimetypes for incoming data.
@ -183,7 +183,7 @@ Released on July 1st 2012, codename Campari.
explicitly. explicitly.
- Unregister a circular dependency between the WSGI environment and - Unregister a circular dependency between the WSGI environment and
the request object when shutting down the request. This means that the request object when shutting down the request. This means that
environ ``werkzeug.request`` will be `None` after the response was environ ``werkzeug.request`` will be ``None`` after the response was
returned to the WSGI server but has the advantage that the garbage returned to the WSGI server but has the advantage that the garbage
collector is not needed on CPython to tear down the request unless collector is not needed on CPython to tear down the request unless
the user created circular dependencies themselves. the user created circular dependencies themselves.
@ -204,8 +204,8 @@ Released on July 1st 2012, codename Campari.
- The :func:`flask.get_flashed_messages` function now allows rendering flashed - The :func:`flask.get_flashed_messages` function now allows rendering flashed
message categories in separate blocks, through a ``category_filter`` message categories in separate blocks, through a ``category_filter``
argument. argument.
- The :meth:`flask.Flask.run` method now accepts `None` for `host` and `port` - The :meth:`flask.Flask.run` method now accepts ``None`` for `host` and `port`
arguments, using default values when `None`. This allows for calling run arguments, using default values when ``None``. This allows for calling run
using configuration values, e.g. ``app.run(app.config.get('MYHOST'), using configuration values, e.g. ``app.run(app.config.get('MYHOST'),
app.config.get('MYPORT'))``, with proper behavior whether or not a config app.config.get('MYPORT'))``, with proper behavior whether or not a config
file is provided. file is provided.

View file

@ -115,7 +115,7 @@ Incoming Request Data
.. attribute:: is_xhr .. attribute:: is_xhr
`True` if the request was triggered via a JavaScript ``True`` if the request was triggered via a JavaScript
`XMLHttpRequest`. This only works with libraries that support the `XMLHttpRequest`. This only works with libraries that support the
``X-Requested-With`` header and set it to `XMLHttpRequest`. ``X-Requested-With`` header and set it to `XMLHttpRequest`.
Libraries that do that are prototype, jQuery and Mochikit and Libraries that do that are prototype, jQuery and Mochikit and
@ -178,14 +178,14 @@ To access the current session you can use the :class:`session` object:
.. attribute:: new .. attribute:: new
`True` if the session is new, `False` otherwise. ``True`` if the session is new, ``False`` otherwise.
.. attribute:: modified .. attribute:: modified
`True` if the session object detected a modification. Be advised ``True`` if the session object detected a modification. Be advised
that modifications on mutable structures are not picked up that modifications on mutable structures are not picked up
automatically, in that situation you have to explicitly set the automatically, in that situation you have to explicitly set the
attribute to `True` yourself. Here an example:: attribute to ``True`` yourself. Here an example::
# this change is not picked up because a mutable object (here # this change is not picked up because a mutable object (here
# a list) is changed. # a list) is changed.
@ -195,9 +195,9 @@ To access the current session you can use the :class:`session` object:
.. attribute:: permanent .. attribute:: permanent
If set to `True` the session lives for If set to ``True`` the session lives for
:attr:`~flask.Flask.permanent_session_lifetime` seconds. The :attr:`~flask.Flask.permanent_session_lifetime` seconds. The
default is 31 days. If set to `False` (which is the default) the default is 31 days. If set to ``False`` (which is the default) the
session will be deleted when the user closes the browser. session will be deleted when the user closes the browser.
@ -279,7 +279,7 @@ thing, like it does for :class:`request` and :class:`session`.
pattern for testing. pattern for testing.
Additionally as of 0.10 you can use the :meth:`get` method to Additionally as of 0.10 you can use the :meth:`get` method to
get an attribute or `None` (or the second argument) if it's not set. get an attribute or ``None`` (or the second argument) if it's not set.
These two usages are now equivalent:: These two usages are now equivalent::
user = getattr(flask.g, 'user', None) user = getattr(flask.g, 'user', None)
@ -516,7 +516,7 @@ Signals
.. data:: signals_available .. data:: signals_available
`True` if the signaling system is available. This is the case ``True`` if the signaling system is available. This is the case
when `blinker`_ is installed. when `blinker`_ is installed.
.. data:: template_rendered .. data:: template_rendered

View file

@ -56,7 +56,7 @@ The following configuration values are used internally by Flask:
``TESTING`` enable/disable testing mode ``TESTING`` enable/disable testing mode
``PROPAGATE_EXCEPTIONS`` explicitly enable or disable the ``PROPAGATE_EXCEPTIONS`` explicitly enable or disable the
propagation of exceptions. If not set or propagation of exceptions. If not set or
explicitly set to `None` this is explicitly set to ``None`` this is
implicitly true if either `TESTING` or implicitly true if either `TESTING` or
`DEBUG` is true. `DEBUG` is true.
``PRESERVE_CONTEXT_ON_EXCEPTION`` By default if the application is in ``PRESERVE_CONTEXT_ON_EXCEPTION`` By default if the application is in
@ -80,20 +80,20 @@ The following configuration values are used internally by Flask:
that is not set for ``'/'``. that is not set for ``'/'``.
``SESSION_COOKIE_HTTPONLY`` controls if the cookie should be set ``SESSION_COOKIE_HTTPONLY`` controls if the cookie should be set
with the httponly flag. Defaults to with the httponly flag. Defaults to
`True`. ``True``.
``SESSION_COOKIE_SECURE`` controls if the cookie should be set ``SESSION_COOKIE_SECURE`` controls if the cookie should be set
with the secure flag. Defaults to with the secure flag. Defaults to
`False`. ``False``.
``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as ``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as
:class:`datetime.timedelta` object. :class:`datetime.timedelta` object.
Starting with Flask 0.8 this can also be Starting with Flask 0.8 this can also be
an integer representing seconds. an integer representing seconds.
``SESSION_REFRESH_EACH_REQUEST`` this flag controls how permanent ``SESSION_REFRESH_EACH_REQUEST`` this flag controls how permanent
sessions are refreshed. If set to `True` sessions are refreshed. If set to ``True``
(which is the default) then the cookie (which is the default) then the cookie
is refreshed each request which is refreshed each request which
automatically bumps the lifetime. If automatically bumps the lifetime. If
set to `False` a `set-cookie` header is set to ``False`` a `set-cookie` header is
only sent if the session is modified. only sent if the session is modified.
Non permanent sessions are not affected Non permanent sessions are not affected
by this. by this.

View file

@ -176,7 +176,7 @@ request path up to the first slash::
return app(environ, start_response) return app(environ, start_response)
The big difference between this and the subdomain one is that this one The big difference between this and the subdomain one is that this one
falls back to another application if the creator function returns `None`:: falls back to another application if the creator function returns ``None``::
from myapplication import create_app, default_app, get_user_for_prefix from myapplication import create_app, default_app, get_user_for_prefix

View file

@ -50,7 +50,7 @@ operations: :meth:`~werkzeug.contrib.cache.BaseCache.get` and
To get an item from the cache call To get an item from the cache call
:meth:`~werkzeug.contrib.cache.BaseCache.get` with a string as key name. :meth:`~werkzeug.contrib.cache.BaseCache.get` with a string as key name.
If something is in the cache, it is returned. Otherwise that function If something is in the cache, it is returned. Otherwise that function
will return `None`:: will return ``None``::
rv = cache.get('my-item') rv = cache.get('my-item')

View file

@ -109,7 +109,7 @@ your tarball::
Don't forget that even if you enlist them in your `MANIFEST.in` file, they Don't forget that even if you enlist them in your `MANIFEST.in` file, they
won't be installed for you unless you set the `include_package_data` won't be installed for you unless you set the `include_package_data`
parameter of the `setup` function to `True`! parameter of the `setup` function to ``True``!
Declaring Dependencies Declaring Dependencies

View file

@ -76,7 +76,7 @@ Here is an example document (put this also into `app.py`, e.g.)::
This example shows you how to define your schema (named structure), a This example shows you how to define your schema (named structure), a
validator for the maximum character length and uses a special MongoKit feature validator for the maximum character length and uses a special MongoKit feature
called `use_dot_notation`. Per default MongoKit behaves like a python called `use_dot_notation`. Per default MongoKit behaves like a python
dictionary but with `use_dot_notation` set to `True` you can use your dictionary but with `use_dot_notation` set to ``True`` you can use your
documents like you use models in nearly any other ORM by using dots to documents like you use models in nearly any other ORM by using dots to
separate between attributes. separate between attributes.

View file

@ -23,7 +23,7 @@ often forgotten, but you don't have to do that by hand, there is a
function for that that is used like a decorator (:func:`functools.wraps`). function for that that is used like a decorator (:func:`functools.wraps`).
This example assumes that the login page is called ``'login'`` and that This example assumes that the login page is called ``'login'`` and that
the current user is stored as `g.user` and `None` if there is no-one the current user is stored as `g.user` and ``None`` if there is no-one
logged in:: logged in::
from functools import wraps from functools import wraps
@ -120,7 +120,7 @@ As you can see, if no template name is provided it will use the endpoint
of the URL map with dots converted to slashes + ``'.html'``. Otherwise of the URL map with dots converted to slashes + ``'.html'``. Otherwise
the provided template name is used. When the decorated function returns, the provided template name is used. When the decorated function returns,
the dictionary returned is passed to the template rendering function. If the dictionary returned is passed to the template rendering function. If
`None` is returned, an empty dictionary is assumed, if something else than ``None`` is returned, an empty dictionary is assumed, if something else than
a dictionary is returned we return it from the function unchanged. That a dictionary is returned we return it from the function unchanged. That
way you can still use the redirect function or return simple strings. way you can still use the redirect function or return simple strings.

View file

@ -64,7 +64,7 @@ Things to remember:
the data is submitted via the HTTP `POST` method and the data is submitted via the HTTP `POST` method and
:attr:`~flask.request.args` if the data is submitted as `GET`. :attr:`~flask.request.args` if the data is submitted as `GET`.
2. to validate the data, call the :func:`~wtforms.form.Form.validate` 2. to validate the data, call the :func:`~wtforms.form.Form.validate`
method which will return `True` if the data validates, `False` method which will return ``True`` if the data validates, ``False``
otherwise. otherwise.
3. to access individual values from the form, access `form.<NAME>.data`. 3. to access individual values from the form, access `form.<NAME>.data`.

View file

@ -108,7 +108,7 @@ Comparisons:
- against arbitrary types: ``==`` and ``!=`` - against arbitrary types: ``==`` and ``!=``
- against singletons with ``is`` and ``is not`` (eg: ``foo is not - against singletons with ``is`` and ``is not`` (eg: ``foo is not
None``) None``)
- never compare something with `True` or `False` (for example never - never compare something with ``True`` or ``False`` (for example never
do ``foo == False``, do ``not foo`` instead) do ``foo == False``, do ``not foo`` instead)
Negated containment checks: Negated containment checks:

View file

@ -53,7 +53,7 @@ every time the app context tears down. So what does this mean?
Essentially the app context is created before the request comes in and is Essentially the app context is created before the request comes in and is
destroyed (torn down) whenever the request finishes. A teardown can destroyed (torn down) whenever the request finishes. A teardown can
happen because of two reasons: either everything went well (the error happen because of two reasons: either everything went well (the error
parameter will be `None`) or an exception happened in which case the error parameter will be ``None``) or an exception happened in which case the error
is passed to the teardown function. is passed to the teardown function.
Curious about what these contexts mean? Have a look at the Curious about what these contexts mean? Have a look at the

View file

@ -46,7 +46,7 @@ redirect back to the `show_entries` page::
return redirect(url_for('show_entries')) return redirect(url_for('show_entries'))
Note that we check that the user is logged in here (the `logged_in` key is Note that we check that the user is logged in here (the `logged_in` key is
present in the session and `True`). present in the session and ``True``).
.. admonition:: Security Note .. admonition:: Security Note
@ -61,7 +61,7 @@ Login and Logout
These functions are used to sign the user in and out. Login checks the These functions are used to sign the user in and out. Login checks the
username and password against the ones from the configuration and sets the username and password against the ones from the configuration and sets the
`logged_in` key in the session. If the user logged in successfully, that `logged_in` key in the session. If the user logged in successfully, that
key is set to `True`, and the user is redirected back to the `show_entries` key is set to ``True``, and the user is redirected back to the `show_entries`
page. In addition, a message is flashed that informs the user that he or page. In addition, a message is flashed that informs the user that he or
she was logged in successfully. If an error occurred, the template is she was logged in successfully. If an error occurred, the template is
notified about that, and the user is asked again:: notified about that, and the user is asked again::

View file

@ -135,7 +135,7 @@ class Flask(_PackageBoundObject):
By default the folder ``'instance'`` next to the By default the folder ``'instance'`` next to the
package or module is assumed to be the instance package or module is assumed to be the instance
path. path.
:param instance_relative_config: if set to `True` relative filenames :param instance_relative_config: if set to ``True`` relative filenames
for loading the config are assumed to for loading the config are assumed to
be relative to the instance path instead be relative to the instance path instead
of the application root. of the application root.
@ -193,16 +193,16 @@ class Flask(_PackageBoundObject):
#: .. versionadded:: 1.0 #: .. versionadded:: 1.0
config_class = Config config_class = Config
#: The debug flag. Set this to `True` to enable debugging of the #: The debug flag. Set this to ``True`` to enable debugging of the
#: application. In debug mode the debugger will kick in when an unhandled #: application. In debug mode the debugger will kick in when an unhandled
#: exception occurs and the integrated server will automatically reload #: exception occurs and the integrated server will automatically reload
#: the application if changes in the code are detected. #: the application if changes in the code are detected.
#: #:
#: This attribute can also be configured from the config with the `DEBUG` #: This attribute can also be configured from the config with the `DEBUG`
#: configuration key. Defaults to `False`. #: configuration key. Defaults to ``False``.
debug = ConfigAttribute('DEBUG') debug = ConfigAttribute('DEBUG')
#: The testing flag. Set this to `True` to enable the test mode of #: The testing flag. Set this to ``True`` to enable the test mode of
#: Flask extensions (and in the future probably also Flask itself). #: Flask extensions (and in the future probably also Flask itself).
#: For example this might activate unittest helpers that have an #: For example this might activate unittest helpers that have an
#: additional runtime cost which should not be enabled by default. #: additional runtime cost which should not be enabled by default.
@ -211,7 +211,7 @@ class Flask(_PackageBoundObject):
#: default it's implicitly enabled. #: default it's implicitly enabled.
#: #:
#: This attribute can also be configured from the config with the #: This attribute can also be configured from the config with the
#: `TESTING` configuration key. Defaults to `False`. #: `TESTING` configuration key. Defaults to ``False``.
testing = ConfigAttribute('TESTING') testing = ConfigAttribute('TESTING')
#: If a secret key is set, cryptographic components can use this to #: If a secret key is set, cryptographic components can use this to
@ -219,7 +219,7 @@ class Flask(_PackageBoundObject):
#: when you want to use the secure cookie for instance. #: when you want to use the secure cookie for instance.
#: #:
#: This attribute can also be configured from the config with the #: This attribute can also be configured from the config with the
#: `SECRET_KEY` configuration key. Defaults to `None`. #: `SECRET_KEY` configuration key. Defaults to ``None``.
secret_key = ConfigAttribute('SECRET_KEY') secret_key = ConfigAttribute('SECRET_KEY')
#: The secure cookie uses this for the name of the session cookie. #: The secure cookie uses this for the name of the session cookie.
@ -245,7 +245,7 @@ class Flask(_PackageBoundObject):
#: .. versionadded:: 0.2 #: .. versionadded:: 0.2
#: #:
#: This attribute can also be configured from the config with the #: This attribute can also be configured from the config with the
#: `USE_X_SENDFILE` configuration key. Defaults to `False`. #: `USE_X_SENDFILE` configuration key. Defaults to ``False``.
use_x_sendfile = ConfigAttribute('USE_X_SENDFILE') use_x_sendfile = ConfigAttribute('USE_X_SENDFILE')
#: The name of the logger to use. By default the logger name is the #: The name of the logger to use. By default the logger name is the
@ -364,11 +364,11 @@ class Flask(_PackageBoundObject):
# :attr:`error_handler_spec` shall be used now. # :attr:`error_handler_spec` shall be used now.
self._error_handlers = {} self._error_handlers = {}
#: A dictionary of all registered error handlers. The key is `None` #: A dictionary of all registered error handlers. The key is ``None``
#: for error handlers active on the application, otherwise the key is #: for error handlers active on the application, otherwise the key is
#: the name of the blueprint. Each key points to another dictionary #: the name of the blueprint. Each key points to another dictionary
#: where the key is the status code of the http exception. The #: where the key is the status code of the http exception. The
#: special key `None` points to a list of tuples where the first item #: special key ``None`` points to a list of tuples where the first item
#: is the class for the instance check and the second the error handler #: is the class for the instance check and the second the error handler
#: function. #: function.
#: #:
@ -379,7 +379,7 @@ class Flask(_PackageBoundObject):
#: A list of functions that are called when :meth:`url_for` raises a #: A list of functions that are called when :meth:`url_for` raises a
#: :exc:`~werkzeug.routing.BuildError`. Each function registered here #: :exc:`~werkzeug.routing.BuildError`. Each function registered here
#: is called with `error`, `endpoint` and `values`. If a function #: is called with `error`, `endpoint` and `values`. If a function
#: returns `None` or raises a `BuildError` the next function is #: returns ``None`` or raises a `BuildError` the next function is
#: tried. #: tried.
#: #:
#: .. versionadded:: 0.9 #: .. versionadded:: 0.9
@ -387,7 +387,7 @@ class Flask(_PackageBoundObject):
#: A dictionary with lists of functions that should be called at the #: A dictionary with lists of functions that should be called at the
#: beginning of the request. The key of the dictionary is the name of #: beginning of the request. The key of the dictionary is the name of
#: the blueprint this function is active for, `None` for all requests. #: the blueprint this function is active for, ``None`` for all requests.
#: This can for example be used to open database connections or #: This can for example be used to open database connections or
#: getting hold of the currently logged in user. To register a #: getting hold of the currently logged in user. To register a
#: function here, use the :meth:`before_request` decorator. #: function here, use the :meth:`before_request` decorator.
@ -402,7 +402,7 @@ class Flask(_PackageBoundObject):
#: A dictionary with lists of functions that should be called after #: A dictionary with lists of functions that should be called after
#: each request. The key of the dictionary is the name of the blueprint #: each request. The key of the dictionary is the name of the blueprint
#: this function is active for, `None` for all requests. This can for #: this function is active for, ``None`` for all requests. This can for
#: example be used to open database connections or getting hold of the #: example be used to open database connections or getting hold of the
#: currently logged in user. To register a function here, use the #: currently logged in user. To register a function here, use the
#: :meth:`after_request` decorator. #: :meth:`after_request` decorator.
@ -411,7 +411,7 @@ class Flask(_PackageBoundObject):
#: A dictionary with lists of functions that are called after #: A dictionary with lists of functions that are called after
#: each request, even if an exception has occurred. The key of the #: each request, even if an exception has occurred. The key of the
#: dictionary is the name of the blueprint this function is active for, #: dictionary is the name of the blueprint this function is active for,
#: `None` for all requests. These functions are not allowed to modify #: ``None`` for all requests. These functions are not allowed to modify
#: the request, and their return values are ignored. If an exception #: the request, and their return values are ignored. If an exception
#: occurred while processing the request, it gets passed to each #: occurred while processing the request, it gets passed to each
#: teardown_request function. To register a function here, use the #: teardown_request function. To register a function here, use the
@ -431,7 +431,7 @@ class Flask(_PackageBoundObject):
#: A dictionary with lists of functions that can be used as URL #: A dictionary with lists of functions that can be used as URL
#: value processor functions. Whenever a URL is built these functions #: value processor functions. Whenever a URL is built these functions
#: are called to modify the dictionary of values in place. The key #: are called to modify the dictionary of values in place. The key
#: `None` here is used for application wide #: ``None`` here is used for application wide
#: callbacks, otherwise the key is the name of the blueprint. #: callbacks, otherwise the key is the name of the blueprint.
#: Each of these functions has the chance to modify the dictionary #: Each of these functions has the chance to modify the dictionary
#: #:
@ -439,7 +439,7 @@ class Flask(_PackageBoundObject):
self.url_value_preprocessors = {} self.url_value_preprocessors = {}
#: A dictionary with lists of functions that can be used as URL value #: A dictionary with lists of functions that can be used as URL value
#: preprocessors. The key `None` here is used for application wide #: preprocessors. The key ``None`` here is used for application wide
#: callbacks, otherwise the key is the name of the blueprint. #: callbacks, otherwise the key is the name of the blueprint.
#: Each of these functions has the chance to modify the dictionary #: Each of these functions has the chance to modify the dictionary
#: of URL values before they are used as the keyword arguments of the #: of URL values before they are used as the keyword arguments of the
@ -452,7 +452,7 @@ class Flask(_PackageBoundObject):
#: A dictionary with list of functions that are called without argument #: A dictionary with list of functions that are called without argument
#: to populate the template context. The key of the dictionary is the #: to populate the template context. The key of the dictionary is the
#: name of the blueprint this function is active for, `None` for all #: name of the blueprint this function is active for, ``None`` for all
#: requests. Each returns a dictionary that the template context is #: requests. Each returns a dictionary that the template context is
#: updated with. To register a function here, use the #: updated with. To register a function here, use the
#: :meth:`context_processor` decorator. #: :meth:`context_processor` decorator.
@ -612,7 +612,7 @@ class Flask(_PackageBoundObject):
@property @property
def got_first_request(self): def got_first_request(self):
"""This attribute is set to `True` if the application started """This attribute is set to ``True`` if the application started
handling the first request. handling the first request.
.. versionadded:: 0.8 .. versionadded:: 0.8
@ -715,7 +715,7 @@ class Flask(_PackageBoundObject):
""" """
def select_jinja_autoescape(self, filename): def select_jinja_autoescape(self, filename):
"""Returns `True` if autoescaping should be active for the given """Returns ``True`` if autoescaping should be active for the given
template name. template name.
.. versionadded:: 0.5 .. versionadded:: 0.5
@ -782,7 +782,7 @@ class Flask(_PackageBoundObject):
unless it is in debug mode. As such to enable just the unless it is in debug mode. As such to enable just the
interactive debugger without the code reloading, you have to interactive debugger without the code reloading, you have to
invoke :meth:`run` with ``debug=True`` and ``use_reloader=False``. invoke :meth:`run` with ``debug=True`` and ``use_reloader=False``.
Setting ``use_debugger`` to `True` without being in debug mode Setting ``use_debugger`` to ``True`` without being in debug mode
won't catch any exceptions because there won't be any to won't catch any exceptions because there won't be any to
catch. catch.
@ -1102,8 +1102,8 @@ class Flask(_PackageBoundObject):
however is discouraged as it requires fiddling with nested dictionaries however is discouraged as it requires fiddling with nested dictionaries
and the special case for arbitrary exception types. and the special case for arbitrary exception types.
The first `None` refers to the active blueprint. If the error The first ``None`` refers to the active blueprint. If the error
handler should be application wide `None` shall be used. handler should be application wide ``None`` shall be used.
.. versionadded:: 0.7 .. versionadded:: 0.7
Use :meth:`register_error_handler` instead of modifying Use :meth:`register_error_handler` instead of modifying
@ -1392,12 +1392,12 @@ class Flask(_PackageBoundObject):
def trap_http_exception(self, e): def trap_http_exception(self, e):
"""Checks if an HTTP exception should be trapped or not. By default """Checks if an HTTP exception should be trapped or not. By default
this will return `False` for all exceptions except for a bad request this will return ``False`` for all exceptions except for a bad request
key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to `True`. It key error if ``TRAP_BAD_REQUEST_ERRORS`` is set to ``True``. It
also returns `True` if ``TRAP_HTTP_EXCEPTIONS`` is set to `True`. also returns ``True`` if ``TRAP_HTTP_EXCEPTIONS`` is set to ``True``.
This is called for all HTTP exceptions raised by a view function. This is called for all HTTP exceptions raised by a view function.
If it returns `True` for any exception the error handler for this If it returns ``True`` for any exception the error handler for this
exception is not called and it shows up as regular exception in the exception is not called and it shows up as regular exception in the
traceback. This is helpful for debugging implicitly raised HTTP traceback. This is helpful for debugging implicitly raised HTTP
exceptions. exceptions.
@ -1584,7 +1584,7 @@ class Flask(_PackageBoundObject):
def should_ignore_error(self, error): def should_ignore_error(self, error):
"""This is called to figure out if an error should be ignored """This is called to figure out if an error should be ignored
or not as far as the teardown system is concerned. If this or not as far as the teardown system is concerned. If this
function returns `True` then the teardown handlers will not be function returns ``True`` then the teardown handlers will not be
passed the error. passed the error.
.. versionadded:: 0.10 .. versionadded:: 0.10

View file

@ -42,7 +42,7 @@ class BlueprintSetupState(object):
if subdomain is None: if subdomain is None:
subdomain = self.blueprint.subdomain subdomain = self.blueprint.subdomain
#: The subdomain that the blueprint should be active for, `None` #: The subdomain that the blueprint should be active for, ``None``
#: otherwise. #: otherwise.
self.subdomain = subdomain self.subdomain = subdomain

View file

@ -93,9 +93,9 @@ class Config(dict):
app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS']) app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
:param variable_name: name of the environment variable :param variable_name: name of the environment variable
:param silent: set to `True` if you want silent failure for missing :param silent: set to ``True`` if you want silent failure for missing
files. files.
:return: bool. `True` if able to load config, `False` otherwise. :return: bool. ``True`` if able to load config, ``False`` otherwise.
""" """
rv = os.environ.get(variable_name) rv = os.environ.get(variable_name)
if not rv: if not rv:
@ -116,7 +116,7 @@ class Config(dict):
:param filename: the filename of the config. This can either be an :param filename: the filename of the config. This can either be an
absolute filename or a filename relative to the absolute filename or a filename relative to the
root path. root path.
:param silent: set to `True` if you want silent failure for missing :param silent: set to ``True`` if you want silent failure for missing
files. files.
.. versionadded:: 0.7 .. versionadded:: 0.7
@ -173,7 +173,7 @@ class Config(dict):
:param filename: the filename of the JSON file. This can either be an :param filename: the filename of the JSON file. This can either be an
absolute filename or a filename relative to the absolute filename or a filename relative to the
root path. root path.
:param silent: set to `True` if you want silent failure for missing :param silent: set to ``True`` if you want silent failure for missing
files. files.
.. versionadded:: 1.0 .. versionadded:: 1.0

View file

@ -210,7 +210,7 @@ class RequestContext(object):
exceptions happen so that interactive debuggers have a chance to exceptions happen so that interactive debuggers have a chance to
introspect the data. With 0.4 this can also be forced for requests introspect the data. With 0.4 this can also be forced for requests
that did not fail and outside of `DEBUG` mode. By setting that did not fail and outside of `DEBUG` mode. By setting
``'flask._preserve_context'`` to `True` on the WSGI environment the ``'flask._preserve_context'`` to ``True`` on the WSGI environment the
context will not pop itself at the end of the request. This is used by context will not pop itself at the end of the request. This is used by
the :meth:`~flask.Flask.test_client` for example to implement the the :meth:`~flask.Flask.test_client` for example to implement the
deferred cleanup functionality. deferred cleanup functionality.

View file

@ -188,7 +188,7 @@ def url_for(endpoint, **values):
Variable arguments that are unknown to the target endpoint are appended Variable arguments that are unknown to the target endpoint are appended
to the generated URL as query arguments. If the value of a query argument to the generated URL as query arguments. If the value of a query argument
is `None`, the whole pair is skipped. In case blueprints are active is ``None``, the whole pair is skipped. In case blueprints are active
you can shortcut references to the same blueprint by prefixing the you can shortcut references to the same blueprint by prefixing the
local endpoint with a dot (``.``). local endpoint with a dot (``.``).
@ -203,7 +203,7 @@ def url_for(endpoint, **values):
function results in a :exc:`~werkzeug.routing.BuildError` when the current function results in a :exc:`~werkzeug.routing.BuildError` when the current
app does not have a URL for the given endpoint and values. When it does, the app does not have a URL for the given endpoint and values. When it does, the
:data:`~flask.current_app` calls its :attr:`~Flask.url_build_error_handlers` if :data:`~flask.current_app` calls its :attr:`~Flask.url_build_error_handlers` if
it is not `None`, which can return a string to use as the result of it is not ``None``, which can return a string to use as the result of
`url_for` (instead of `url_for`'s default to raise the `url_for` (instead of `url_for`'s default to raise the
:exc:`~werkzeug.routing.BuildError` exception) or re-raise the exception. :exc:`~werkzeug.routing.BuildError` exception) or re-raise the exception.
An example:: An example::
@ -244,11 +244,11 @@ def url_for(endpoint, **values):
:param endpoint: the endpoint of the URL (name of the function) :param endpoint: the endpoint of the URL (name of the function)
:param values: the variable arguments of the URL rule :param values: the variable arguments of the URL rule
:param _external: if set to `True`, an absolute URL is generated. Server :param _external: if set to ``True``, an absolute URL is generated. Server
address can be changed via `SERVER_NAME` configuration variable which address can be changed via `SERVER_NAME` configuration variable which
defaults to `localhost`. defaults to `localhost`.
:param _scheme: a string specifying the desired URL scheme. The `_external` :param _scheme: a string specifying the desired URL scheme. The `_external`
parameter must be set to `True` or a `ValueError` is raised. The default parameter must be set to ``True`` or a `ValueError` is raised. The default
behavior uses the same scheme as the current request, or behavior uses the same scheme as the current request, or
``PREFERRED_URL_SCHEME`` from the :ref:`app configuration <config>` if no ``PREFERRED_URL_SCHEME`` from the :ref:`app configuration <config>` if no
request context is available. As of Werkzeug 0.10, this also can be set request context is available. As of Werkzeug 0.10, this also can be set
@ -376,7 +376,7 @@ def get_flashed_messages(with_categories=False, category_filter=[]):
"""Pulls all flashed messages from the session and returns them. """Pulls all flashed messages from the session and returns them.
Further calls in the same request to the function will return Further calls in the same request to the function will return
the same messages. By default just the messages are returned, the same messages. By default just the messages are returned,
but when `with_categories` is set to `True`, the return value will but when `with_categories` is set to ``True``, the return value will
be a list of tuples in the form ``(category, message)`` instead. be a list of tuples in the form ``(category, message)`` instead.
Filter the flashed messages to one or more categories by providing those Filter the flashed messages to one or more categories by providing those
@ -385,7 +385,7 @@ def get_flashed_messages(with_categories=False, category_filter=[]):
arguments are distinct: arguments are distinct:
* `with_categories` controls whether categories are returned with message * `with_categories` controls whether categories are returned with message
text (`True` gives a tuple, where `False` gives just the message text). text (``True`` gives a tuple, where ``False`` gives just the message text).
* `category_filter` filters the messages down to only those matching the * `category_filter` filters the messages down to only those matching the
provided categories. provided categories.
@ -397,7 +397,7 @@ def get_flashed_messages(with_categories=False, category_filter=[]):
.. versionchanged:: 0.9 .. versionchanged:: 0.9
`category_filter` parameter added. `category_filter` parameter added.
:param with_categories: set to `True` to also receive categories. :param with_categories: set to ``True`` to also receive categories.
:param category_filter: whitelist of categories to limit return values :param category_filter: whitelist of categories to limit return values
""" """
flashes = _request_ctx_stack.top.flashes flashes = _request_ctx_stack.top.flashes
@ -459,14 +459,14 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
of data to send before calling :func:`send_file`. of data to send before calling :func:`send_file`.
:param mimetype: the mimetype of the file if provided, otherwise :param mimetype: the mimetype of the file if provided, otherwise
auto detection happens. auto detection happens.
:param as_attachment: set to `True` if you want to send this file with :param as_attachment: set to ``True`` if you want to send this file with
a ``Content-Disposition: attachment`` header. a ``Content-Disposition: attachment`` header.
:param attachment_filename: the filename for the attachment if it :param attachment_filename: the filename for the attachment if it
differs from the file's filename. differs from the file's filename.
:param add_etags: set to `False` to disable attaching of etags. :param add_etags: set to ``False`` to disable attaching of etags.
:param conditional: set to `True` to enable conditional responses. :param conditional: set to ``True`` to enable conditional responses.
:param cache_timeout: the timeout in seconds for the headers. When `None` :param cache_timeout: the timeout in seconds for the headers. When ``None``
(default), this value is set by (default), this value is set by
:meth:`~Flask.get_send_file_max_age` of :meth:`~Flask.get_send_file_max_age` of
:data:`~flask.current_app`. :data:`~flask.current_app`.
@ -784,7 +784,7 @@ class _PackageBoundObject(object):
#: it was set by the constructor. #: it was set by the constructor.
self.import_name = import_name self.import_name = import_name
#: location of the templates. `None` if templates should not be #: location of the templates. ``None`` if templates should not be
#: exposed. #: exposed.
self.template_folder = template_folder self.template_folder = template_folder
@ -818,7 +818,7 @@ class _PackageBoundObject(object):
@property @property
def has_static_folder(self): def has_static_folder(self):
"""This is `True` if the package bound object's container has a """This is ``True`` if the package bound object's container has a
folder named ``'static'``. folder named ``'static'``.
.. versionadded:: 0.5 .. versionadded:: 0.5
@ -843,7 +843,7 @@ class _PackageBoundObject(object):
Static file functions such as :func:`send_from_directory` use this Static file functions such as :func:`send_from_directory` use this
function, and :func:`send_file` calls this function on function, and :func:`send_file` calls this function on
:data:`~flask.current_app` when the given cache_timeout is `None`. If a :data:`~flask.current_app` when the given cache_timeout is ``None``. If a
cache_timeout is given in :func:`send_file`, that timeout is used; cache_timeout is given in :func:`send_file`, that timeout is used;
otherwise, this method is called. otherwise, this method is called.

View file

@ -42,13 +42,13 @@ class SessionMixin(object):
#: some session backends can tell you if a session is new, but that is #: some session backends can tell you if a session is new, but that is
#: not necessarily guaranteed. Use with caution. The default mixin #: not necessarily guaranteed. Use with caution. The default mixin
#: implementation just hardcodes `False` in. #: implementation just hardcodes ``False`` in.
new = False new = False
#: for some backends this will always be `True`, but some backends will #: for some backends this will always be ``True``, but some backends will
#: default this to false and detect changes in the dictionary for as #: default this to false and detect changes in the dictionary for as
#: long as changes do not happen on mutable structures in the session. #: long as changes do not happen on mutable structures in the session.
#: The default mixin implementation just hardcodes `True` in. #: The default mixin implementation just hardcodes ``True`` in.
modified = True modified = True
@ -149,7 +149,7 @@ class SessionInterface(object):
class Session(dict, SessionMixin): class Session(dict, SessionMixin):
pass pass
If :meth:`open_session` returns `None` Flask will call into If :meth:`open_session` returns ``None`` Flask will call into
:meth:`make_null_session` to create a session that acts as replacement :meth:`make_null_session` to create a session that acts as replacement
if the session support cannot work because some requirement is not if the session support cannot work because some requirement is not
fulfilled. The default :class:`NullSession` class that is created fulfilled. The default :class:`NullSession` class that is created
@ -228,7 +228,7 @@ class SessionInterface(object):
"""Returns the path for which the cookie should be valid. The """Returns the path for which the cookie should be valid. The
default implementation uses the value from the ``SESSION_COOKIE_PATH`` default implementation uses the value from the ``SESSION_COOKIE_PATH``
config var if it's set, and falls back to ``APPLICATION_ROOT`` or config var if it's set, and falls back to ``APPLICATION_ROOT`` or
uses ``/`` if it's `None`. uses ``/`` if it's ``None``.
""" """
return app.config['SESSION_COOKIE_PATH'] or \ return app.config['SESSION_COOKIE_PATH'] or \
app.config['APPLICATION_ROOT'] or '/' app.config['APPLICATION_ROOT'] or '/'
@ -248,7 +248,7 @@ class SessionInterface(object):
def get_expiration_time(self, app, session): def get_expiration_time(self, app, session):
"""A helper method that returns an expiration date for the session """A helper method that returns an expiration date for the session
or `None` if the session is linked to the browser session. The or ``None`` if the session is linked to the browser session. The
default implementation returns now + the permanent session default implementation returns now + the permanent session
lifetime configured on the application. lifetime configured on the application.
""" """
@ -260,8 +260,8 @@ class SessionInterface(object):
used by session backends to figure out if they should emit a used by session backends to figure out if they should emit a
set-cookie header or not. The default behavior is controlled by set-cookie header or not. The default behavior is controlled by
the ``SESSION_REFRESH_EACH_REQUEST`` config variable. If the ``SESSION_REFRESH_EACH_REQUEST`` config variable. If
it's set to `False` then a cookie is only set if the session is it's set to ``False`` then a cookie is only set if the session is
modified, if set to `True` it's always set if the session is modified, if set to ``True`` it's always set if the session is
permanent. permanent.
This check is usually skipped if sessions get deleted. This check is usually skipped if sessions get deleted.
@ -274,7 +274,7 @@ class SessionInterface(object):
return save_each and session.permanent return save_each and session.permanent
def open_session(self, app, request): def open_session(self, app, request):
"""This method has to be implemented and must either return `None` """This method has to be implemented and must either return ``None``
in case the loading failed because of a configuration error or an in case the loading failed because of a configuration error or an
instance of a session object which implements a dictionary like instance of a session object which implements a dictionary like
interface + the methods and attributes on :class:`SessionMixin`. interface + the methods and attributes on :class:`SessionMixin`.

View file

@ -47,7 +47,7 @@ class Request(RequestBase):
url_rule = None url_rule = None
#: A dict of view arguments that matched the request. If an exception #: A dict of view arguments that matched the request. If an exception
#: happened when matching, this will be `None`. #: happened when matching, this will be ``None``.
view_args = None view_args = None
#: If matching the URL failed, this is the exception that will be #: If matching the URL failed, this is the exception that will be
@ -72,7 +72,7 @@ class Request(RequestBase):
"""The endpoint that matched the request. This in combination with """The endpoint that matched the request. This in combination with
:attr:`view_args` can be used to reconstruct the same or a :attr:`view_args` can be used to reconstruct the same or a
modified URL. If an exception happened when matching, this will modified URL. If an exception happened when matching, this will
be `None`. be ``None``.
""" """
if self.url_rule is not None: if self.url_rule is not None:
return self.url_rule.endpoint return self.url_rule.endpoint
@ -99,7 +99,7 @@ class Request(RequestBase):
@property @property
def json(self): def json(self):
"""If the mimetype is `application/json` this will contain the """If the mimetype is `application/json` this will contain the
parsed JSON data. Otherwise this will be `None`. parsed JSON data. Otherwise this will be ``None``.
The :meth:`get_json` method should be used instead. The :meth:`get_json` method should be used instead.
""" """
@ -130,10 +130,10 @@ class Request(RequestBase):
only load the json data if the mimetype is ``application/json`` only load the json data if the mimetype is ``application/json``
but this can be overridden by the `force` parameter. but this can be overridden by the `force` parameter.
:param force: if set to `True` the mimetype is ignored. :param force: if set to ``True`` the mimetype is ignored.
:param silent: if set to `True` this method will fail silently :param silent: if set to ``True`` this method will fail silently
and return `None`. and return ``None``.
:param cache: if set to `True` the parsed JSON data is remembered :param cache: if set to ``True`` the parsed JSON data is remembered
on the request. on the request.
""" """
rv = getattr(self, '_cached_json', _missing) rv = getattr(self, '_cached_json', _missing)