working import layout for module
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Justin Quick · committed by Justin Quick · parent d0dc89e · Browse files · 9 files·+78 added−47 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+78 added−47 removed
- other:+78 added−47 removed
Provenance
- Commit
c4f64c1- Tree
0ec0626- Author
Justin Quick <justquick@gmail.com>- Committer
Justin Quick <justquick@gmail.com>- Parent
d0dc89e
9 files changed+78 added−47 removed
modified:flask/__init__.py+6 added-41 removed
7 unmodified lines8 9 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11 """12-from __future__ import with_statement13-import os14-import sys15-import mimetypes16-from datetime import datetime, timedelta12 18-# this is a workaround for appengine. Do not remove this import19-import werkzeug20-21-from itertools import chain22-from threading import Lock23-from jinja2 import Environment, PackageLoader, FileSystemLoader24-from werkzeug import Request as RequestBase, Response as ResponseBase, \25- LocalStack, LocalProxy, create_environ, SharedDataMiddleware, \26- ImmutableDict, cached_property, wrap_file, Headers, \27- import_string28-from werkzeug.routing import Map, Rule29-from werkzeug.exceptions import HTTPException, InternalServerError30-from werkzeug.contrib.securecookie import SecureCookie31-32-33-13 # utilities we import from Werkzeug and Jinja2 that are unused14 # in the module but are exported as public interface.15 from werkzeug import abort, redirect16 from jinja2 import Markup, escape17 39-# use pkg_resource if that works, otherwise fall back to cwd. The40-# current working directory is generally not reliable with the notable41-# exception of google appengine.42-try:43- import pkg_resources44- pkg_resources.resource_stream45-except (ImportError, AttributeError):46- pkg_resources = None47-48-# a lock used for logger initialization49-_logger_lock = Lock()50-51-52-53-# context locals54-_request_ctx_stack = LocalStack()55-current_app = LocalProxy(lambda: _request_ctx_stack.top.app)56-request = LocalProxy(lambda: _request_ctx_stack.top.request)57-session = LocalProxy(lambda: _request_ctx_stack.top.session)58-g = LocalProxy(lambda: _request_ctx_stack.top.g)18+from flask.app import Flask19+from flask.helpers import url_for, jsonify, json_available, flash, send_file, \20+ get_flashed_messages, render_template, render_template, render_template_string, \21+ get_template_attribute22+from flask.globals import current_app, g, request, session, _request_ctx_stack23+from flask.module import Modulemodified:flask/app.py+22 added-2 removed
1+from threading import Lock2+from datetime import timedelta, datetime3+from itertools import chain4 5+from jinja2 import Environment, PackageLoader, FileSystemLoader6+from werkzeug import ImmutableDict, SharedDataMiddleware, create_environ7+from werkzeug.routing import Map, Rule8+from werkzeug.exceptions import HTTPException, InternalServerError9 10+from flask.helpers import _PackageBoundObject, url_for, get_flashed_messages, \11+ _tojson_filter, get_pkg_resources12+from flask.wrappers import Request, Response13+from flask.conf import ConfigAttribute, Config14+from flask.ctx import _default_template_ctx_processor, _RequestContext15+from flask.globals import _request_ctx_stack, request16+from flask.session import Session, _NullSession17+from flask.module import _ModuleSetupState18+19+# a lock used for logger initialization20+_logger_lock = Lock()21+22+23 class Flask(_PackageBoundObject):24 """The flask object implements a WSGI application and acts as the central25 object. It is passed the name of the module or package of the26 application. Once it is created it will act as a central registry for211 unmodified lines238 239 if self.static_path is not None:240 self.add_url_rule(self.static_path + '/<filename>',241 build_only=True, endpoint='static')222- if pkg_resources is not None:242+ if get_pkg_resources() is not None:243 target = (self.import_name, 'static')244 else:245 target = os.path.join(self.root_path, 'static')246 self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {51 unmodified lines298 the configured package is returned that looks up templates in the299 `templates` folder. To add other loaders it's possible to300 override this method.301 """282- if pkg_resources is None:302+ if get_pkg_resources() is None:303 return FileSystemLoader(os.path.join(self.root_path, 'templates'))304 return PackageLoader(self.import_name)305 306 def update_template_context(self, context):492 unmodified linesmodified:flask/conf.py+4 added
1+import os2+import sys3 4+from werkzeug import import_string5 6+7 class ConfigAttribute(object):8 """Makes an attribute forward to the config"""9 10 def __init__(self, name):129 unmodified linesmodified:flask/ctx.py+5 added
1+from werkzeug.exceptions import HTTPException2 3+from flask.wrappers import _RequestGlobals4+from flask.globals import _request_ctx_stack5+from flask.session import _NullSession6 7+8 class _RequestContext(object):9 """The request context contains all request relevant information. It is10 created at the beginning of the request and pushed to the11 `_request_ctx_stack` and removed at the end of it. It will create the51 unmodified linesadded:flask/globals.py+8 added
1+from werkzeug import LocalStack, LocalProxy2+3+# context locals4+_request_ctx_stack = LocalStack()5+current_app = LocalProxy(lambda: _request_ctx_stack.top.app)6+request = LocalProxy(lambda: _request_ctx_stack.top.request)7+session = LocalProxy(lambda: _request_ctx_stack.top.session)8+g = LocalProxy(lambda: _request_ctx_stack.top.g)modified:flask/helpers.py+22 added-4 removed
1+import os2+import sys3+import mimetypes4+5 # try to load the best simplejson implementation available. If JSON6 # is not installed, we add a failing class.7 json_available = True8 try:3 unmodified lines12 import json13 except ImportError:14 json_available = False15 16+from werkzeug import Headers, wrap_file17+18+from flask.globals import session, _request_ctx_stack, current_app, request19+from flask.wrappers import Response20+21+ 22 def _assert_have_json():23 """Helper function that fails if JSON is unavailable."""24 if not json_available:25 raise RuntimeError('simplejson not installed')40 unmodified lines66 _assert_have_json()67 return current_app.response_class(json.dumps(dict(*args, **kwargs),68 indent=None if request.is_xhr else 2), mimetype='application/json')69 70+def get_pkg_resources():71+ """Use pkg_resource if that works, otherwise fall back to cwd. The72+ current working directory is generally not reliable with the notable73+ exception of google appengine.74+ """75+ try:76+ import pkg_resources77+ pkg_resources.resource_stream78+ except (ImportError, AttributeError):79+ return80+ return pkg_resources81 82 83 def url_for(endpoint, **values):84 """Generates a URL to the given endpoint with the method provided.99 unmodified lines184 return [x[1] for x in flashes]185 return flashes186 187 167-188 def send_file(filename_or_fp, mimetype=None, as_attachment=False,189 attachment_filename=None):190 """Sends the contents of a file to the client. This will use the191 most efficient method available and configured. By default it will89 unmodified lines281 current_app.update_template_context(context)282 return current_app.jinja_env.from_string(source).render(context)283 284 265-285 def _get_package_path(name):286 """Returns the path to a package or cwd if that cannot be found."""287 try:288 return os.path.abspath(os.path.dirname(sys.modules[name].__file__))289 except (KeyError, AttributeError):290 return os.getcwd()291 292 274-293 class _PackageBoundObject(object):294 295 def __init__(self, import_name):296 #: The name of the package or module. Do not change this once24 unmodified lines321 322 :param resource: the name of the resource. To access resources within323 subfolders use forward slashes as separator.324 """325+ pkg_resources = get_pkg_resources()326 if pkg_resources is None:327 return open(os.path.join(self.root_path, resource), 'rb')328 return pkg_resources.resource_stream(self.import_name, resource)310-modified:flask/module.py+1 added
1+from flask.helpers import _PackageBoundObject2 3 4 class _ModuleSetupState(object):5 147 unmodified linesmodified:flask/session.py+3 added
1+from werkzeug.contrib.securecookie import SecureCookie2+3+4 class Session(SecureCookie):5 """Expands the session with support for switching between permanent6 and non-permanent sessions.7 """24 unmodified linesmodified:flask/wrappers.py+7 added
1+from werkzeug import Request as RequestBase, Response as ResponseBase, \2+ cached_property3+4+from helpers import json5+6+7 class Request(RequestBase):8 """The request object used by default in flask. Remembers the9 matched endpoint and view arguments.10 29 unmodified lines40 """If the mimetype is `application/json` this will contain the41 parsed JSON data.42 """43 if __debug__:44+ from flask.helpers import _assert_have_json45 _assert_have_json()46 if self.mimetype == 'application/json':47 return json.loads(self.data)48 16 unmodified lines