Skip to content
Myr

phased out shared data middleware in flask for send_file

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent d0c6ad7 · Browse files · 2 files+23 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+23 added−12 removed

  • other:+23 added−12 removed

2 files+23 added−12 removed

modified:flask/app.py+21 added-11 removed
7 unmodified lines
8 :copyright: (c) 2010 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112import os13import posixpath14from threading import Lock15from datetime import timedelta, datetime16from itertools import chain1718from jinja2 import Environment, PackageLoader, FileSystemLoader17from werkzeug import ImmutableDict, SharedDataMiddleware, create_environ19from werkzeug import ImmutableDict, create_environ20from werkzeug.routing import Map, Rule19from werkzeug.exceptions import HTTPException, InternalServerError21from werkzeug.exceptions import HTTPException, InternalServerError, NotFound2223from flask.helpers import _PackageBoundObject, url_for, get_flashed_messages, \22 _tojson_filter, get_pkg_resources24 _tojson_filter, get_pkg_resources, send_file25from flask.wrappers import Request, Response26from flask.config import ConfigAttribute, Config27from flask.ctx import _default_template_ctx_processor, _RequestContext28from flask.globals import _request_ctx_stack, request
230 unmodified lines
259 self.url_map = Map()260261 if self.static_path is not None:262 self.add_url_rule(self.static_path + '/<filename>',261 build_only=True, endpoint='static')262 if get_pkg_resources() is not None:263 target = (self.import_name, 'static')264 else:265 target = os.path.join(self.root_path, 'static')266 self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {267 self.static_path: target268 })263 endpoint='static',264 view_func=self.send_static_file)265266 #: The Jinja2 environment. It is created from the267 #: :attr:`jinja_options` and the loader that is returned268 #: by the :meth:`create_jinja_loader` function.
109 unmodified lines
378 options.setdefault('use_reloader', self.debug)379 options.setdefault('use_debugger', self.debug)380 return run_simple(host, port, self, **options)381382 def send_static_file(self, filename):383 """Function used internally to send static files from the static384 folder to the browser.385386 .. versionadded:: 0.5387 """388 filename = posixpath.normpath(filename)389 if filename.startswith('../'):390 raise NotFound()391 filename = os.path.join(self.root_path, 'static', filename)392 if not os.path.isfile(filename):393 raise NotFound()394 return send_file(filename, conditional=True)395396 def test_client(self):397 """Creates a test client for this application. For information398 about unit testing head over to :ref:`testing`.399
446 unmodified lines
modified:flask/helpers.py+2 added-1 removed
248 unmodified lines
249 else:250 file = filename_or_fp251 filename = getattr(file, 'name', None)252 if filename is not None:253 if not os.path.isabs(filename):253 filename = os.path.join(current_app.root_path, filename)254 filename = os.path.join(current_app.root_path, filename)255 if mimetype is None and (filename or attachment_filename):256 mimetype = mimetypes.guess_type(filename or attachment_filename)[0]257 if mimetype is None:258 mimetype = 'application/octet-stream'
113 unmodified lines