|
|
|
@ -349,29 +349,38 @@ class Flask(_PackageBoundObject):
|
|
|
|
|
#: resources contained in the package. |
|
|
|
|
root_path = None |
|
|
|
|
|
|
|
|
|
def __init__(self, import_name, static_path=None, static_url_path=None, |
|
|
|
|
static_folder='static', static_host=None, |
|
|
|
|
host_matching=False, template_folder='templates', |
|
|
|
|
instance_path=None, instance_relative_config=False, |
|
|
|
|
root_path=None): |
|
|
|
|
_PackageBoundObject.__init__(self, import_name, |
|
|
|
|
template_folder=template_folder, |
|
|
|
|
root_path=root_path) |
|
|
|
|
if static_path is not None: |
|
|
|
|
from warnings import warn |
|
|
|
|
warn(DeprecationWarning('static_path is now called ' |
|
|
|
|
'static_url_path'), stacklevel=2) |
|
|
|
|
static_url_path = static_path |
|
|
|
|
def __init__( |
|
|
|
|
self, |
|
|
|
|
import_name, |
|
|
|
|
static_url_path=None, |
|
|
|
|
static_folder='static', |
|
|
|
|
static_host=None, |
|
|
|
|
host_matching=False, |
|
|
|
|
template_folder='templates', |
|
|
|
|
instance_path=None, |
|
|
|
|
instance_relative_config=False, |
|
|
|
|
root_path=None |
|
|
|
|
): |
|
|
|
|
_PackageBoundObject.__init__( |
|
|
|
|
self, |
|
|
|
|
import_name, |
|
|
|
|
template_folder=template_folder, |
|
|
|
|
root_path=root_path |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
if static_url_path is not None: |
|
|
|
|
self.static_url_path = static_url_path |
|
|
|
|
|
|
|
|
|
if static_folder is not None: |
|
|
|
|
self.static_folder = static_folder |
|
|
|
|
|
|
|
|
|
if instance_path is None: |
|
|
|
|
instance_path = self.auto_find_instance_path() |
|
|
|
|
elif not os.path.isabs(instance_path): |
|
|
|
|
raise ValueError('If an instance path is provided it must be ' |
|
|
|
|
'absolute. A relative path was given instead.') |
|
|
|
|
raise ValueError( |
|
|
|
|
'If an instance path is provided it must be absolute.' |
|
|
|
|
' A relative path was given instead.' |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
#: Holds the path to the instance folder. |
|
|
|
|
#: |
|
|
|
@ -393,10 +402,6 @@ class Flask(_PackageBoundObject):
|
|
|
|
|
#: To register a view function, use the :meth:`route` decorator. |
|
|
|
|
self.view_functions = {} |
|
|
|
|
|
|
|
|
|
# support for the now deprecated `error_handlers` attribute. The |
|
|
|
|
# :attr:`error_handler_spec` shall be used now. |
|
|
|
|
self._error_handlers = {} |
|
|
|
|
|
|
|
|
|
#: A dictionary of all registered error handlers. The key is ``None`` |
|
|
|
|
#: for error handlers active on the application, otherwise the key is |
|
|
|
|
#: the name of the blueprint. Each key points to another dictionary |
|
|
|
@ -407,7 +412,7 @@ class Flask(_PackageBoundObject):
|
|
|
|
|
#: |
|
|
|
|
#: To register an error handler, use the :meth:`errorhandler` |
|
|
|
|
#: decorator. |
|
|
|
|
self.error_handler_spec = {None: self._error_handlers} |
|
|
|
|
self.error_handler_spec = {} |
|
|
|
|
|
|
|
|
|
#: A list of functions that are called when :meth:`url_for` raises a |
|
|
|
|
#: :exc:`~werkzeug.routing.BuildError`. Each function registered here |
|
|
|
@ -551,9 +556,12 @@ class Flask(_PackageBoundObject):
|
|
|
|
|
# development). Also, Google App Engine stores static files somewhere |
|
|
|
|
if self.has_static_folder: |
|
|
|
|
assert bool(static_host) == host_matching, 'Invalid static_host/host_matching combination' |
|
|
|
|
self.add_url_rule(self.static_url_path + '/<path:filename>', |
|
|
|
|
endpoint='static', host=static_host, |
|
|
|
|
view_func=self.send_static_file) |
|
|
|
|
self.add_url_rule( |
|
|
|
|
self.static_url_path + '/<path:filename>', |
|
|
|
|
endpoint='static', |
|
|
|
|
host=static_host, |
|
|
|
|
view_func=self.send_static_file |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
#: The click command line context for this application. Commands |
|
|
|
|
#: registered here show up in the :command:`flask` command once the |
|
|
|
@ -563,17 +571,6 @@ class Flask(_PackageBoundObject):
|
|
|
|
|
#: This is an instance of a :class:`click.Group` object. |
|
|
|
|
self.cli = cli.AppGroup(self.name) |
|
|
|
|
|
|
|
|
|
def _get_error_handlers(self): |
|
|
|
|
from warnings import warn |
|
|
|
|
warn(DeprecationWarning('error_handlers is deprecated, use the ' |
|
|
|
|
'new error_handler_spec attribute instead.'), stacklevel=1) |
|
|
|
|
return self._error_handlers |
|
|
|
|
def _set_error_handlers(self, value): |
|
|
|
|
self._error_handlers = value |
|
|
|
|
self.error_handler_spec[None] = value |
|
|
|
|
error_handlers = property(_get_error_handlers, _set_error_handlers) |
|
|
|
|
del _get_error_handlers, _set_error_handlers |
|
|
|
|
|
|
|
|
|
@locked_cached_property |
|
|
|
|
def name(self): |
|
|
|
|
"""The name of the application. This is usually the import name |
|
|
|
|