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
Provenance
- Commit
9fa4f94- Tree
bfb7278- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
de909b3- Parent 2
f80e1d3
9 files changed+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- 16-body {17- font-family: 'Georgia', serif;18- font-size: 17px;19- background-color: #ddd;20- color: #000;21- margin: 0;22- padding: 0;23-}24-25-div.document {26- background: #fafafa;27-}28-29-div.documentwrapper {30- float: left;31- width: 100%;32-}33-34-div.bodywrapper {35- margin: 0 0 0 230px;36-}37-38-hr {39- border: 1px solid #B1B4B6;40-}41- 42-div.body {43- background-color: #ffffff;44- color: #3E4349;45- padding: 0 30px 30px 30px;46- min-height: 34em;47-}48-49-img.floatingflask {50- padding: 0 0 10px 10px;51- float: right;52-}53- 54-div.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- 64-div.footer a {65- color: #888;66- text-decoration: underline;67-}68- 69-div.related {70- line-height: 32px;71- color: #888;72-}73-74-div.related ul {75- padding: 0 0 0 10px;76-}77- 78-div.related a {79- color: #444;80-}81- 82-div.sphinxsidebar {83- font-size: 14px;84- line-height: 1.5;85-}86-87-div.sphinxsidebarwrapper {88- padding: 0 20px;89-}90-91-div.sphinxsidebarwrapper p.logo {92- padding: 20px 0 10px 0;93- margin: 0;94- text-align: center;95-}96- 97-div.sphinxsidebar h3,98-div.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-}106-107-div.sphinxsidebar h4 {108- font-size: 20px;109-}110- 111-div.sphinxsidebar h3 a {112- color: #444;113-}114- 115-div.sphinxsidebar p {116- color: #555;117- margin: 10px 0;118-}119- 120-div.sphinxsidebar ul {121- margin: 10px 0;122- padding: 0;123- color: #000;124-}125- 126-div.sphinxsidebar a {127- color: #444;128- text-decoration: none;129-}130-131-div.sphinxsidebar a:hover {132- text-decoration: underline;133-}134- 135-div.sphinxsidebar input {136- border: 1px solid #ccc;137- font-family: 'Georgia', serif;138- font-size: 1em;139-}140- 141-/* -- body styles ----------------------------------------------------------- */142- 143-a {144- color: #004B6B;145- text-decoration: underline;146-}147- 148-a:hover {149- color: #6D4100;150- text-decoration: underline;151-}152-153-div.body {154- padding-bottom: 40px; /* saved for footer */155-}156- 157-div.body h1,158-div.body h2,159-div.body h3,160-div.body h4,161-div.body h5,162-div.body h6 {163- font-family: 'Garamond', 'Georgia', serif;164- font-weight: normal;165- margin: 30px 0px 10px 0px;166- padding: 0;167-}168- 169-div.body h1 { margin-top: 0; padding-top: 20px; font-size: 240%; }170-div.body h2 { font-size: 180%; }171-div.body h3 { font-size: 150%; }172-div.body h4 { font-size: 130%; }173-div.body h5 { font-size: 100%; }174-div.body h6 { font-size: 100%; }175- 176-a.headerlink {177- color: white;178- padding: 0 4px;179- text-decoration: none;180-}181- 182-a.headerlink:hover {183- color: #444;184- background: #eaeaea;185-}186- 187-div.body p, div.body dd, div.body li {188- line-height: 1.4em;189-}190-191-div.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-}198-199-div.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-}207-208-div.admonition p.last {209- margin-bottom: 0;210-}211-212-div.highlight{213- background-color: white;214-}215-216-dt:target, .highlight {217- background: #FAF3E8;218-}219-220-div.note {221- background-color: #eee;222- border: 1px solid #ccc;223-}224- 225-div.seealso {226- background-color: #ffc;227- border: 1px solid #ff6;228-}229- 230-div.topic {231- background-color: #eee;232-}233- 234-div.warning {235- background-color: #ffe4e4;236- border: 1px solid #f66;237-}238- 239-p.admonition-title {240- display: inline;241-}242- 243-p.admonition-title:after {244- content: ":";245-}246-247-pre, tt {248- font-family: 'Consolas', 'Menlo', 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace;249- font-size: 0.9em;250-}251-252-img.screenshot {253-}254-255-tt.descname, tt.descclassname {256- font-size: 0.95em;257-}258-259-tt.descname {260- padding-right: 0.08em;261-}262-263-img.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-}268-269-table.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-}275-276-table.docutils td, table.docutils th {277- border: 1px solid #888;278- padding: 0.25em 0.7em;279-}280-281-table.field-list, table.footnote {282- border: none;283- -moz-box-shadow: none;284- -webkit-box-shadow: none;285- box-shadow: none;286-}287-288-table.footnote {289- margin: 15px 0;290- width: 100%;291- border: 1px solid #eee;292-}293-294-table.field-list th {295- padding: 0 0.8em 0 0;296-}297-298-table.field-list td {299- padding: 0;300-}301-302-table.footnote td {303- padding: 0.5em;304-}305-306-dl {307- margin: 0;308- padding: 0;309-}310-311-dl dd {312- margin-left: 30px;313-}314- 315-pre {316- background: #eee;317- padding: 7px 30px;318- margin: 15px -30px;319- line-height: 1.3em;320-}321-322-dl pre {323- margin-left: -60px;324- padding-left: 60px;325-}326-327-dl dl pre {328- margin-left: -90px;329- padding-left: 90px;330-}331- 332-tt {333- background-color: #ecf0f3;334- color: #222;335- /* padding: 1px 2px; */336-}337-338-tt.xref, a tt {339- background-color: #FBFBFB;340-}341-342-a:hover tt {343- background: #EEE;344-}deleted:docs/_themes/flasky/theme.conf-3 removed
1-[theme]2-inherit = basic3-stylesheet = flasky.cssmodified:docs/api.rst+2 added
220 unmodified lines221 :param code: the HTTP error code.222 223 .. autofunction:: redirect224 225+.. autofunction:: send_file226+227 .. autofunction:: escape228 229 .. autoclass:: Markup230 :members: escape, unescape, striptags50 unmodified linesmodified:docs/conf.py+4 added-5 removed
14 unmodified lines15 16 # 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.19-sys.path.append(os.path.abspath('.'))19+sys.path.append(os.path.abspath('_themes'))20 21 # -- General configuration -----------------------------------------------------22 23 # If your documentation needs a minimal Sphinx version, state it here.54 unmodified lines78 # If true, sectionauthor and moduleauthor directives will be shown in the79 # output. They are ignored by default.80 #show_authors = False81 82-# The name of the Pygments (syntax highlighting) style to use.83-pygments_style = 'flaskext.FlaskyStyle'84-82 # A list of ignored prefixes for module index sorting.83 #modindex_common_prefix = []84 85 86 # -- Options for HTML output ---------------------------------------------------87 88 # The theme to use for HTML and HTML Help pages. Major themes that come with89 # Sphinx are currently 'default' and 'sphinxdoc'.93-html_theme = 'flasky'90+html_theme = 'flask'91 92 # 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 lines233 'http://werkzeug.pocoo.org/documentation/dev/': None,234 'http://www.sqlalchemy.org/docs/': None,235 'http://wtforms.simplecodes.com/docs/0.5/': None236 }237+238+pygments_style = 'flask_theme_support.FlaskyStyle'modified:tests/flask_tests.py+85 added-2 removed
15 unmodified lines16 import flask17 import unittest18 import tempfile19 from datetime import datetime20-from werkzeug import parse_date20+from werkzeug import parse_date, parse_options_header21+from cStringIO import StringIO22 23 24 example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')25 sys.path.append(os.path.join(example_path, 'flaskr'))448 unmodified lines474 app.register_module(admin, url_prefix='/admin')475 assert app.test_client().get('/admin/').data == '42'476 477 478+class SendfileTestCase(unittest.TestCase):479+480+ 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()488+489+ 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'499+500+ 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'508+509+ 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')517+518+ 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'528+529+ 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.headers534+535+ 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'542+543+ 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'549+550+ 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'557+558+559 def 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 suite573 574 575 if __name__ == '__main__':1 unmodified lineadded:.gitmodules+3 added
1+[submodule "docs/_themes"]2+ path = docs/_themes3+ url = git://github.com/mitsuhiko/flask-sphinx-themes.gitmodified:CHANGES+1 added
13 unmodified lines14 - :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.21 22 Version 0.13 unmodified linesmodified:flask.py+81 added-1 removed
10 unmodified lines11 """12 from __future__ import with_statement13 import os14 import sys15+import mimetypes16 from datetime import datetime, timedelta17 18 from itertools import chain19 from jinja2 import Environment, PackageLoader, FileSystemLoader20 from werkzeug import Request as RequestBase, Response as ResponseBase, \21 LocalStack, LocalProxy, create_environ, SharedDataMiddleware, \21- ImmutableDict, cached_property22+ ImmutableDict, cached_property, wrap_file, Headers23 from werkzeug.routing import Map, Rule24 from werkzeug.exceptions import HTTPException25 from werkzeug.contrib.securecookie import SecureCookie26 241 unmodified lines268 return current_app.response_class(json.dumps(dict(*args, **kwargs),269 indent=None if request.is_xhr else 2), mimetype='application/json')270 271 272+def 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`.280+281+ 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).284+285+ Please never pass filenames to this function from user sources without286+ checking them first. Something like this is usually sufficient to287+ avoid security problems::288+289+ if '..' in filename or filename.startswith('/'):290+ abort(404)291+292+ .. versionadded:: 0.2293+294+ :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'319+320+ 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)329+330+ 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)339+340+ return Response(data, mimetype=mimetype, headers=headers,341+ direct_passthrough=True)342+343+344 def render_template(template_name, **context):345 """Renders a template from the template folder with the given346 context.347 278 unmodified lines626 #: 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)629 630+ #: 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 = False636+637 #: 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