Skip to content
Myr

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

9 files+78 added−47 removed

modified:flask/__init__.py+6 added-41 removed
7 unmodified lines
89 :copyright: (c) 2010 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""12from __future__ import with_statement13import os14import sys15import mimetypes16from datetime import datetime, timedelta1218# this is a workaround for appengine. Do not remove this import19import werkzeug2021from itertools import chain22from threading import Lock23from jinja2 import Environment, PackageLoader, FileSystemLoader24from werkzeug import Request as RequestBase, Response as ResponseBase, \25 LocalStack, LocalProxy, create_environ, SharedDataMiddleware, \26 ImmutableDict, cached_property, wrap_file, Headers, \27 import_string28from werkzeug.routing import Map, Rule29from werkzeug.exceptions import HTTPException, InternalServerError30from werkzeug.contrib.securecookie import SecureCookie31323313# utilities we import from Werkzeug and Jinja2 that are unused14# in the module but are exported as public interface.15from werkzeug import abort, redirect16from jinja2 import Markup, escape1739# 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.42try:43 import pkg_resources44 pkg_resources.resource_stream45except (ImportError, AttributeError):46 pkg_resources = None4748# a lock used for logger initialization49_logger_lock = Lock()50515253# context locals54_request_ctx_stack = LocalStack()55current_app = LocalProxy(lambda: _request_ctx_stack.top.app)56request = LocalProxy(lambda: _request_ctx_stack.top.request)57session = LocalProxy(lambda: _request_ctx_stack.top.session)58g = LocalProxy(lambda: _request_ctx_stack.top.g)18from flask.app import Flask19from 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_attribute22from flask.globals import current_app, g, request, session, _request_ctx_stack23from flask.module import Module
modified:flask/app.py+22 added-2 removed
1from threading import Lock2from datetime import timedelta, datetime3from itertools import chain45from jinja2 import Environment, PackageLoader, FileSystemLoader6from werkzeug import ImmutableDict, SharedDataMiddleware, create_environ7from werkzeug.routing import Map, Rule8from werkzeug.exceptions import HTTPException, InternalServerError910from flask.helpers import _PackageBoundObject, url_for, get_flashed_messages, \11 _tojson_filter, get_pkg_resources12from flask.wrappers import Request, Response13from flask.conf import ConfigAttribute, Config14from flask.ctx import _default_template_ctx_processor, _RequestContext15from flask.globals import _request_ctx_stack, request16from flask.session import Session, _NullSession17from flask.module import _ModuleSetupState1819# a lock used for logger initialization20_logger_lock = Lock()212223class 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 for
211 unmodified lines
238239 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 lines
298 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)305306 def update_template_context(self, context):
492 unmodified lines
modified:flask/conf.py+4 added
1import os2import sys34from werkzeug import import_string567class ConfigAttribute(object):8 """Makes an attribute forward to the config"""910 def __init__(self, name):
129 unmodified lines
modified:flask/ctx.py+5 added
1from werkzeug.exceptions import HTTPException23from flask.wrappers import _RequestGlobals4from flask.globals import _request_ctx_stack5from flask.session import _NullSession678class _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 the
51 unmodified lines
added:flask/globals.py+8 added
1from werkzeug import LocalStack, LocalProxy23# context locals4_request_ctx_stack = LocalStack()5current_app = LocalProxy(lambda: _request_ctx_stack.top.app)6request = LocalProxy(lambda: _request_ctx_stack.top.request)7session = LocalProxy(lambda: _request_ctx_stack.top.session)8g = LocalProxy(lambda: _request_ctx_stack.top.g)
modified:flask/helpers.py+22 added-4 removed
1import os2import sys3import mimetypes45# try to load the best simplejson implementation available. If JSON6# is not installed, we add a failing class.7json_available = True8try:
3 unmodified lines
12 import json13 except ImportError:14 json_available = False15 16from werkzeug import Headers, wrap_file1718from flask.globals import session, _request_ctx_stack, current_app, request19from flask.wrappers import Response2021 22def _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 lines
66 _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 70def 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_resources818283def url_for(endpoint, **values):84 """Generates a URL to the given endpoint with the method provided.
99 unmodified lines
184 return [x[1] for x in flashes]185 return flashes186187167188def 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 will
89 unmodified lines
281 current_app.update_template_context(context)282 return current_app.jinja_env.from_string(source).render(context)283284265285def _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()291292274293class _PackageBoundObject(object):294295 def __init__(self, import_name):296 #: The name of the package or module. Do not change this once
24 unmodified lines
321322 :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
1from flask.helpers import _PackageBoundObject234class _ModuleSetupState(object):5
147 unmodified lines
modified:flask/session.py+3 added
1from werkzeug.contrib.securecookie import SecureCookie234class Session(SecureCookie):5 """Expands the session with support for switching between permanent6 and non-permanent sessions.7 """
24 unmodified lines
modified:flask/wrappers.py+7 added
1from werkzeug import Request as RequestBase, Response as ResponseBase, \2 cached_property34from helpers import json567class Request(RequestBase):8 """The request object used by default in flask. Remembers the9 matched endpoint and view arguments.10
29 unmodified lines
40 """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