Skip to content
Myr

Merged in changes from master by hand

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 81148db · Browse files · 3 files+37 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

3 files+37 added−12 removed

  • tests:+2 added−3 removed
  • other:+35 added−9 removed

3 files+37 added−12 removed

modified:flask/__init__.py+1 added-1 removed
16 unmodified lines
1718from 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_attribute21 get_template_attribute, json22from flask.globals import current_app, g, request, session, _request_ctx_stack23from flask.module import Module
modified:flask/app.py+34 added-8 removed
18 unmodified lines
19# a lock used for logger initialization20_logger_lock = Lock()212223def _select_autoescape(filename):24 """Returns `True` if autoescaping should be active for the given25 template name.26 """27 if filename is None:28 return False29 return filename.endswith(('.html', '.htm', '.xml', '.xhtml'))303132class Flask(_PackageBoundObject):33 """The flask object implements a WSGI application and acts as the central34 object. It is passed the name of the module or package of the35 application. Once it is created it will act as a central registry for
124 unmodified lines
160 )161162 #: Options that are passed directly to the Jinja2 environment.163 jinja_options = ImmutableDict(155 autoescape=True,164 autoescape=_select_autoescape,165 extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']166 )167168 #: Default configuration parameters.
89 unmodified lines
258259 #: The Jinja2 environment. It is created from the260 #: :attr:`jinja_options` and the loader that is returned261 #: by the :meth:`create_jinja_loader` function.253 self.jinja_env = Environment(loader=self.create_jinja_loader(),254 **self.jinja_options)255 self.jinja_env.globals.update(256 url_for=url_for,257 get_flashed_messages=get_flashed_messages258 )259 self.jinja_env.filters['tojson'] = _tojson_filter262 self.jinja_env = self.create_jinja_environment()263 self.init_jinja_globals()264265 @property266 def logger(self):267 """A :class:`logging.Logger` object for this application. The
28 unmodified lines
296 logger.addHandler(handler)297 self._logger = logger298 return logger299300 def create_jinja_environment(self):301 """Creates the Jinja2 environment based on :attr:`jinja_options`302 and :meth:`create_jinja_loader`.303304 .. versionadded:: 0.5305 """306 return Environment(loader=self.create_jinja_loader(),307 **self.jinja_options)308309 def create_jinja_loader(self):310 """Creates the Jinja loader. By default just a package loader for311 the configured package is returned that looks up templates in the312 `templates` folder. To add other loaders it's possible to
2 unmodified lines
315 if get_pkg_resources() is None:316 return FileSystemLoader(os.path.join(self.root_path, 'templates'))317 return PackageLoader(self.import_name)318319 def init_jinja_globals(self):320 """Callde directly after the environment was created to inject321 some defaults (like `url_for`, `get_flashed_messages` and the322 `tojson` filter.323324 .. versionadded:: 0.5325 """326 self.jinja_env.globals.update(327 url_for=url_for,328 get_flashed_messages=get_flashed_messages329 )330 self.jinja_env.filters['tojson'] = _tojson_filter331332 def update_template_context(self, context):333 """Update the template context with some commonly used variables.334 This injects request, session and g into the template context.335
489 unmodified lines
modified:tests/flask_tests.py+2 added-3 removed
19 unmodified lines
20from contextlib import contextmanager21from datetime import datetime22from werkzeug import parse_date, parse_options_header23from cStringIO import StringIO24from flask.helpers import json2425example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')26sys.path.append(os.path.join(example_path, 'flaskr'))27sys.path.append(os.path.join(example_path, 'minitwit'))
379 unmodified lines
407 c = app.test_client()408 for url in '/kw', '/dict':409 rv = c.get(url)410 assert rv.mimetype == 'application/json'412 assert json.loads(rv.data) == d411 assert flask.json.loads(rv.data) == d412413 def test_json_attr(self):414 app = flask.Flask(__name__)415 @app.route('/add', methods=['POST'])416 def add():417 return unicode(flask.request.json['a'] + flask.request.json['b'])418 c = app.test_client()420 rv = c.post('/add', data=json.dumps({'a': 1, 'b': 2}),419 rv = c.post('/add', data=flask.json.dumps({'a': 1, 'b': 2}),420 content_type='application/json')421 assert rv.data == '3'422423 def test_template_escaping(self):
474 unmodified lines