Skip to content
Myr

Flask now runs without the presence of pkg_resources as well.

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 ca520fb · Browse files · 1 file+24 added−3 removed
This commit

State

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

Diff stats

1 file+24 added−3 removed

  • other:+24 added−3 removed

1 file+24 added−3 removed

modified:flask.py+24 added-3 removed
9 unmodified lines
10 :license: BSD, see LICENSE for more details.11"""12import os13import sys14import pkg_resources1415from threading import local16from contextlib import contextmanager17from jinja2 import Environment, PackageLoader17from jinja2 import Environment, PackageLoader, FileSystemLoader18from werkzeug import Request as RequestBase, Response as ResponseBase, \19 LocalStack, LocalProxy, create_environ, cached_property, \20 SharedDataMiddleware21from werkzeug.routing import Map, Rule
4 unmodified lines
26# in the module but are exported as public interface.27from werkzeug import abort, redirect28from jinja2 import Markup, escape2930# use pkg_resource if that works, otherwise fall back to cwd. The31# current working directory is generally not reliable with the notable32# exception of google appengine.33try:34 import pkg_resources35 pkg_resources.resource_stream36except (ImportError, AttributeError):37 pkg_resources = None383940class Request(RequestBase):41 """The request object used by default in flask. Remembers the42 matched endpoint and view arguments.43
166 unmodified lines
210 #: the name of the package or module. Do not change this once211 #: it was set by the constructor.212 self.package_name = package_name213214 #: where is the app root located?215 self.root_path = os.path.abspath(os.path.dirname(216 sys.modules[self.package_name].__file__))217218 #: a dictionary of all view functions registered. The keys will219 #: be function names which are also used to generate URLs and220 #: the values are the function objects themselves.221 #: to register a view function, use the :meth:`route` decorator.
32 unmodified lines
254255 if self.static_path is not None:256 self.url_map.add(Rule(self.static_path + '/<filename>',257 build_only=True, endpoint='static'))258 if pkg_resources is not None:259 target = (self.package_name, 'static')260 else:261 target = os.path.join(self.root_path, 'static')262 self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {246 self.static_path: (self.package_name, 'static')263 self.static_path: target264 })265266 #: the Jinja2 environment. It is created from the267 #: :attr:`jinja_options` and the loader that is returned
10 unmodified lines
278 the configured package is returned that looks up templates in the279 `templates` folder. To add other loaders it's possible to280 override this method.281 """282 if pkg_resources is None:283 return FileSystemLoader(os.path.join(self.root_path, 'templates'))284 return PackageLoader(self.package_name)285286 def update_template_context(self, context):287 """Update the template context with some commonly used variables.
53 unmodified lines
341342 :param resource: the name of the resource. To access resources within343 subfolders use forward slashes as separator.344 """345 if pkg_resources is None:346 return open(os.path.join(self.root_path, resource), 'rb')347 return pkg_resources.resource_stream(self.package_name, resource)348349 def open_session(self, request):350 """Creates or opens a new session. Default implementation stores all
300 unmodified lines