Browse Source

remove deprecated Flask.static_path

pull/2394/head
David Lord 8 years ago
parent
commit
d63c2bc417
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
  1. 48
      flask/app.py
  2. 13
      tests/test_basic.py

48
flask/app.py

@ -349,29 +349,38 @@ class Flask(_PackageBoundObject):
#: resources contained in the package. #: resources contained in the package.
root_path = None root_path = None
def __init__(self, import_name, static_path=None, static_url_path=None, def __init__(
static_folder='static', static_host=None, self,
host_matching=False, template_folder='templates', import_name,
instance_path=None, instance_relative_config=False, static_url_path=None,
root_path=None): static_folder='static',
_PackageBoundObject.__init__(self, import_name, static_host=None,
template_folder=template_folder, host_matching=False,
root_path=root_path) template_folder='templates',
if static_path is not None: instance_path=None,
from warnings import warn instance_relative_config=False,
warn(DeprecationWarning('static_path is now called ' root_path=None
'static_url_path'), stacklevel=2) ):
static_url_path = static_path _PackageBoundObject.__init__(
self,
import_name,
template_folder=template_folder,
root_path=root_path
)
if static_url_path is not None: if static_url_path is not None:
self.static_url_path = static_url_path self.static_url_path = static_url_path
if static_folder is not None: if static_folder is not None:
self.static_folder = static_folder self.static_folder = static_folder
if instance_path is None: if instance_path is None:
instance_path = self.auto_find_instance_path() instance_path = self.auto_find_instance_path()
elif not os.path.isabs(instance_path): elif not os.path.isabs(instance_path):
raise ValueError('If an instance path is provided it must be ' raise ValueError(
'absolute. A relative path was given instead.') 'If an instance path is provided it must be absolute.'
' A relative path was given instead.'
)
#: Holds the path to the instance folder. #: Holds the path to the instance folder.
#: #:
@ -547,9 +556,12 @@ class Flask(_PackageBoundObject):
# development). Also, Google App Engine stores static files somewhere # development). Also, Google App Engine stores static files somewhere
if self.has_static_folder: if self.has_static_folder:
assert bool(static_host) == host_matching, 'Invalid static_host/host_matching combination' assert bool(static_host) == host_matching, 'Invalid static_host/host_matching combination'
self.add_url_rule(self.static_url_path + '/<path:filename>', self.add_url_rule(
endpoint='static', host=static_host, self.static_url_path + '/<path:filename>',
view_func=self.send_static_file) endpoint='static',
host=static_host,
view_func=self.send_static_file
)
#: The click command line context for this application. Commands #: The click command line context for this application. Commands
#: registered here show up in the :command:`flask` command once the #: registered here show up in the :command:`flask` command once the

13
tests/test_basic.py

@ -1353,19 +1353,6 @@ def test_static_files(app, client):
rv.close() rv.close()
def test_static_path_deprecated(recwarn):
app = flask.Flask(__name__, static_path='/foo')
recwarn.pop(DeprecationWarning)
app.testing = True
rv = app.test_client().get('/foo/index.html')
assert rv.status_code == 200
rv.close()
with app.test_request_context():
assert flask.url_for('static', filename='index.html') == '/foo/index.html'
def test_static_url_path(): def test_static_url_path():
app = flask.Flask(__name__, static_url_path='/foo') app = flask.Flask(__name__, static_url_path='/foo')
app.testing = True app.testing = True

Loading…
Cancel
Save