Skip to content
Myr

Merge branch 'master' into module-support

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

Conflicts: CHANGES docs/_themes tests/flask_tests.py

authored by Armin Ronacher · committed by Armin Ronacher · parents de909b3, f80e1d3 · Browse files · 9 files+176 added−355 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+176 added−355 removed

  • tests:+85 added−2 removed
  • other:+91 added−353 removed

9 files+176 added−355 removed

added:docs/_themesnot shown

Its text is not shown, added.

deleted:docs/_themes/flasky/static/flasky.css_t-344 removed
1/*2 * flasky.css_t3 * ~~~~~~~~~~~~4 *5 * Sphinx stylesheet -- flasky theme based on nature theme.6 *7 * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS.8 * :license: BSD, see LICENSE for details.9 *10 */11 12@import url("basic.css");13 14/* -- page layout ----------------------------------------------------------- */15 16body {17 font-family: 'Georgia', serif;18 font-size: 17px;19 background-color: #ddd;20 color: #000;21 margin: 0;22 padding: 0;23}2425div.document {26 background: #fafafa;27}2829div.documentwrapper {30 float: left;31 width: 100%;32}3334div.bodywrapper {35 margin: 0 0 0 230px;36}3738hr {39 border: 1px solid #B1B4B6;40}41 42div.body {43 background-color: #ffffff;44 color: #3E4349;45 padding: 0 30px 30px 30px;46 min-height: 34em;47}4849img.floatingflask {50 padding: 0 0 10px 10px;51 float: right;52}53 54div.footer {55 position: absolute;56 right: 0;57 margin-top: -70px;58 text-align: right;59 color: #888;60 padding: 10px;61 font-size: 14px;62}63 64div.footer a {65 color: #888;66 text-decoration: underline;67}68 69div.related {70 line-height: 32px;71 color: #888;72}7374div.related ul {75 padding: 0 0 0 10px;76}77 78div.related a {79 color: #444;80}81 82div.sphinxsidebar {83 font-size: 14px;84 line-height: 1.5;85}8687div.sphinxsidebarwrapper {88 padding: 0 20px;89}9091div.sphinxsidebarwrapper p.logo {92 padding: 20px 0 10px 0;93 margin: 0;94 text-align: center;95}96 97div.sphinxsidebar h3,98div.sphinxsidebar h4 {99 font-family: 'Garamond', 'Georgia', serif;100 color: #222;101 font-size: 24px;102 font-weight: normal;103 margin: 20px 0 5px 0;104 padding: 0;105}106107div.sphinxsidebar h4 {108 font-size: 20px;109}110 111div.sphinxsidebar h3 a {112 color: #444;113}114 115div.sphinxsidebar p {116 color: #555;117 margin: 10px 0;118}119 120div.sphinxsidebar ul {121 margin: 10px 0;122 padding: 0;123 color: #000;124}125 126div.sphinxsidebar a {127 color: #444;128 text-decoration: none;129}130131div.sphinxsidebar a:hover {132 text-decoration: underline;133}134 135div.sphinxsidebar input {136 border: 1px solid #ccc;137 font-family: 'Georgia', serif;138 font-size: 1em;139}140 141/* -- body styles ----------------------------------------------------------- */142 143a {144 color: #004B6B;145 text-decoration: underline;146}147 148a:hover {149 color: #6D4100;150 text-decoration: underline;151}152153div.body {154 padding-bottom: 40px; /* saved for footer */155}156 157div.body h1,158div.body h2,159div.body h3,160div.body h4,161div.body h5,162div.body h6 {163 font-family: 'Garamond', 'Georgia', serif;164 font-weight: normal;165 margin: 30px 0px 10px 0px;166 padding: 0;167}168 169div.body h1 { margin-top: 0; padding-top: 20px; font-size: 240%; }170div.body h2 { font-size: 180%; }171div.body h3 { font-size: 150%; }172div.body h4 { font-size: 130%; }173div.body h5 { font-size: 100%; }174div.body h6 { font-size: 100%; }175 176a.headerlink {177 color: white;178 padding: 0 4px;179 text-decoration: none;180}181 182a.headerlink:hover {183 color: #444;184 background: #eaeaea;185}186 187div.body p, div.body dd, div.body li {188 line-height: 1.4em;189}190191div.admonition {192 background: #fafafa;193 margin: 20px -30px;194 padding: 10px 30px;195 border-top: 1px solid #ccc;196 border-bottom: 1px solid #ccc;197}198199div.admonition p.admonition-title {200 font-family: 'Garamond', 'Georgia', serif;201 font-weight: normal;202 font-size: 24px;203 margin: 0 0 10px 0;204 padding: 0;205 line-height: 1;206}207208div.admonition p.last {209 margin-bottom: 0;210}211212div.highlight{213 background-color: white;214}215216dt:target, .highlight {217 background: #FAF3E8;218}219220div.note {221 background-color: #eee;222 border: 1px solid #ccc;223}224 225div.seealso {226 background-color: #ffc;227 border: 1px solid #ff6;228}229 230div.topic {231 background-color: #eee;232}233 234div.warning {235 background-color: #ffe4e4;236 border: 1px solid #f66;237}238 239p.admonition-title {240 display: inline;241}242 243p.admonition-title:after {244 content: ":";245}246247pre, tt {248 font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;249 font-size: 0.9em;250}251252img.screenshot {253}254255tt.descname, tt.descclassname {256 font-size: 0.95em;257}258259tt.descname {260 padding-right: 0.08em;261}262263img.screenshot {264 -moz-box-shadow: 2px 2px 4px #eee;265 -webkit-box-shadow: 2px 2px 4px #eee;266 box-shadow: 2px 2px 4px #eee;267}268269table.docutils {270 border: 1px solid #888;271 -moz-box-shadow: 2px 2px 4px #eee;272 -webkit-box-shadow: 2px 2px 4px #eee;273 box-shadow: 2px 2px 4px #eee;274}275276table.docutils td, table.docutils th {277 border: 1px solid #888;278 padding: 0.25em 0.7em;279}280281table.field-list, table.footnote {282 border: none;283 -moz-box-shadow: none;284 -webkit-box-shadow: none;285 box-shadow: none;286}287288table.footnote {289 margin: 15px 0;290 width: 100%;291 border: 1px solid #eee;292}293294table.field-list th {295 padding: 0 0.8em 0 0;296}297298table.field-list td {299 padding: 0;300}301302table.footnote td {303 padding: 0.5em;304}305306dl {307 margin: 0;308 padding: 0;309}310311dl dd {312 margin-left: 30px;313}314 315pre {316 background: #eee;317 padding: 7px 30px;318 margin: 15px -30px;319 line-height: 1.3em;320}321322dl pre {323 margin-left: -60px;324 padding-left: 60px;325}326327dl dl pre {328 margin-left: -90px;329 padding-left: 90px;330}331 332tt {333 background-color: #ecf0f3;334 color: #222;335 /* padding: 1px 2px; */336}337338tt.xref, a tt {339 background-color: #FBFBFB;340}341342a:hover tt {343 background: #EEE;344}
deleted:docs/_themes/flasky/theme.conf-3 removed
1[theme]2inherit = basic3stylesheet = flasky.css
modified:docs/api.rst+2 added
220 unmodified lines
221 :param code: the HTTP error code.222223.. autofunction:: redirect224225.. autofunction:: send_file226227.. autofunction:: escape228229.. autoclass:: Markup230 :members: escape, unescape, striptags
50 unmodified lines
modified:docs/conf.py+4 added-5 removed
14 unmodified lines
1516# If extensions (or modules to document with autodoc) are in another directory,17# add these directories to sys.path here. If the directory is relative to the18# documentation root, use os.path.abspath to make it absolute, like shown here.19sys.path.append(os.path.abspath('.'))19sys.path.append(os.path.abspath('_themes'))2021# -- General configuration -----------------------------------------------------2223# If your documentation needs a minimal Sphinx version, state it here.
54 unmodified lines
78# If true, sectionauthor and moduleauthor directives will be shown in the79# output. They are ignored by default.80#show_authors = False8182# The name of the Pygments (syntax highlighting) style to use.83pygments_style = 'flaskext.FlaskyStyle'8482# A list of ignored prefixes for module index sorting.83#modindex_common_prefix = []848586# -- Options for HTML output ---------------------------------------------------8788# The theme to use for HTML and HTML Help pages. Major themes that come with89# Sphinx are currently 'default' and 'sphinxdoc'.93html_theme = 'flasky'90html_theme = 'flask'9192# Theme options are theme-specific and customize the look and feel of a theme93# further. For a list of options available for each theme, see the94# documentation.
138 unmodified lines
233 'http://werkzeug.pocoo.org/documentation/dev/': None,234 'http://www.sqlalchemy.org/docs/': None,235 'http://wtforms.simplecodes.com/docs/0.5/': None236}237238pygments_style = 'flask_theme_support.FlaskyStyle'
modified:tests/flask_tests.py+85 added-2 removed
15 unmodified lines
16import flask17import unittest18import tempfile19from datetime import datetime20from werkzeug import parse_date20from werkzeug import parse_date, parse_options_header21from cStringIO import StringIO222324example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')25sys.path.append(os.path.join(example_path, 'flaskr'))
448 unmodified lines
474 app.register_module(admin, url_prefix='/admin')475 assert app.test_client().get('/admin/').data == '42'476477478class SendfileTestCase(unittest.TestCase):479480 def test_send_file_regular(self):481 app = flask.Flask(__name__)482 with app.test_request_context():483 rv = flask.send_file('static/index.html')484 assert rv.direct_passthrough485 assert rv.mimetype == 'text/html'486 with app.open_resource('static/index.html') as f:487 assert rv.data == f.read()488489 def test_send_file_xsendfile(self):490 app = flask.Flask(__name__)491 app.use_x_sendfile = True492 with app.test_request_context():493 rv = flask.send_file('static/index.html')494 assert rv.direct_passthrough495 assert 'x-sendfile' in rv.headers496 assert rv.headers['x-sendfile'] == \497 os.path.join(app.root_path, 'static/index.html')498 assert rv.mimetype == 'text/html'499500 def test_send_file_object(self):501 app = flask.Flask(__name__)502 with app.test_request_context():503 f = open(os.path.join(app.root_path, 'static/index.html'))504 rv = flask.send_file(f)505 with app.open_resource('static/index.html') as f:506 assert rv.data == f.read()507 assert rv.mimetype == 'text/html'508509 app.use_x_sendfile = True510 with app.test_request_context():511 f = open(os.path.join(app.root_path, 'static/index.html'))512 rv = flask.send_file(f)513 assert rv.mimetype == 'text/html'514 assert 'x-sendfile' in rv.headers515 assert rv.headers['x-sendfile'] == \516 os.path.join(app.root_path, 'static/index.html')517518 app.use_x_sendfile = False519 with app.test_request_context():520 f = StringIO('Test')521 rv = flask.send_file(f)522 assert rv.data == 'Test'523 assert rv.mimetype == 'application/octet-stream'524 f = StringIO('Test')525 rv = flask.send_file(f, mimetype='text/plain')526 assert rv.data == 'Test'527 assert rv.mimetype == 'text/plain'528529 app.use_x_sendfile = True530 with app.test_request_context():531 f = StringIO('Test')532 rv = flask.send_file(f)533 assert 'x-sendfile' not in rv.headers534535 def test_attachment(self):536 app = flask.Flask(__name__)537 with app.test_request_context():538 f = open(os.path.join(app.root_path, 'static/index.html'))539 rv = flask.send_file(f, as_attachment=True)540 value, options = parse_options_header(rv.headers['Content-Disposition'])541 assert value == 'attachment'542543 with app.test_request_context():544 assert options['filename'] == 'index.html'545 rv = flask.send_file('static/index.html', as_attachment=True)546 value, options = parse_options_header(rv.headers['Content-Disposition'])547 assert value == 'attachment'548 assert options['filename'] == 'index.html'549550 with app.test_request_context():551 rv = flask.send_file(StringIO('Test'), as_attachment=True,552 attachment_filename='index.txt')553 assert rv.mimetype == 'text/plain'554 value, options = parse_options_header(rv.headers['Content-Disposition'])555 assert value == 'attachment'556 assert options['filename'] == 'index.txt'557558559def suite():560 from minitwit_tests import MiniTwitTestCase561 from flaskr_tests import FlaskrTestCase562 suite = unittest.TestSuite()563 suite.addTest(unittest.makeSuite(ContextTestCase))564 suite.addTest(unittest.makeSuite(BasicFunctionalityTestCase))565 suite.addTest(unittest.makeSuite(TemplatingTestCase))566 suite.addTest(unittest.makeSuite(SendfileTestCase))567 suite.addTest(unittest.makeSuite(ModuleTestCase))568 if flask.json_available:569 suite.addTest(unittest.makeSuite(JSONTestCase))570 suite.addTest(unittest.makeSuite(MiniTwitTestCase))571 suite.addTest(unittest.makeSuite(FlaskrTestCase))488 suite.addTest(unittest.makeSuite(ModuleTestCase))572 return suite573574575if __name__ == '__main__':
1 unmodified line
added:.gitmodules+3 added
1[submodule "docs/_themes"]2 path = docs/_themes3 url = git://github.com/mitsuhiko/flask-sphinx-themes.git
modified:CHANGES+1 added
13 unmodified lines
14- :meth:`~flask.Flask.add_url_rule` can now also register a15 view function.16- server listens on 127.0.0.1 by default now to fix issues with chrome.17- added external URL support.18- added support for :func:`~flask.send_file`19- module support and internal request handling refactoring20 to better support pluggable applications.2122Version 0.1
3 unmodified lines
modified:flask.py+81 added-1 removed
10 unmodified lines
11"""12from __future__ import with_statement13import os14import sys15import mimetypes16from datetime import datetime, timedelta1718from itertools import chain19from jinja2 import Environment, PackageLoader, FileSystemLoader20from werkzeug import Request as RequestBase, Response as ResponseBase, \21 LocalStack, LocalProxy, create_environ, SharedDataMiddleware, \21 ImmutableDict, cached_property22 ImmutableDict, cached_property, wrap_file, Headers23from werkzeug.routing import Map, Rule24from werkzeug.exceptions import HTTPException25from werkzeug.contrib.securecookie import SecureCookie26
241 unmodified lines
268 return current_app.response_class(json.dumps(dict(*args, **kwargs),269 indent=None if request.is_xhr else 2), mimetype='application/json')270271272def send_file(filename_or_fp, mimetype=None, as_attachment=False,273 attachment_filename=None):274 """Sends the contents of a file to the client. This will use the275 most efficient method available and configured. By default it will276 try to use the WSGI server's file_wrapper support. Alternatively277 you can set the application's :attr:`~Flask.use_x_sendfile` attribute278 to ``True`` to directly emit an `X-Sendfile` header. This however279 requires support of the underlying webserver for `X-Sendfile`.280281 By default it will try to guess the mimetype for you, but you can282 also explicitly provide one. For extra security you probably want283 to sent certain files as attachment (HTML for instance).284285 Please never pass filenames to this function from user sources without286 checking them first. Something like this is usually sufficient to287 avoid security problems::288289 if '..' in filename or filename.startswith('/'):290 abort(404)291292 .. versionadded:: 0.2293294 :param filename_or_fp: the filename of the file to send. This is295 relative to the :attr:`~Flask.root_path` if a296 relative path is specified.297 Alternatively a file object might be provided298 in which case `X-Sendfile` might not work and299 fall back to the traditional method.300 :param mimetype: the mimetype of the file if provided, otherwise301 auto detection happens.302 :param as_attachment: set to `True` if you want to send this file with303 a ``Content-Disposition: attachment`` header.304 :param attachment_filename: the filename for the attachment if it305 differs from the file's filename.306 """307 if isinstance(filename_or_fp, basestring):308 filename = filename_or_fp309 file = None310 else:311 file = filename_or_fp312 filename = getattr(file, 'name', None)313 if filename is not None:314 filename = os.path.join(current_app.root_path, filename)315 if mimetype is None and (filename or attachment_filename):316 mimetype = mimetypes.guess_type(filename or attachment_filename)[0]317 if mimetype is None:318 mimetype = 'application/octet-stream'319320 headers = Headers()321 if as_attachment:322 if attachment_filename is None:323 if filename is None:324 raise TypeError('filename unavailable, required for '325 'sending as attachment')326 attachment_filename = os.path.basename(filename)327 headers.add('Content-Disposition', 'attachment',328 filename=attachment_filename)329330 if current_app.use_x_sendfile and filename:331 if file is not None:332 file.close()333 headers['X-Sendfile'] = filename334 data = None335 else:336 if file is None:337 file = open(filename, 'rb')338 data = wrap_file(request.environ, file)339340 return Response(data, mimetype=mimetype, headers=headers,341 direct_passthrough=True)342343344def render_template(template_name, **context):345 """Renders a template from the template folder with the given346 context.347
278 unmodified lines
626 #: date of a permanent session. The default is 31 days which makes a627 #: permanent session survive for roughly one month.628 permanent_session_lifetime = timedelta(days=31)629630 #: Enable this if you want to use the X-Sendfile feature. Keep in631 #: mind that the server has to support this. This only affects files632 #: sent with the :func:`send_file` method.633 #:634 #: .. versionadded:: 0.2635 use_x_sendfile = False636637 #: options that are passed directly to the Jinja2 environment638 jinja_options = ImmutableDict(639 autoescape=True,640 extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']
497 unmodified lines