117 Commits

Author SHA1 Message Date
Jeff Widman
03d79be02c Release 0.12.0 2022-03-27 23:48:08 -07:00
Jeff Widman
7f17d2ce57 Update PyPI metadata files: add setup.cfg etc (#164)
Update to the newer PyPI / python packaging metadata file structure.

A lot of this was cribbed from how [`Flask`](https://github.com/pallets/flask) itself
exposes its metadata.
2022-03-26 21:51:54 -07:00
Nick Janetakis
30fba11f36 Remove with_ extension for Jinja 3.0 (#157)
Jinja 3.0 throws a deprecation warning that this will be removed in 3.1
because it's built into Jinja now without needing an extension.

However since folks might want to use Jinja 2 for a while this supports
both versions by only using the extension with Jinja 2.
2022-03-25 21:26:26 -07:00
jnnkB
d474a6a689 prefixed css classes, fixes #152 (#153) 2020-08-14 11:39:15 -07:00
zaw007
83d398d9d5 Support gzip response (#154)
* add gzip compress and decompress

* support gzip response
2020-08-14 11:37:37 -07:00
Jeff Widman
3929742d9c Cleanup version handling slightly (#149)
Some improvements I saw over on
https://github.com/FactoryBoy/factory_boy/pull/676/files that looked
useful here as well.
2020-03-09 13:10:02 -07:00
Jeff Widman
70abd78e55 Setup DB properly
When I switched over to `flask run` entrypoint in b92391d177,
I forgot that the `if name==__main__` code no longer triggers.
So the SQLite in-memory database wasn't getting created for the example
app.

This moves the DB creation to a werkzeug/Flask hook that runs before the
first request to the app, so that the DB table is created when we query
it.

Also updated the test which worked fine previously, but this is more
idiomatic.
2020-03-09 10:01:59 -07:00
Jeff Widman
dbea74b626 Update README.rst 2020-03-09 09:46:05 -07:00
Jeff Widman
c6102aeb14 Change docs to pull version from setup.py 2020-03-02 09:37:37 -08:00
Jeff Widman
10c9c1ae5d Update Flask-SQLAlchemy links 2020-02-22 20:39:21 -08:00
Yaser Amiri
9e600c6e13 Add flask.g section to show g object content. 2020-02-22 09:47:21 -08:00
Matthew Swabey
9b8a8afa97 Fix SQLAlchemy SELECT/EXPLAIN to use url_for to respect app prefixes. Provide url_for to all toolbar templates 2020-02-22 09:24:23 -08:00
Jeff Widman
39ac97a7e0 pycodestyle fixes 2020-02-18 01:21:40 -08:00
Jeff Widman
a5cb5a709f Bump version for development 2020-02-18 01:19:49 -08:00
Jeff Widman
02064c76ed Release 0.11.0 2020-02-18 01:11:19 -08:00
Jeff Widman
d713732807 Cleanup tox/travis
* Switch to python 3.8 in Travis. I tried to add 3.8 while keeping 3.7
and 3.6, but ran into issues with Travis config, so instead just bumped
straight to 3.8. Long term I'd like to explore moving to Azure
Pipelines, but don't have the time to figure that out just yet.
* `flake8` was renamed to `pycodestyle`
* `py.test` was deprecated in favor of `pytest`
2020-02-18 00:42:39 -08:00
Jeff Widman
b92391d177 Switch to Flask's native CLI
Drop `flask_script` in favor of Flask's native CLI:
* https://flask.palletsprojects.com/en/master/cli/

This also requires changing the tests so that `pytest` mocks the env var
`FLASK_ENV` so that the test app starts in development mode. Unlike
normal test apps, we _do_ want development/debug mode, in addition to
testing mode.
2020-02-17 23:57:04 -08:00
Florian
4964ae261f RoutesList: Do not show debugtoolbar routes 2020-02-17 22:30:10 -08:00
Pierre GIRAUD
ad847299c4 Add doc for SQL syntax highlighting 2020-02-17 21:57:01 -08:00
Jeff Widman
7ce099c3d0 Remove deprecated request.is_xhr
This was removed from `werkzeug` `1.0.0`.

Details:
* https://github.com/pallets/werkzeug/issues/1077
* https://github.com/pallets/werkzeug/issues/1714 (search for `is_xhr`)

Fix #144.
2020-02-17 21:50:56 -08:00
Jeff Widman
9c7db48362 Explicitly disable SQLALCHEMY_TRACK_MODIFICATIONS
This silences deprecation warnings.
Background: https://stackoverflow.com/a/33790196/770425

Note: This code can be removed once `flask_sqlalchemy` 3.0 ships, or any
release that includes
https://github.com/pallets/flask-sqlalchemy/pull/727.
2020-02-17 21:36:01 -08:00
Tim Gates
88f15cba35 Fix simple typo: exapanded -> expanded
Closes #141
2020-02-06 14:03:36 -08:00
Matt Good
d852042ccb Merge pull request #119 from davidism/json-available
don't use flask.json_available
2018-02-07 09:52:11 -08:00
David Lord
5bd2e8a423 flask.json_available is a no-op
it is removed in Flask 1.0
2018-02-07 07:13:21 -08:00
Jeff Widman
c27256c00a Bump dev version 2017-02-12 03:33:05 -08:00
Jeff Widman
010206298e Release 0.10.1 2017-02-12 03:04:07 -08:00
Jeff Widman
678ec31229 Revert "Change docs to pull version from setup.py"
This reverts commit 45b70c952f.
This commit broke the readthedocs build because RTD is building the docs
without running setup.py. So there is no package metadata.
2017-02-12 02:48:44 -08:00
Jeff Widman
23d52703fd Make copyright string track current year 2017-02-12 02:33:47 -08:00
Jeff Widman
45b70c952f Change docs to pull version from setup.py 2017-02-12 02:32:47 -08:00
Jeff Widman
9f2c353e86 Trivial imports cleanup 2017-02-12 02:31:26 -08:00
Jeff Widman
cfe142b285 Point Flask-SQLAlchemy docs at ‘latest’ 2017-02-12 00:21:20 -08:00
Jeff Widman
19a25fd895 Add universal wheel support
Let’s roll!
2017-02-10 01:09:59 -08:00
Jeff Widman
8dcb97c05a Travis should use python 3.6 interpreter 2017-02-10 00:50:38 -08:00
Jeff Widman
b49af327cf Use containers for travis tests 2017-02-10 00:44:27 -08:00
Jeff Widman
38ab3a49c1 Test using modern python 2017-02-10 00:42:00 -08:00
Jeff Widman
9f901e34ae Remove deprecated tox arg —use-mirrors 2017-02-10 00:36:19 -08:00
Jeff Widman
f050a6b0de Use latest for flask-sqlalchemy docs rather than pinning version 2017-02-10 00:28:45 -08:00
Jeff Widman
e33f3e1c85 Update RTD links w/https & .io 2017-02-09 23:54:16 -08:00
Peter M. Landwehr
02ff95acde Add LICENSE file to MANIFEST.in / source bundle (#102) 2016-09-18 23:13:08 -07:00
Iuri de Silvio
2436239964 Additional cleanup of deprecated flask.ext.* magic imports. (#97) 2016-06-29 16:52:23 -07:00
Michael Lenzen
18a0030354 Fix deprecated import from flask.ext.sqlalchemy (#94) 2016-06-29 13:33:02 -07:00
Matt Good
ee726eece2 Better setup.py description 2015-04-17 17:53:40 -07:00
Matt Good
1cd9ba69d1 Update CHANGES for 0.10 2015-04-17 17:49:30 -07:00
Matt Good
30a1cd399a Add docs note on Versions panel displaying other packages 2015-04-17 17:49:30 -07:00
Matt Good
0524e7f3e9 Update "Thanks" section of docs 2015-04-17 17:49:30 -07:00
Matt Good
14cd912df7 Fix style errors and add to automated checks
Adds a "stylecheck" to the Tox build config to automatically run flake8 checks.
Fixes existing flake8 issues.
2015-04-17 14:23:58 -07:00
Matt Good
f087311f7c Add missing sqlalchemy_error template
Missed adding this file in the last commit.
2015-04-17 14:19:41 -07:00
Matt Good
61d1fc2678 Display steps needed to display SQL queries
In the SQLAlchemy panel, detect if Flask-SQLAlchemy is not set up to record
queries for the current app, and display the necessary steps to set it up.

The following steps will be detected and displayed if needed:

* install Flask-SQLAlchemy package
* add the extension to this app
* set SQLALCHEMY_RECORD_QUERIES if DEBUG is False
2015-04-17 13:51:10 -07:00
Matt Good
6b2566c01f Enable toolbar on HTML5 pages without </body> tag
Includes the toolbar on HTML5 pages without an explicit </body> tag by checking
for the HTML5 `<!doctype html>`.

Fixes #79
2015-04-17 12:56:10 -07:00
Matt Good
31ea3bce41 Merge branch 'body-warning' 2015-04-16 14:54:32 -07:00
Matt Good
2d60ea6c8d Fix case-insensitive HTML insertion
Keeps the case-insensitive search for "</body>" and removes extra scan for the
tag by trying to insert the toolbar, and warning if unsuccessful.
2015-04-16 14:47:46 -07:00
Matt Good
56994a522d Document using init_app() for the factor pattern 2015-04-16 14:24:24 -07:00
Matt Good
aa90a9d052 Remove restyling table rows before sorting
It doesn't seem to be necessary to remove the "even / odd" styles before
sorting, since they are explicitly toggled to the right state after sorting. It
should be slightly more responsive to skip this step when sorting large tables.
2015-04-15 12:47:14 -07:00
Matt Good
32e0aa8ca3 Ensure profiler "Calls" are sorted numerically
JS Tablesorter's detection of the data type is occasionally confused when the
profiler calls show ratios like "94/57" for total calls to primitive calls.
This change enables parsing "data" attributes on the table headers to pass as
options to Tablesorter. This way we can explicitly specify to use the "digit"
sorter which works the way we want.

Fixes #62
2015-04-15 12:39:59 -07:00
Matt Good
e052b005ec Merge branch 'package-versions' 2015-04-14 19:21:45 -07:00
Matt Good
2f18ac90f9 Convert versions template to 2 spaces for indentation 2015-04-14 19:20:29 -07:00
Matt Good
612f93c129 Show relative paths for package paths
Since most of the paths are the same, only display the path relative to the
main Python library path.
2015-04-14 19:18:45 -07:00
Matt Good
c0826c9a31 Add detailed docs on the built-in panels 2015-04-14 17:22:07 -07:00
Matt Good
7e2de8f588 Merge pull request #48 from yoloseem/sqlparse
Suggestion: Use sqlparse.format() for better sql indentation
2015-04-14 15:44:00 -07:00
Matt Good
5aaa7a6634 Merge branch 'routes' 2015-04-14 15:28:16 -07:00
Matt Good
f7feecc751 Include the "static" route in the list
While this is enabled for most apps, it's optional and might still be useful to display.
2015-04-14 15:23:04 -07:00
Matt Good
cfe1624730 Simplify route methods display
Show just the names as text, without the Python list syntax formatting.
2015-04-14 14:58:31 -07:00
Matt Good
95d7eb977f Format route_list template with spaces 2015-04-14 14:57:47 -07:00
Matt Good
794380fc03 Merge pull request #81 from EricWorkman/master
Add tablesorter to slqlalchemy panel
2015-04-14 14:46:40 -07:00
Eric Workman
5a05620257 Add tablesorter to slqlalchemy panel 2015-04-10 15:44:38 -04:00
Matt Good
bebe884615 Update for 0.9.2 release 2014-12-05 15:43:46 -08:00
Matt Good
10c03880c7 Safely decode non-ascii SQL queries for display
SQL queries containing non-ascii byte strings would cause errors, both with and
without Pygments highlighting.

This updates the non-Pygments case to handle a simple decoding to ensure the
value is ascii-safe. It also removes passing an explicit "utf-8" encoding to
Pygments, since this causes errors when the bytes are not utf-8. When the
encoding is omitted, Pygments will default to "guess" the encoding by trying
utf-8 and falling back to latin-1.

Fixes #55
2014-12-04 14:06:48 -08:00
Matt Good
3fcdfc8f83 Use platform-sensitive filename normalization
The os.path.commonprefix() function only does basic string prefix checking, and
isn't aware of case-insensitive file names, or path separators. Instead, this
switches the filename formatting to use os.path.relpath() for normalizing paths
relative to sys.path.

Fixes #67
2014-12-02 18:15:59 -08:00
Matt Good
914553ddf5 Consolidate redundant code for SQL select/explain
The code for displaying the SQL select results and explain plan were nearly
identical, so this consolidates it to one function and template. It also fixes
correctly displaying the timing results as milliseconds.
2014-11-24 15:04:50 -08:00
Matt Good
b4fe0b954c Fix misspelled CSS classes 2014-11-24 14:46:41 -08:00
Matt Good
7557ee6794 Ensure SQL queries are HTML-escaped
The SQL queries were displayed with the `safe` filter which allowed properly
including the Pygments-highlighted HTML, but if Pygments wasn't installed this
allowed the raw SQL to be included without escaping. This change removes the
`safe` filter and instead wraps the Pygments HTML with the `Markup` class. This
allows proper auto-escaping in the template.

Fixes #70
2014-11-24 14:36:56 -08:00
Matt Good
382c5e7da9 Remove old commented code
Looks like some old code from the original Django toolbar was left in the
template.
2014-11-24 14:25:32 -08:00
Matt Good
6286dadc27 Version update for 0.9.1 release 2014-11-24 13:25:17 -08:00
=
81f8e34846 Removed printing of routes to console. 2014-03-23 15:14:28 +11:00
=
79717926a5 Added endpoints, HTTP methods, Is alias and Redirect to columns to route list. 2014-03-23 15:12:31 +11:00
Justin McKay
5084428c9d Added the Route List panel to show the routes that are available within Flask. 2014-03-22 23:57:48 +11:00
Matt Good
82295aa4aa printable filter should replace non-ascii bytes
In Python 2, when repr() returns bytes, replace any non-ascii bytes
with the unicode ? character to ensure that the result is printable.

Fixes #66
2014-02-02 14:46:41 -08:00
Matt Good
70488fc14a Fix Py3 support for bytes SQL queries
Fixes #64
2014-01-14 17:56:47 -08:00
Matt Good
4901d68b01 Fix version number in docs 2014-01-03 15:14:49 -08:00
Matt Good
d671a849bb Bump version for new release 2014-01-03 15:07:48 -08:00
Matt Good
ffbdf0f563 Add SQLAlchemy to test app 2013-12-31 17:55:19 -05:00
Matt Good
b08fe477b6 Merge pull request #63 from defuz/pep8
PEP8 formatting
2013-12-02 16:20:27 -08:00
Ivan Ivaschenko
903ed85f00 remove coding:utf-8 and add some style fixes 2013-11-29 00:17:15 +02:00
Ivan Ivaschenko
5710314252 pep8 formatting + coding: utf8 2013-11-28 18:31:29 +02:00
Matt Good
277462d822 Fix build status image
RST example copied from Travis was a bit broken
2013-11-06 09:59:50 -08:00
Matt Good
26691d49cd Add Travis build statis to README 2013-11-06 09:58:49 -08:00
Matt Good
bd37db9dc4 Fix SQLAlchemy URL registration
The init_app() restructuring in 356e6c removed "load_panels()", but need
to add it back so panels like SQLAlchemy can register their URLs on the
Blueprint before it's activated.
2013-11-06 09:33:00 -08:00
Matt Good
091c4fa70c Compatibility fixes for Python 3
Fixes #54 (at least the basic stuff, this is still a bit experimental)
2013-11-06 09:06:05 -08:00
Matt Good
d5987410d1 Add basic sanity test 2013-11-06 09:00:05 -08:00
Matt Good
6d8249160d Rename "settings" panel to "config" 2013-11-01 14:04:10 -07:00
Matt Good
1e046d57f4 Remove some unneeded code from SettingsVars panel 2013-11-01 12:42:38 -07:00
Matt Good
9e3546b416 Merge commit 'refs/pull/51/head' of github.com:mgood/flask-debugtoolbar
Conflicts:
	flask_debugtoolbar/toolbar.py
2013-11-01 11:41:08 -07:00
Matt Good
26034475f2 Load panels with werkzeug's "import_string"
Also add back caching of the loaded panel classes.
This prevents repeated warnings if there was an import error loading the
class the first time.
2013-07-30 17:56:54 -07:00
Matt Good
356e6c8268 Restructure to support init_app
Fixes #38
2013-07-30 17:37:34 -07:00
Matt Good
5870fce178 Can check blueprint name instead of URL prefix 2013-07-30 09:25:02 -07:00
Alexey Diyan
855c7ab377 Port SettingsVarsDebugPanel from Django DebugToolbar 2013-05-10 19:17:32 +03:00
Lucas Taylor
ccd8ba66b2 Display installed packages and versions in Versions panel (requires setup tools) 2013-03-27 17:28:51 -07:00
Lucas Taylor
093763909f Display installed packages and versions in Versions panel (requires Yolk) 2013-03-27 17:16:28 -07:00
Matt Good
115e874a39 Reformat templates and static files with 2 space indentation
Fixes #45
2013-03-16 16:21:39 -07:00
Hyunjun Kim
bd2b65d068 Improve format_sql(): use sqlparse.format() 2013-03-11 13:33:41 +09:00
Matt Good
b7c39113e7 Template editor should use Jinja loader's encoding
The template loader wouldn't handle non-ASCII template encodings.
Updated it to use the encoding parameter of the Jinja loader when
reading and writing the template files.

Fixes #46
2013-03-08 09:00:10 -08:00
Matt Good
05288daf17 Docs Makefile needs to ensure git submodules are initialized 2013-02-21 13:43:27 -08:00
Matt Good
79421df5cd Use Flask theme for the documentation 2013-02-21 13:37:12 -08:00
Matt Good
8d5d37fa0b Merge branch 'release/0.8.0' 2013-02-21 12:26:23 -08:00
Matt Good
1029b9131b Prepare 0.8.0 release 2013-02-21 12:25:45 -08:00
Matt Good
3bea63dc8a Fix werkzeug request logging with the log panel
Werkzeug will disable its default logging setup if another log handler
is already configured.  At some point the initialization order changed
and the logging panel's handler is getting added first now, so
werkzeug's request log will not be printed to the console by default. By
explicitly calling werkzeug's logger we now make sure it's initialized
before the logging panel's handler.

Fixes #33
2013-02-21 10:53:16 -08:00
Matt Good
856eb52a95 Nice error message for un-repr-able objects
The "printable" filter can throw an exception when trying to display a
user object whose __repr__ implementation returns unicode, which repr()
does not allow. Catch it and display a more informative message
instead.

See #31 and #39
2013-02-20 20:46:31 -08:00
Matt Good
50017f13a7 Switch to itsdangerous for SQL query signing
Fixing #31 where the query signing would break when the SECRET_KEY
contained non-ascii values. In the process switch to itsdangerous
instead of rolling our own signatures.
2013-02-20 20:02:00 -08:00
Matt Good
561889738f Merge pull request #41 from crosspop/ajaxfix
Intercept redirect only if it’s not XHR (Ajax)
2013-02-19 17:01:11 -08:00
Matt Good
b97e58c1f2 Merge pull request #42 from bollwyvl/share-jquery
adding reference to noConflict'ed jQuery
2013-02-19 11:10:48 -08:00
Nicholas Bollweg
0f923475c8 adding reference to noConflict'ed jQuery 2013-02-13 12:29:45 -05:00
Hong Minhee
43df69ab24 Intercept redirect only if it's not XHR (Ajax)
Intercept redirect can't really help debugging at all
if requests are XHR (Ajax), because browsers just don't render
their response by default.
2013-01-17 05:11:26 +09:00
Matt Good
3e4cd1ecfa Merge pull request #35 from rconradharris/patch-1
Profiler: Use update_wrapper on partial

If the profiler panel is applied before the request-vars panel, the wrapper added by the profiler causes an error since it's missing a `__module__` attribute.
2012-09-25 10:43:19 -07:00
Matt Good
cfa5984d3e Convert SQLAlchemy query duration to ms to match the label
The SQLAlchemy panel labels the query duration column "(ms)" but the
times from Flask-SQLAlchemy are given in seconds.

Fixes #36
2012-09-25 09:45:52 -07:00
Rick Harris
c9c0228a62 Profiler: Use update_wrapper on partial
The `update_wrapper` call is needed so that the new partial
func inherits the `__module__` of the original function.

The `__module__` is needed because the request-vars panel uses
`func.__module__` in building the qualified name.
2012-09-04 19:45:51 -05:00
Rune Halvorsen
f6e37be73c Issue a warning, rather than an exception, when toolbar can't be inserted 2012-03-10 19:36:57 +01:00
Rune Halvorsen
71bd15a4d6 Added an exception when debug toolbar can't be inserted due to missing markup 2012-02-29 01:44:17 +01:00
64 changed files with 2014 additions and 1211 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@
build/
dist/
docs/_build
.tox

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "docs/_themes"]
path = docs/_themes
url = git://github.com/mitsuhiko/flask-sphinx-themes.git

9
.travis.yml Normal file
View File

@@ -0,0 +1,9 @@
sudo: false
language: python
python: "3.8"
env:
- TOXENV=py27
- TOXENV=py38
install:
- pip install tox
script: tox

View File

@@ -1,6 +1,117 @@
Changes
=======
0.12.0 (2022-03-28)
-------------------
Enhancements:
- Add flask.g section to show g object content. by @Yaser-Amiri in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/118
- Support gzip response by @zaw007 in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/154
- Update PyPI metadata files: add `setup.cfg` etc by @jeffwidman in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/164
Fixes:
- Remove deprecated Jinja with_ extension for Jinja 3.0 (related to Flask 2.0) by @nickjj in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/157
- Fix SQLAlchemy SELECT/EXPLAIN to use url_for to respect app prefixes.… by @mattaw in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/143
- Setup DB properly by @jeffwidman in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/148
- prefixed css classes, fixes #152 by @jnnkB in https://github.com/flask-debugtoolbar/flask-debugtoolbar/pull/153
0.11.0 (2020-02-18)
-------------------
Enhancements:
- Switch to Flask's native CLI, dropping flask_script in the process (b92391d, thanks @jeffwidman)
- Do not show DebugToolbar routes in the route map (#86, thanks @floqqi)
- Document Pygments for SQL highlighting (#127, thanks @pgiraud)
Fixes:
- Remove deprecated flask.json_available (#119, thanks @davidism)
- Remove deprecated request.is_xhr (7ce099c, thanks @jeffwidman)
- Explicitly disable `SQLALCHEMY_TRACK_MODIFICATIONS` (9c7db48, thanks @jeffwidman)
- Fix typo (#142, thanks @timgates42)
0.10.1 (2017-02-12)
-------------------
Enhancements:
- Add support for Python wheels
Fixes:
- Switch imports from deprecated flask.ext.* to flask_* syntax (#94, thanks
Michael Lenzen & #97 thanks Iuri de Silvio)
0.10.0 (2015-04-17)
-------------------
Enhancements:
- Added new "Routes" panel displaying URL routing rules (#69, thanks Justin McKay)
- "Versions" panel displays versions of all installed packages (#49, thanks Lucas Taylor)
- SQLAlchemy displays necessary setup steps to set up query recording
- Support reformatting SQL queries if ``sqlparse`` library is available (#48, thanks Hyunjun Kim)
- Enable sorting SQLAlchemy queries (#81, thanks Eric Workman)
- Support inserting toolbar on HTML5 pages without ``</body>`` tag
- Log a warning if unable to insert the toolbar (#20, thanks Rune Halvorsen)
Fixes:
- Ensure numeric sorting of profiler "Calls" column
0.9.2 (2014-12-05)
------------------
Fixes:
- HTML escape SQL queries when syntax highlighting is not available
- Use case-insensitive comparison to normalize filenames on Windows
- Fix exception when SQL query contained non-ASCII characters
0.9.1 (2014-11-24)
------------------
Fixes:
- Fix SQL queries with byte strings on Python 3
- Fix displaying values whose `repr()` contains unprintable characters
0.9.0 (2014-01-03)
------------------
Enhancements:
- Python 3 compatibility (#54, thanks justinmayer and jmagnusson)
- Support .init_app() (#38)
- New "Config" panel displaying Flask config values (#51, thanks Alexey Diyan)
- Better PEP8-style formatting (#63, thanks Ivan Ivaschenko)
Fixes:
- Fix template editor with non-ASCII templates (#46)
0.8 (2013-02-21)
----------------
Enhancements:
- Use `itsdangerous <http://pythonhosted.org/itsdangerous/>`_ to sign SQL queries
- Expose the jQuery object as ``fldt.$`` so extensions can use the toolbar's
copy of jQuery (#42)
Fixes:
- Don't intercept redirects on XHR requests (#41)
- Fix SQL query time display as milliseconds (#36)
- Fix ``functools.partial`` error (#35)
- Fix werkzeug request logging with logging panel (#33)
- Fix SQL panel unicode encoding error (#31)
0.7.1 (2012-05-18)
------------------
@@ -20,7 +131,7 @@ Enhancements:
0.6.3.1 (2012-04-16)
------------------
--------------------
New release to add missing changelog for 0.6.3

View File

@@ -1,2 +1,3 @@
include LICENSE
recursive-include flask_debugtoolbar/templates *.html
recursive-include flask_debugtoolbar/static *

View File

@@ -4,6 +4,9 @@ Flask Debug-toolbar
This is a port of the excellent `django-debug-toolbar <https://github.com/django-debug-toolbar/django-debug-toolbar>`_
for Flask applications.
.. image:: https://travis-ci.org/flask-debugtoolbar/flask-debugtoolbar.png?branch=master
:target: https://travis-ci.org/flask-debugtoolbar/flask-debugtoolbar
Installation
------------
@@ -37,4 +40,4 @@ In production, setting ``app.debug = False`` will disable the toolbar.
See the `documentation`_ for more information.
.. _documentation: http://flask-debugtoolbar.readthedocs.org
.. _documentation: https://flask-debugtoolbar.readthedocs.io/

View File

@@ -41,7 +41,7 @@ help:
clean:
-rm -rf $(BUILDDIR)/*
html:
html: _themes
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
@@ -151,3 +151,7 @@ doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
_themes:
git clone git://github.com/Pylons/pylons_sphinx_theme.git _themes
cd ..; git submodule update --init; cd docs

BIN
docs/_static/example.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

BIN
docs/_static/screenshot-config-panel.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
docs/_static/screenshot-logger-panel.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

BIN
docs/_static/screenshot-time-panel.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

1
docs/_themes Submodule

Submodule docs/_themes added at 1cc44686f0

View File

@@ -11,7 +11,16 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
import datetime
import os
import pkg_resources
import sys
import time
import flask_debugtoolbar
BUILD_DATE = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
@@ -25,7 +34,10 @@ import sys, os
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.viewcode']
extensions = [
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -41,16 +53,16 @@ master_doc = 'index'
# General information about the project.
project = u'Flask-DebugToolbar'
copyright = u'2012, Matt Good'
copyright = u'2012-{0}'.format(BUILD_DATE.year)
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.7'
# The full version, including alpha/beta/rc tags.
release = '0.7.1'
release = flask_debugtoolbar.__version__
# The short X.Y version.
version = '.'.join(release.split('.')[:2])
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -86,20 +98,27 @@ pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
intersphinx_mapping = {
'flasksqlalchemy': ('http://flask-sqlalchemy.pocoo.org/latest/', None)
}
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
html_theme = 'flask'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
html_theme_options = {
'index_logo': None,
}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
sys.path.append(os.path.abspath('_themes'))
html_theme_path = ['_themes']
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".

View File

@@ -1,21 +1,19 @@
.. Flask-DebugToolbar documentation master file, created by
sphinx-quickstart on Wed Feb 15 18:08:39 2012.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Flask-DebugToolbar
==================
Welcome to Flask-DebugToolbar's documentation!
==============================================
This extension adds a toolbar overlay to Flask applications containing useful information for debugging.
This is a port of the excellent `django-debug-toolbar <https://github.com/django-debug-toolbar/django-debug-toolbar>`_
for Flask applications.
.. image:: _static/example.gif
Installation
------------
Installing is simple with pip::
Installing is simple with `pip`_::
$ pip install flask-debugtoolbar
.. _pip: https://pip.pypa.io/
Usage
-----
@@ -36,9 +34,16 @@ Setting up the debug toolbar is simple::
toolbar = DebugToolbarExtension(app)
The toolbar will automatically be injected into Jinja templates when debug mode is on.
In production, setting ``app.debug = False`` will disable the toolbar.
The toolbar will automatically be injected into HTML responses when debug mode
is on. In production, setting ``app.debug = False`` will disable the toolbar.
This extension also supports the Flask app factory pattern by separately
creating the toolbar and later initializing it for an app::
toolbar = DebugToolbarExtension()
# Then later on.
app = create_app('the-config.cfg')
toolbar.init_app(app)
Configuration
-------------
@@ -61,11 +66,26 @@ To change one of the config options, set it in the Flask app's config like::
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
Panels
------
.. toctree::
panels
Contributing
------------
Fork us `on GitHub <https://github.com/mgood/flask-debugtoolbar>`_
Thanks
------
This was based on the original `django-debug-toolbar`_. Thanks to `Michael van Tellingen`_ for the original development of this Flask extension, and to all the `individual contributors`_.
.. _django-debug-toolbar: https://github.com/django-debug-toolbar/django-debug-toolbar
.. _Michael van Tellingen: https://github.com/mvantellingen
.. _individual contributors: https://github.com/mgood/flask-debugtoolbar/graphs/contributors
Indices and tables
==================

110
docs/panels.rst Normal file
View File

@@ -0,0 +1,110 @@
Built-In Panels
===============
Versions
--------
flask_debugtoolbar.panels.versions.VersionDebugPanel
Shows the installed Flask version. The expanded view displays all installed packages and their versions as detected by ``setuptools``.
Time
----
flask_debugtoolbar.panels.timer.TimerDebugPanel
Shows the time taken to process the current request. The expanded view includes the breakdown of CPU time, by user and system, wall clock time, and context switches.
.. image:: _static/screenshot-time-panel.png
HTTP Headers
------------
flask_debugtoolbar.panels.headers.HeaderDebugPanel
Displays the HTTP headers for the current request.
.. image:: _static/screenshot-headers-panel.png
Request Vars
------------
flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel
Displays details of the Flask request-related variables, including the view function parameters, cookies, session variables, and GET and POST variables.
.. image:: _static/screenshot-request-vars-panel.png
Config
------
flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel
Shows the contents of the Flask application's config dict ``app.config``.
.. image:: _static/screenshot-config-panel.png
Templates
---------
flask_debugtoolbar.panels.template.TemplateDebugPanel
Shows information about the templates rendered for this request, and the value of the template parameters provided.
.. image:: _static/screenshot-template-panel.png
SQLAlchemy
----------
flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel
Shows SQL queries run during the current request.
.. note:: This panel requires using the `Flask-SQLAlchemy`_ extension in order
to record the queries. See the Flask-SQLAlchemy
:ref:`flasksqlalchemy:quickstart` section to configure it.
For additional details on query recording see the
:py:func:`~flask_sqlalchemy.get_debug_queries` documentation.
.. note:: SQL syntax highlighting requires `Pygments`_ to be installed.
.. image:: _static/screenshot-sqlalchemy-panel.png
.. _Flask-SQLAlchemy: http://flask-sqlalchemy.pocoo.org/
.. _Pygments: http://pygments.org/
Logging
-------
flask_debugtoolbar.panels.logger.LoggingPanel
Displays log messages recorded during the current request.
.. image:: _static/screenshot-logger-panel.png
Route List
----------
flask_debugtoolbar.panels.route_list.RouteListDebugPanel
Displays the Flask URL routing rules.
Profiler
--------
flask_debugtoolbar.panels.profiler.ProfilerDebugPanel
Reports profiling data for the current request. Due to the performance overhead, profiling is disabled by default. Click the checkmark to toggle profiling on or off. After enabling the profiler, refresh the page to re-run it with profiling.
.. image:: _static/screenshot-profiler-panel.png

View File

@@ -1,9 +1,7 @@
import sys
sys.path.insert(0, '.')
# Run using: `FLASK_ENV=development flask run`
from flask import Flask, render_template, redirect, url_for
from flask.ext.script import Manager
from flask.ext.sqlalchemy import SQLAlchemy
from flask_sqlalchemy import SQLAlchemy
from flask_debugtoolbar import DebugToolbarExtension
@@ -16,32 +14,35 @@ app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = True
#)
#app.config['DEBUG_TB_HOSTS'] = ('127.0.0.1', '::1' )
app.config['SECRET_KEY'] = 'asd'
app.config['DEBUG'] = True
# TODO: This can be removed once flask_sqlalchemy 3.0 ships
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
db = SQLAlchemy(app)
toolbar = DebugToolbarExtension(app)
class ExampleModel(db.Model):
__tablename__ = 'examples'
value = db.Column(db.String(100), primary_key=True)
@app.before_first_request
def setup():
db.create_all()
@app.route('/')
def index():
app.logger.info("Hello there")
ExampleModel.query.get(1)
return render_template('index.html')
@app.route('/redirect')
def redirect_example():
response = redirect(url_for('index'))
response.set_cookie('test_cookie', '1')
return response
if __name__ == "__main__":
db.create_all()
manager = Manager(app)
manager.run()

View File

@@ -1,37 +1,49 @@
import os
import warnings
from flask import current_app, request, g
from flask import Blueprint, current_app, request, g, send_from_directory, url_for
from flask.globals import _request_ctx_stack
from flask import send_from_directory
from jinja2 import __version__ as __jinja_version__
from jinja2 import Environment, PackageLoader
from werkzeug.exceptions import HTTPException
from werkzeug.urls import url_quote_plus
from flask_debugtoolbar.compat import iteritems
from flask_debugtoolbar.toolbar import DebugToolbar
from flask import Blueprint
from flask_debugtoolbar.utils import decode_text, gzip_compress, gzip_decompress
try:
# Python 3.8+
from importlib.metadata import version
__version__ = version("Flask-DebugToolbar")
except ImportError:
import pkg_resources
__version__ = pkg_resources.get_distribution("Flask-DebugToolbar").version
module = Blueprint('debugtoolbar', __name__)
def replace_insensitive(string, target, replacement):
"""Similar to string.replace() but is case insensitive
Code borrowed from: http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
Code borrowed from:
http://forums.devshed.com/python-programming-11/case-insensitive-string-replace-490921.html
"""
no_case = string.lower()
index = no_case.rfind(target.lower())
if index >= 0:
return string[:index] + replacement + string[index + len(target):]
else: # no results so return the original string
else: # no results so return the original string
return string
def _printable(value):
if isinstance(value, unicode):
return value.encode('unicode_escape')
elif isinstance(value, str):
return value.encode('string_escape')
else:
return repr(value)
try:
return decode_text(repr(value))
except Exception as e:
return '<repr(%s) raised %s: %s>' % (
object.__repr__(value), type(e).__name__, e)
class DebugToolbarExtension(object):
@@ -40,12 +52,32 @@ class DebugToolbarExtension(object):
_redirect_codes = [301, 302, 303, 304]
def __init__(self, app):
def __init__(self, app=None):
self.app = app
self.debug_toolbars = {}
self.hosts = ()
jinja_extensions = ['jinja2.ext.i18n']
if not app.config.get('DEBUG_TB_ENABLED', app.debug):
if __jinja_version__[0] == '2':
jinja_extensions.append('jinja2.ext.with_')
# Configure jinja for the internal templates and add url rules
# for static data
self.jinja_env = Environment(
autoescape=True,
extensions=jinja_extensions,
loader=PackageLoader(__name__, 'templates'))
self.jinja_env.filters['urlencode'] = url_quote_plus
self.jinja_env.filters['printable'] = _printable
self.jinja_env.globals['url_for'] = url_for
if app is not None:
self.init_app(app)
def init_app(self, app):
for k, v in iteritems(self._default_config(app)):
app.config.setdefault(k, v)
if not app.config['DEBUG_TB_ENABLED']:
return
if not app.config.get('SECRET_KEY'):
@@ -55,29 +87,38 @@ class DebugToolbarExtension(object):
DebugToolbar.load_panels(app)
self.hosts = app.config.get('DEBUG_TB_HOSTS', ())
self.app.before_request(self.process_request)
self.app.after_request(self.process_response)
self.app.teardown_request(self.teardown_request)
app.before_request(self.process_request)
app.after_request(self.process_response)
app.teardown_request(self.teardown_request)
# Monkey-patch the Flask.dispatch_request method
app.dispatch_request = self.dispatch_request
# Configure jinja for the internal templates and add url rules
# for static data
self.jinja_env = Environment(
autoescape=True,
extensions=['jinja2.ext.i18n', 'jinja2.ext.with_'],
loader=PackageLoader(__name__, 'templates'))
self.jinja_env.filters['urlencode'] = url_quote_plus
self.jinja_env.filters['printable'] = _printable
app.add_url_rule('/_debug_toolbar/static/<path:filename>',
'_debug_toolbar.static', self.send_static_file)
'_debug_toolbar.static', self.send_static_file)
app.register_blueprint(module, url_prefix='/_debug_toolbar/views')
def _default_config(self, app):
return {
'DEBUG_TB_ENABLED': app.debug,
'DEBUG_TB_HOSTS': (),
'DEBUG_TB_INTERCEPT_REDIRECTS': True,
'DEBUG_TB_PANELS': (
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flask_debugtoolbar.panels.config_vars.ConfigVarsDebugPanel',
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_debugtoolbar.panels.route_list.RouteListDebugPanel',
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
'flask_debugtoolbar.panels.g.GDebugPanel',
),
}
def dispatch_request(self):
"""Modified version of Flask.dispatch_request to call process_view."""
req = _request_ctx_stack.top.request
@@ -102,10 +143,11 @@ class DebugToolbarExtension(object):
def _show_toolbar(self):
"""Return a boolean to indicate if we need to show the toolbar."""
if request.path.startswith('/_debug_toolbar/'):
if request.blueprint == 'debugtoolbar':
return False
if self.hosts and request.remote_addr not in self.hosts:
hosts = current_app.config['DEBUG_TB_HOSTS']
if hosts and request.remote_addr not in hosts:
return False
return True
@@ -122,7 +164,9 @@ class DebugToolbarExtension(object):
real_request = request._get_current_object()
self.debug_toolbars[real_request] = DebugToolbar(real_request, self.jinja_env)
self.debug_toolbars[real_request] = (
DebugToolbar(real_request, self.jinja_env))
for panel in self.debug_toolbars[real_request].panels:
panel.process_request(real_request)
@@ -131,11 +175,16 @@ class DebugToolbarExtension(object):
This is done by the dispatch_request method.
"""
real_request = request._get_current_object()
if real_request in self.debug_toolbars:
for panel in self.debug_toolbars[real_request].panels:
new_view = panel.process_view(real_request, view_func, view_kwargs)
if new_view:
view_func = new_view
try:
toolbar = self.debug_toolbars[real_request]
except KeyError:
return view_func
for panel in toolbar.panels:
new_view = panel.process_view(real_request, view_func, view_kwargs)
if new_view:
view_func = new_view
return view_func
def process_response(self, response):
@@ -145,7 +194,7 @@ class DebugToolbarExtension(object):
# Intercept http redirect codes and display an html page with a
# link to the target.
if self.debug_toolbars[real_request].config['DEBUG_TB_INTERCEPT_REDIRECTS']:
if current_app.config['DEBUG_TB_INTERCEPT_REDIRECTS']:
if response.status_code in self._redirect_codes:
redirect_to = response.location
redirect_code = response.status_code
@@ -161,20 +210,43 @@ class DebugToolbarExtension(object):
# If the http response code is 200 then we process to add the
# toolbar to the returned html response.
if (response.status_code == 200
and response.headers['content-type'].startswith('text/html')):
for panel in self.debug_toolbars[real_request].panels:
panel.process_response(real_request, response)
if not (response.status_code == 200 and
response.is_sequence and
response.headers['content-type'].startswith('text/html')):
return response
if response.is_sequence:
response_html = response.data.decode(response.charset)
toolbar_html = self.debug_toolbars[real_request].render_toolbar()
if 'gzip' in response.headers.get('Content-Encoding', ''):
response_html = gzip_decompress(response.data).decode(response.charset)
else:
response_html = response.data.decode(response.charset)
content = replace_insensitive(
response_html, '</body>', toolbar_html + '</body>')
content = content.encode(response.charset)
response.response = [content]
response.content_length = len(content)
no_case = response_html.lower()
body_end = no_case.rfind('</body>')
if body_end >= 0:
before = response_html[:body_end]
after = response_html[body_end:]
elif no_case.startswith('<!doctype html>'):
before = response_html
after = ''
else:
warnings.warn('Could not insert debug toolbar.'
' </body> tag not found in response.')
return response
toolbar = self.debug_toolbars[real_request]
for panel in toolbar.panels:
panel.process_response(real_request, response)
toolbar_html = toolbar.render_toolbar()
content = ''.join((before, toolbar_html, after))
content = content.encode(response.charset)
if 'gzip' in response.headers.get('Content-Encoding', ''):
content = gzip_compress(content)
response.response = [content]
response.content_length = len(content)
return response

View File

@@ -0,0 +1,9 @@
import sys
PY2 = sys.version_info[0] == 2
if PY2:
iteritems = lambda d: d.iteritems()
else:
iteritems = lambda d: iter(d.items())

View File

@@ -1,16 +1,18 @@
"""Base DebugPanel class"""
class DebugPanel(object):
"""
Base class for debug panels.
"""
# name = Base
has_content = False # If content returns something, set to true in subclass
# If content returns something, set to true in subclass
has_content = False
# If the client is able to activate/de-activate the panel
user_enable = False
# We'll maintain a local context instance so we can expose our template
# context variables to panels which need them:
context = {}
@@ -57,5 +59,3 @@ class DebugPanel(object):
def process_response(self, request, response):
pass

View File

@@ -0,0 +1,29 @@
from flask import current_app
from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x
class ConfigVarsDebugPanel(DebugPanel):
"""
A panel to display all variables from Flask configuration
"""
name = 'ConfigVars'
has_content = True
def nav_title(self):
return _('Config')
def title(self):
return _('Config')
def url(self):
return ''
def content(self):
context = self.context.copy()
context.update({
'config': current_app.config,
})
return self.render('panels/config_vars.html', context)

View File

@@ -0,0 +1,29 @@
from flask import g
from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x
class GDebugPanel(DebugPanel):
"""
A panel to display flask.g content.
"""
name = 'g'
has_content = True
def nav_title(self):
return _('flask.g')
def title(self):
return _('flask.g content')
def url(self):
return ''
def content(self):
context = self.context.copy()
context.update({
'g_content': g.__dict__
})
return self.render('panels/g.html', context)

View File

@@ -12,21 +12,22 @@ from flask_debugtoolbar.utils import format_fname
_ = lambda x: x
class ThreadTrackingHandler(logging.Handler):
def __init__(self):
if threading is None:
raise NotImplementedError("threading module is not available, \
the logging panel cannot be used without it")
logging.Handler.__init__(self)
self.records = {} # a dictionary that maps threads to log records
self.records = {} # a dictionary that maps threads to log records
def emit(self, record):
self.get_records().append(record)
def get_records(self, thread=None):
"""
Returns a list of records for the provided thread, of if none is provided,
returns a list for the current thread.
Returns a list of records for the provided thread, of if none is
provided, returns a list for the current thread.
"""
if thread is None:
thread = threading.currentThread()
@@ -46,18 +47,27 @@ _init_lock = threading.Lock()
def _init_once():
# Initialize the logging handler once, but after werkzeug has set up its
# default logger. Otherwise, if this sets up the logging first, werkzeug
# will not create a default logger, so the development server's output will
# not get printed.
global handler
if handler is not None:
return
with _init_lock:
global handler
if handler is not None:
return
handler = ThreadTrackingHandler()
logging.root.addHandler(handler)
return
with _init_lock:
if handler is not None:
return
# Call werkzeug's internal logging to make sure it gets configured
# before we add our handler. Otherwise werkzeug will see our handler
# and not configure console logging for the request log.
# Werkzeug's default log level is INFO so this message probably won't
# be seen.
try:
from werkzeug._internal import _log
except ImportError:
pass
else:
_log('debug', 'Initializing Flask-DebugToolbar log handler')
handler = ThreadTrackingHandler()
logging.root.addHandler(handler)
class LoggingPanel(DebugPanel):
@@ -78,7 +88,8 @@ class LoggingPanel(DebugPanel):
def nav_subtitle(self):
# FIXME l10n: use ngettext
return "%s message%s" % (len(handler.get_records()), (len(handler.get_records()) == 1) and '' or 's')
num_records = len(handler.get_records())
return '%s message%s' % (num_records, '' if num_records == 1 else 's')
def title(self):
return _('Log Messages')
@@ -102,5 +113,3 @@ class LoggingPanel(DebugPanel):
context.update({'records': records})
return self.render('panels/logger.html', context)

View File

@@ -1,10 +1,8 @@
import sys
try:
import cProfile as profile
except ImportError:
import profile
import functools
import os.path
import pstats
from flask import current_app
@@ -37,7 +35,9 @@ class ProfilerDebugPanel(DebugPanel):
def process_view(self, request, view_func, view_kwargs):
if self.is_active:
return functools.partial(self.profiler.runcall, view_func)
func = functools.partial(self.profiler.runcall, view_func)
functools.update_wrapper(func, view_func)
return func
def process_response(self, request, response):
if not self.is_active:
@@ -116,6 +116,3 @@ class ProfilerDebugPanel(DebugPanel):
'function_calls': self.function_calls,
}
return self.render('panels/profiler.html', context)

View File

@@ -4,6 +4,7 @@ from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x
class RequestVarsDebugPanel(DebugPanel):
"""
A panel to display request variables (POST/GET, session, cookies).
@@ -34,14 +35,15 @@ class RequestVarsDebugPanel(DebugPanel):
def content(self):
context = self.context.copy()
context.update({
'get': [(k, self.request.args.getlist(k)) for k in self.request.args],
'post': [(k, self.request.form.getlist(k)) for k in self.request.form],
'cookies': [(k, self.request.cookies.get(k)) for k in self.request.cookies],
'view_func': '%s.%s' % (self.view_func.__module__, self.view_func.__name__) if self.view_func else '[unknown]',
'get': self.request.args.lists(),
'post': self.request.form.lists(),
'cookies': self.request.cookies.items(),
'view_func': ('%s.%s' % (self.view_func.__module__,
self.view_func.__name__)
if self.view_func else '[unknown]'),
'view_args': self.view_args,
'view_kwargs': self.view_kwargs or {},
'session': self.session.items(),
})
return self.render('panels/request_vars.html', context)

View File

@@ -0,0 +1,38 @@
from flask_debugtoolbar.panels import DebugPanel
from flask import current_app
_ = lambda x: x
class RouteListDebugPanel(DebugPanel):
"""
Panel that displays the URL routing rules.
"""
name = 'RouteList'
has_content = True
routes = []
def nav_title(self):
return _('Route List')
def title(self):
return _('Route List')
def url(self):
return ''
def nav_subtitle(self):
count = len(self.routes)
return '%s %s' % (count, 'route' if count == 1 else 'routes')
def process_request(self, request):
self.routes = [
rule
for rule in current_app.url_map.iter_rules()
if not rule.rule.startswith('/_debug_toolbar')
]
def content(self):
return self.render('panels/route_list.html', {
'routes': self.routes,
})

View File

@@ -1,34 +1,83 @@
import hashlib
try:
from flask.ext.sqlalchemy import get_debug_queries, SQLAlchemy
from flask_sqlalchemy import get_debug_queries, SQLAlchemy
except ImportError:
sqlalchemy_available = False
get_debug_queries = SQLAlchemy = None
else:
sqlalchemy_available = True
from flask import request, current_app, abort, json_available, g
from flask.helpers import json
from flask import request, current_app, abort, g
from flask_debugtoolbar import module
from flask_debugtoolbar.panels import DebugPanel
from flask_debugtoolbar.utils import format_fname, format_sql
import itsdangerous
_ = lambda x: x
def query_signer():
return itsdangerous.URLSafeSerializer(current_app.config['SECRET_KEY'],
salt='fdt-sql-query')
def is_select(statement):
prefix = b'select' if isinstance(statement, bytes) else 'select'
return statement.lower().strip().startswith(prefix)
def dump_query(statement, params):
if not params or not is_select(statement):
return None
try:
return query_signer().dumps([statement, params])
except TypeError:
return None
def load_query(data):
try:
statement, params = query_signer().loads(request.args['query'])
except (itsdangerous.BadSignature, TypeError):
abort(406)
# Make sure it is a select statement
if not is_select(statement):
abort(406)
return statement, params
def extension_used():
return 'sqlalchemy' in current_app.extensions
def recording_enabled():
return (current_app.debug
or current_app.config.get('SQLALCHEMY_RECORD_QUERIES'))
def is_available():
return sqlalchemy_available and extension_used() and recording_enabled()
def get_queries():
if get_debug_queries:
return get_debug_queries()
else:
return []
class SQLAlchemyDebugPanel(DebugPanel):
"""
Panel that displays the time a response took in milliseconds.
"""
name = 'SQLAlchemy'
@property
def has_content(self):
if not json_available or not sqlalchemy_available:
return True # will display an error message
return bool(get_debug_queries())
return bool(get_queries()) or not is_available()
def process_request(self, request):
pass
@@ -40,12 +89,12 @@ class SQLAlchemyDebugPanel(DebugPanel):
return _('SQLAlchemy')
def nav_subtitle(self):
if not json_available or not sqlalchemy_available:
count = len(get_queries())
if not count and not is_available():
return 'Unavailable'
if get_debug_queries:
count = len(get_debug_queries())
return "%d %s" % (count, "query" if count == 1 else "queries")
return '%d %s' % (count, 'query' if count == 1 else 'queries')
def title(self):
return _('SQLAlchemy queries')
@@ -54,63 +103,42 @@ class SQLAlchemyDebugPanel(DebugPanel):
return ''
def content(self):
if not json_available or not sqlalchemy_available:
msg = ['Missing required libraries:', '<ul>']
if not json_available:
msg.append('<li>simplejson</li>')
if not sqlalchemy_available:
msg.append('<li>Flask-SQLAlchemy</li>')
msg.append('</ul>')
return '\n'.join(msg)
queries = get_queries()
if not queries and not is_available():
return self.render('panels/sqlalchemy_error.html', {
'sqlalchemy_available': sqlalchemy_available,
'extension_used': extension_used(),
'recording_enabled': recording_enabled(),
})
queries = get_debug_queries()
data = []
for query in queries:
is_select = query.statement.strip().lower().startswith('select')
_params = ''
try:
_params = json.dumps(query.parameters)
except TypeError:
pass # object not JSON serializable
hash = hashlib.sha1(
current_app.config['SECRET_KEY'] +
query.statement + _params).hexdigest()
data.append({
'duration': query.duration,
'sql': format_sql(query.statement, query.parameters),
'raw_sql': query.statement,
'hash': hash,
'params': _params,
'is_select': is_select,
'signed_query': dump_query(query.statement, query.parameters),
'context_long': query.context,
'context': format_fname(query.context)
})
return self.render('panels/sqlalchemy.html', { 'queries': data})
return self.render('panels/sqlalchemy.html', {'queries': data})
# Panel views
@module.route('/sqlalchemy/sql_select', methods=['GET', 'POST'])
def sql_select():
statement = request.args['sql']
params = request.args['params']
# Validate hash
hash = hashlib.sha1(
current_app.config['SECRET_KEY'] + statement + params).hexdigest()
if hash != request.args['hash']:
return abort(406)
# Make sure it is a select statement
if not statement.lower().strip().startswith('select'):
return abort(406)
params = json.loads(params)
@module.route('/sqlalchemy/sql_explain', methods=['GET', 'POST'],
defaults=dict(explain=True))
def sql_select(explain=False):
statement, params = load_query(request.args['query'])
engine = SQLAlchemy().get_engine(current_app)
if explain:
if engine.driver == 'pysqlite':
statement = 'EXPLAIN QUERY PLAN\n%s' % statement
else:
statement = 'EXPLAIN\n%s' % statement
result = engine.execute(statement, params)
return g.debug_toolbar.render('panels/sqlalchemy_select.html', {
'result': result.fetchall(),
@@ -118,35 +146,3 @@ def sql_select():
'sql': format_sql(statement, params),
'duration': float(request.args['duration']),
})
@module.route('/sqlalchemy/sql_explain', methods=['GET', 'POST'])
def sql_explain():
statement = request.args['sql']
params = request.args['params']
# Validate hash
hash = hashlib.sha1(
current_app.config['SECRET_KEY'] + statement + params).hexdigest()
if hash != request.args['hash']:
return abort(406)
# Make sure it is a select statement
if not statement.lower().strip().startswith('select'):
return abort(406)
params = json.loads(params)
engine = SQLAlchemy().get_engine(current_app)
if engine.driver == 'pysqlite':
query = 'EXPLAIN QUERY PLAN %s' % statement
else:
query = 'EXPLAIN %s' % statement
result = engine.execute(query, params)
return g.debug_toolbar.render('panels/sqlalchemy_explain.html', {
'result': result.fetchall(),
'headers': result.keys(),
'sql': format_sql(statement, params),
'duration': float(request.args['duration']),
})

View File

@@ -1,11 +1,12 @@
import collections
import json
import sys
import traceback
import uuid
from jinja2.exceptions import TemplateSyntaxError
from flask import template_rendered, request, g, render_template_string, Response, current_app, abort, url_for
from flask import (
template_rendered, request, g,
Response, current_app, abort, url_for
)
from flask_debugtoolbar import module
from flask_debugtoolbar.panels import DebugPanel
@@ -77,18 +78,28 @@ def require_enabled():
abort(403)
def _get_source(template):
with open(template.filename, 'rb') as fp:
source = fp.read()
return source.decode(_template_encoding())
def _template_encoding():
return getattr(current_app.jinja_loader, 'encoding', 'utf-8')
@module.route('/template/<key>')
def template_editor(key):
require_enabled()
# TODO set up special loader that caches templates it loads
# and can override template contents
templates = [t['template'] for t in TemplateDebugPanel.get_cache_for_key(key)]
templates = [t['template'] for t in
TemplateDebugPanel.get_cache_for_key(key)]
return g.debug_toolbar.render('panels/template_editor.html', {
'static_path': url_for('_debug_toolbar.static', filename=''),
'request': request,
'templates': [
{'name': t.name,
'source': open(t.filename).read()}
{'name': t.name, 'source': _get_source(t)}
for t in templates
]
})
@@ -98,8 +109,8 @@ def template_editor(key):
def save_template(key):
require_enabled()
template = TemplateDebugPanel.get_cache_for_key(key)[0]['template']
content = request.form['content']
with open(template.filename, 'w') as fp:
content = request.form['content'].encode(_template_encoding())
with open(template.filename, 'wb') as fp:
fp.write(content)
return 'ok'
@@ -119,6 +130,7 @@ def template_preview(key):
while tb.tb_next:
tb = tb.tb_next
msg = {'lineno': tb.tb_lineno, 'error': str(e)}
return Response(json.dumps(msg), status=400, mimetype='application/json')
return Response(json.dumps(msg), status=400,
mimetype='application/json')
finally:
del tb

View File

@@ -1,18 +1,19 @@
try:
import resource
except ImportError:
pass # Will fail on Win32 systems
pass # Will fail on Win32 systems
import time
from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x
class TimerDebugPanel(DebugPanel):
"""
Panel that displays the time a response took in milliseconds.
"""
name = 'Timer'
try: # if resource module not available, don't show content panel
try: # if resource module not available, don't show content panel
resource
except NameError:
has_content = False
@@ -36,13 +37,14 @@ class TimerDebugPanel(DebugPanel):
def nav_subtitle(self):
# TODO l10n
if self.has_resource:
utime = self._end_rusage.ru_utime - self._start_rusage.ru_utime
stime = self._end_rusage.ru_stime - self._start_rusage.ru_stime
return 'CPU: %0.2fms (%0.2fms)' % ((utime + stime) * 1000.0, self.total_time)
else:
if not self.has_resource:
return 'TOTAL: %0.2fms' % (self.total_time)
utime = self._end_rusage.ru_utime - self._start_rusage.ru_utime
stime = self._end_rusage.ru_stime - self._start_rusage.ru_stime
return 'CPU: %0.2fms (%0.2fms)' % (
(utime + stime) * 1000.0, self.total_time)
def title(self):
return _('Resource Usage')
@@ -50,7 +52,8 @@ class TimerDebugPanel(DebugPanel):
return ''
def _elapsed_ru(self, name):
return getattr(self._end_rusage, name) - getattr(self._start_rusage, name)
return (getattr(self._end_rusage, name)
- getattr(self._start_rusage, name))
def content(self):
@@ -58,8 +61,8 @@ class TimerDebugPanel(DebugPanel):
stime = 1000 * self._elapsed_ru('ru_stime')
vcsw = self._elapsed_ru('ru_nvcsw')
ivcsw = self._elapsed_ru('ru_nivcsw')
minflt = self._elapsed_ru('ru_minflt')
majflt = self._elapsed_ru('ru_majflt')
# minflt = self._elapsed_ru('ru_minflt')
# majflt = self._elapsed_ru('ru_majflt')
# these are documented as not meaningful under Linux. If you're running BSD
# feel free to enable them, and add any others that I hadn't gotten to before
@@ -80,9 +83,9 @@ class TimerDebugPanel(DebugPanel):
(_('Total CPU time'), '%0.3f msec' % (utime + stime)),
(_('Elapsed time'), '%0.3f msec' % self.total_time),
(_('Context switches'), '%d voluntary, %d involuntary' % (vcsw, ivcsw)),
# ('Memory use', '%d max RSS, %d shared, %d unshared' % (rss, srss, urss + usrss)),
# ('Page faults', '%d no i/o, %d requiring i/o' % (minflt, majflt)),
# ('Disk operations', '%d in, %d out, %d swapout' % (blkin, blkout, swap)),
# ('Memory use', '%d max RSS, %d shared, %d unshared' % (rss, srss, urss + usrss)),
# ('Page faults', '%d no i/o, %d requiring i/o' % (minflt, majflt)),
# ('Disk operations', '%d in, %d out, %d swapout' % (blkin, blkout, swap)),
)
context = self.context.copy()
@@ -91,4 +94,3 @@ class TimerDebugPanel(DebugPanel):
})
return self.render('panels/timer.html', context)

View File

@@ -1,14 +1,28 @@
import os
from distutils.sysconfig import get_python_lib
from flask import __version__ as flask_version
from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x
def relpath(location, python_lib):
location = os.path.normpath(location)
relative = os.path.relpath(location, python_lib)
if relative == os.path.curdir:
return ''
elif relative.startswith(os.path.pardir):
return location
return relative
class VersionDebugPanel(DebugPanel):
"""
Panel that displays the Flask version.
"""
name = 'Version'
has_content = False
has_content = True
def nav_title(self):
return _('Versions')
@@ -23,6 +37,16 @@ class VersionDebugPanel(DebugPanel):
return _('Versions')
def content(self):
return None
try:
import pkg_resources
except ImportError:
packages = []
else:
packages = sorted(pkg_resources.working_set,
key=lambda p: p.project_name.lower())
return self.render('panels/versions.html', {
'packages': packages,
'python_lib': os.path.normpath(get_python_lib()),
'relpath': relpath,
})

View File

@@ -1,395 +1,355 @@
/* Debug Toolbar CSS Reset, adapted from Eric Meyer's CSS Reset */
#flDebug, #flDebug * {
margin:0;
padding:0;
border:0;
outline:0;
font-size:12px;
line-height:1.5em;
color:#000;
vertical-align:baseline;
background: none;
font-family: inherit;
text-align:left;
margin:0;
padding:0;
border:0;
outline:0;
font-size:12px;
line-height:1.5em;
color:#000;
vertical-align:baseline;
background: none;
font-family: inherit;
text-align:left;
}
#flDebug { font-family: sans-serif; color: #000; background: #fff; }
#flDebug tbody, #flDebug code {
#flDebug tbody, #flDebug code, #flDebug pre {
font-family: Consolas, Monaco, "Bitstream Vera Sans Mono", "Lucida Console", monospace;
}
#flDebug #flDebugToolbar {
background:#111;
width:200px;
z-index:100000000;
position:fixed;
top:0;
bottom:0;
right:0;
opacity:0.9;
background:#111;
width:200px;
z-index:100000000;
position:fixed;
top:0;
bottom:0;
right:0;
opacity:0.9;
}
#flDebug #flDebugToolbar small {
color:#999;
color:#999;
}
#flDebug #flDebugToolbar ul {
margin:0;
padding:0;
list-style:none;
margin:0;
padding:0;
list-style:none;
}
#flDebug #flDebugToolbar li {
border-bottom:1px solid #222;
color:#fff;
display:block;
font-weight:bold;
float:none;
margin:0;
padding:0;
position:relative;
width:auto;
border-bottom:1px solid #222;
color:#fff;
display:block;
font-weight:bold;
float:none;
margin:0;
padding:0;
position:relative;
width:auto;
}
#flDebug #flDebugToolbar li>a,
#flDebug #flDebugToolbar li>div.contentless {
font-weight:normal;
font-style:normal;
text-decoration:none;
display:block;
font-size:16px;
padding:10px 10px 5px 25px;
color:#fff;
#flDebug #flDebugToolbar li>div.flDebugContentless {
font-weight:normal;
font-style:normal;
text-decoration:none;
display:block;
font-size:16px;
padding:10px 10px 5px 25px;
color:#fff;
}
#flDebug #flDebugToolbar li a:hover {
color:#111;
background-color:#ffc;
color:#111;
background-color:#ffc;
}
#flDebug #flDebugToolbar li.active {
background-image:url(../img/indicator.png);
background-repeat:no-repeat;
background-position:left center;
background-color:#333;
padding-left:10px;
#flDebug #flDebugToolbar li.flDebugActive {
background-image:url(../img/indicator.png);
background-repeat:no-repeat;
background-position:left center;
background-color:#333;
padding-left:10px;
}
#flDebug #flDebugToolbar li.active a:hover {
color:#b36a60;
background-color:transparent;
#flDebug #flDebugToolbar li.flDebugActive a:hover {
color:#b36a60;
background-color:transparent;
}
#flDebug #flDebugToolbar li small {
font-size:12px;
color:#999;
font-style:normal;
text-decoration:none;
font-variant:small-caps;
font-size:12px;
color:#999;
font-style:normal;
text-decoration:none;
font-variant:small-caps;
}
#flDebug #flDebugToolbar li .switch {
font-size: 10px;
position: absolute;
display: block;
color: white;
height: 16px;
width: 16px;
cursor: pointer;
top: 15px;
right: 2px;
#flDebug #flDebugToolbar li .flDebugSwitch {
font-size: 10px;
position: absolute;
display: block;
color: white;
height: 16px;
width: 16px;
cursor: pointer;
top: 15px;
right: 2px;
}
#flDebug #flDebugToolbar li .switch.active {
background-image: url(../img/tick.png);
#flDebug #flDebugToolbar li .flDebugSwitch.flDebugActive {
background-image: url(../img/tick.png);
}
#flDebug #flDebugToolbar li .switch.inactive {
background-image: url(../img/tick-red.png);
#flDebug #flDebugToolbar li .flDebugSwitch.flDebugInactive {
background-image: url(../img/tick-red.png);
}
#flDebug #flDebugToolbarHandle {
position:fixed;
background:#fff;
border:1px solid #111;
top:30px;
right:0;
z-index:100000000;
opacity:0.75;
position:fixed;
background:#fff;
border:1px solid #111;
top:30px;
right:0;
z-index:100000000;
opacity:0.75;
}
#flDebug a#flShowToolBarButton {
display:block;
height:75px;
width:30px;
border-right:none;
border-bottom:4px solid #fff;
border-top:4px solid #fff;
border-left:4px solid #fff;
color:#fff;
font-size:10px;
font-weight:bold;
text-decoration:none;
text-align:center;
text-indent:-999999px;
background:#000 url(../img/djdt_vertical.png) no-repeat left center;
opacity:0.5;
#flDebug a#flDebugShowToolBarButton {
display:block;
height:75px;
width:30px;
border-right:none;
border-bottom:4px solid #fff;
border-top:4px solid #fff;
border-left:4px solid #fff;
color:#fff;
font-size:10px;
font-weight:bold;
text-decoration:none;
text-align:center;
text-indent:-999999px;
background:#000 url(../img/djdt_vertical.png) no-repeat left center;
opacity:0.5;
}
#flDebug a#flShowToolBarButton:hover {
background-color:#111;
padding-right:6px;
border-top-color:#FFE761;
border-left-color:#FFE761;
border-bottom-color:#FFE761;
opacity:1.0;
#flDebug a#flDebugShowToolBarButton:hover {
background-color:#111;
padding-right:6px;
border-top-color:#FFE761;
border-left-color:#FFE761;
border-bottom-color:#FFE761;
opacity:1.0;
}
#flDebug code {
display:block;
white-space:pre;
overflow:auto;
display:inline;
white-space:pre;
overflow:auto;
}
#flDebug tr.flDebugOdd {
background-color:#f5f5f5;
background-color:#f5f5f5;
}
#flDebug .panelContent {
display:none;
position:fixed;
margin:0;
top:0;
right:200px;
bottom:0;
left:0px;
background-color:#eee;
color:#666;
z-index:100000000;
#flDebug .flDebugPanelContentParent {
display:none;
position:fixed;
margin:0;
top:0;
right:200px;
bottom:0;
left:0px;
background-color:#eee;
color:#666;
z-index:100000000;
}
#flDebug .panelContent > div {
border-bottom:1px solid #ddd;
#flDebug .flDebugPanelContentParent > div {
border-bottom:1px solid #ddd;
}
#flDebug .flDebugPanelTitle {
position:absolute;
background-color:#ffc;
color:#666;
padding-left:20px;
top:0;
right:0;
left:0;
height:50px;
position:absolute;
background-color:#ffc;
color:#666;
padding-left:20px;
top:0;
right:0;
left:0;
height:50px;
}
#flDebug .flDebugPanelTitle code {
display:inline;
font-size:inherit;
display:inline;
font-size:inherit;
}
#flDebug .flDebugPanelContent {
position:absolute;
top:50px;
right:0;
bottom:0;
left:0;
height:auto;
padding:0 0 0 20px;
position:absolute;
top:50px;
right:0;
bottom:0;
left:0;
height:auto;
padding:0 0 0 20px;
}
#flDebug .flDebugPanelContent .scroll {
height:100%;
overflow:auto;
display:block;
padding:0 10px 0 0;
height:100%;
overflow:auto;
display:block;
padding:0 10px 0 0;
}
#flDebug h3 {
font-size:24px;
font-weight:normal;
line-height:50px;
font-size:24px;
font-weight:normal;
line-height:50px;
}
#flDebug h4 {
font-size:20px;
font-weight:bold;
margin-top:0.8em;
font-size:20px;
font-weight:bold;
margin-top:0.8em;
}
#flDebug .panelContent table {
border:1px solid #ccc;
border-collapse:collapse;
width:100%;
background-color:#fff;
display:block;
margin-top:0.8em;
overflow: auto;
#flDebug h5 {
font-size: 14px;
}
#flDebug .panelContent tbody td,
#flDebug .panelContent tbody th {
vertical-align:top;
padding:2px 3px;
#flDebug .flDebugPanelContentParent table {
border:1px solid #ccc;
border-collapse:collapse;
width:100%;
background-color:#fff;
display:block;
margin-top:0.8em;
overflow: auto;
}
#flDebug .panelContent thead th {
padding:1px 6px 1px 3px;
text-align:left;
font-weight:bold;
font-size:14px;
#flDebug .flDebugPanelContentParent tbody td,
#flDebug .flDebugPanelContentParent tbody th {
vertical-align:top;
padding:2px 3px;
}
#flDebug .panelContent tbody th {
width:12em;
text-align:right;
color:#666;
padding-right:.5em;
#flDebug .flDebugPanelContentParent thead th {
padding:1px 6px 1px 3px;
text-align:left;
font-weight:bold;
font-size:14px;
}
#flDebug .flDebugPanelContentParent tbody th {
width:12em;
text-align:right;
color:#666;
padding-right:.5em;
}
#flDebug .flDebugPanelContentParent ol li {
margin: 0 0 1em 2em;
}
#flDebug .flDebugPanelContentParent pre {
border:1px solid #ccc;
background-color:#fff;
display:block;
margin:0.8em 0;
padding: 0.2em 0.5em;
}
#flDebug .flTemplateHideContextDiv {
background-color:#fff;
background-color:#fff;
}
/*
#flDebug .panelContent p a:hover, #flDebug .panelContent dd a:hover {
color:#111;
background-color:#ffc;
#flDebug .flDebugPanelContentParent .flDebugClose {
text-indent:-9999999px;
display:block;
position:absolute;
top:4px;
right:15px;
height:40px;
width:40px;
background:url(../img/close.png) no-repeat center center;
}
#flDebug .panelContent p {
padding:0 5px;
#flDebug .flDebugPanelContentParent .flDebugClose:hover {
background-image:url(../img/close_hover.png);
}
#flDebug .panelContent p, #flDebug .panelContent table, #flDebug .panelContent ol, #flDebug .panelContent ul, #flDebug .panelContent dl {
margin:5px 0 15px;
background-color:#fff;
}
#flDebug .panelContent table {
clear:both;
border:0;
padding:0;
margin:0;
border-collapse:collapse;
border-spacing:0;
#flDebug .flDebugPanelContentParent .flDebugClose.flDebugBack {
background-image:url(../img/back.png);
}
#flDebug .panelContent table a {
color:#000;
padding:2px 4px;
}
#flDebug .panelContent table a:hover {
background-color:#ffc;
#flDebug .flDebugPanelContentParent .flDebugClose.flDebugBack:hover {
background-image:url(../img/back_hover.png);
}
#flDebug .panelContent table th {
background-color:#333;
font-weight:bold;
color:#fff;
padding:3px 7px 3px;
text-align:left;
cursor:pointer;
}
#flDebug .panelContent table td {
padding:5px 10px;
font-size:14px;
background:#fff;
color:#000;
vertical-align:top;
border:0;
}
#flDebug .panelContent table tr.flDebugOdd td {
background:#eee;
}
*/
#flDebug .panelContent .flDebugClose {
text-indent:-9999999px;
display:block;
position:absolute;
top:4px;
right:15px;
height:40px;
width:40px;
background:url(../img/close.png) no-repeat center center;
#flDebug .flDebugPanelContentParent dt, #flDebug .flDebugPanelContentParent dd {
display:block;
}
#flDebug .panelContent .flDebugClose:hover {
background-image:url(../img/close_hover.png);
#flDebug .flDebugPanelContentParent dt {
margin-top:0.75em;
}
#flDebug .panelContent .flDebugClose.flDebugBack {
background-image:url(../img/back.png);
#flDebug .flDebugPanelContentParent dd {
margin-left:10px;
}
#flDebug .panelContent .flDebugClose.flDebugBack:hover {
background-image:url(../img/back_hover.png);
#flDebug a.flDebugToggleTemplate {
padding:4px;
background-color:#bbb;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
#flDebug .panelContent dt, #flDebug .panelContent dd {
display:block;
}
#flDebug .panelContent dt {
margin-top:0.75em;
}
#flDebug .panelContent dd {
margin-left:10px;
}
#flDebug a.toggleTemplate {
padding:4px;
background-color:#bbb;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
#flDebug a.toggleTemplate:hover {
padding:4px;
background-color:#444;
color:#ffe761;
-moz-border-radius:3px;
-webkit-border-radius:3px;
#flDebug a.flDebugToggleTemplate:hover {
padding:4px;
background-color:#444;
color:#ffe761;
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
#flDebug a.flTemplateShowContext, #flDebug a.flTemplateShowContext span.toggleArrow {
color:#999;
#flDebug a.flDebugTemplateShowContext, #flDebug a.flDebugTemplateShowContext span.flDebugToggleArrow {
color:#999;
}
#flDebug a.flTemplateShowContext:hover, #flDebug a.flTemplateShowContext:hover span.toggleArrow {
color:#000;
cursor:pointer;
#flDebug a.flDebugTemplateShowContext:hover, #flDebug a.flDebugTemplateShowContext:hover span.flDebugToggleArrow {
color:#000;
cursor:pointer;
}
#flDebug .flDebugSqlWrap {
position:relative;
position:relative;
}
#flDebug .flDebugSql {
z-index:100000002;
z-index:100000002;
}
#flDebug .flSQLHideStacktraceDiv tbody th {
text-align: left;
}
#flDebug .flSqlExplain td {
white-space: pre;
#flDebug .flDebugHideStacktraceDiv tbody th {
text-align: left;
}
#flDebug span.flDebugLineChart {
background-color:#777;
height:3px;
position:absolute;
bottom:0;
top:0;
left:0;
display:block;
z-index:1000000001;
background-color:#777;
height:3px;
position:absolute;
bottom:0;
top:0;
left:0;
display:block;
z-index:1000000001;
}
#flDebug span.flDebugLineChartWarning {
background-color:#900;
background-color:#900;
}
#flDebug .highlight { color:#000; }
@@ -413,25 +373,25 @@
#flDebug .highlight .cp { color:#333 } /* Comment.Preproc */
/* tablesorted */
#flDebug table.tablesorter {
width: 100%;
#flDebug table.flDebugTablesorter {
width: 100%;
}
#flDebug table.tablesorter thead th, table.tablesorter tfoot th {
padding-right: 20px;
#flDebug table.flDebugTablesorter thead th, table.flDebugTablesorter tfoot th {
padding-right: 20px;
}
#flDebug table.tablesorter thead th {
background: url(../img/bg.gif) center right no-repeat;
cursor: pointer;
#flDebug table.flDebugTablesorter thead th {
background: url(../img/bg.gif) center right no-repeat;
cursor: pointer;
}
#flDebug table.tablesorter tbody tr.odd td {
background-color: #F0F0F6;
#flDebug table.flDebugTablesorter tbody tr.odd td {
background-color: #F0F0F6;
}
#flDebug table.tablesorter thead .headerSortUp {
background-image: url(../img/asc.gif);
#flDebug table.flDebugTablesorter thead .headerSortUp {
background-image: url(../img/asc.gif);
}
#flDebug table.tablesorter thead .headerSortDown {
background-image: url(../img/desc.gif);
#flDebug table.flDebugTablesorter thead .headerSortDown {
background-image: url(../img/desc.gif);
}
#flDebug table.tablesorter thead .headerSortDown, #flDebug table.tablesorter thead .headerSortUp {
background-color: #8dbdd8;
#flDebug table.flDebugTablesorter thead .headerSortDown, #flDebug table.flDebugTablesorter thead .headerSortUp {
background-color: #8dbdd8;
}

View File

@@ -1,193 +1,192 @@
(function($) {
$.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); } var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = $.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };
$('head').append('<link rel="stylesheet" href="'+DEBUG_TOOLBAR_STATIC_PATH+'css/toolbar.css?'+ Math.random() +'" type="text/css" />');
var COOKIE_NAME = 'fldt';
var COOKIE_NAME_ACTIVE = COOKIE_NAME +'_active';
var fldt = {
init: function() {
$('#flDebug').show();
var current = null;
$('#flDebugPanelList li a').click(function() {
if (!this.className) {
return false;
}
current = $('#flDebug #' + this.className + '-content');
if (current.is(':visible')) {
$(document).trigger('close.flDebug');
$(this).parent().removeClass('active');
} else {
$('.panelContent').hide(); // Hide any that are already open
current.show();
$('#flDebugToolbar li').removeClass('active');
$(this).parent().addClass('active');
}
return false;
});
$('#flDebugPanelList li .switch').click(function() {
var $panel = $(this).parent();
var $this = $(this);
var dom_id = $panel.attr('id');
// Turn cookie content into an array of active panels
var active_str = $.cookie(COOKIE_NAME_ACTIVE);
var active = (active_str) ? active_str.split(';') : [];
active = $.grep(active, function(n,i) { return n != dom_id; });
if ($this.hasClass('active')) {
$this.removeClass('active');
$this.addClass('inactive');
}
else {
active.push(dom_id);
$this.removeClass('inactive');
$this.addClass('active');
}
if (active.length > 0) {
$.cookie(COOKIE_NAME_ACTIVE, active.join(';'), {
path: '/', expires: 10
});
}
else {
$.cookie(COOKIE_NAME_ACTIVE, null, {
path: '/', expires: -1
});
}
});
$('#flDebug a.flDebugClose').click(function() {
$(document).trigger('close.flDebug');
$('#flDebugToolbar li').removeClass('active');
return false;
});
$('#flDebug a.remoteCall').click(function() {
$('#flDebugWindow').load(this.href, {}, function() {
$('#flDebugWindow a.flDebugBack').click(function() {
$(this).parent().parent().hide();
return false;
});
});
$('#flDebugWindow').show();
return false;
});
$('#flDebugTemplatePanel a.flTemplateShowContext').click(function() {
fldt.toggle_arrow($(this).children('.toggleArrow'))
fldt.toggle_content($(this).parent().next());
return false;
});
$('#flDebugSQLPanel a.flSQLShowStacktrace').click(function() {
fldt.toggle_content($('.flSQLHideStacktraceDiv', $(this).parents('tr')));
return false;
});
$('#flHideToolBarButton').click(function() {
fldt.hide_toolbar(true);
return false;
});
$('#flShowToolBarButton').click(function() {
fldt.show_toolbar();
return false;
});
$(document).bind('close.flDebug', function() {
// If a sub-panel is open, close that
if ($('#flDebugWindow').is(':visible')) {
$('#flDebugWindow').hide();
return;
}
// If a panel is open, close that
if ($('.panelContent').is(':visible')) {
$('.panelContent').hide();
return;
}
// Otherwise, just minimize the toolbar
if ($('#flDebugToolbar').is(':visible')) {
fldt.hide_toolbar(true);
return;
}
});
if ($.cookie(COOKIE_NAME)) {
fldt.hide_toolbar(false);
} else {
fldt.show_toolbar(false);
}
$('#flDebug table.tablesorter')
.tablesorter()
.bind('sortStart', function() {
$(this).find('tbody tr')
.removeClass('flDebugEven')
.removeClass('flDebugOdd');
})
.bind('sortEnd', function() {
$(this).find('tbody tr').each(function(idx, elem) {
var even = idx % 2 == 0;
$(elem)
.toggleClass('flDebugEven', even)
.toggleClass('flDebugOdd', !even);
});
});
},
toggle_content: function(elem) {
if (elem.is(':visible')) {
elem.hide();
} else {
elem.show();
}
},
close: function() {
$(document).trigger('close.flDebug');
return false;
},
hide_toolbar: function(setCookie) {
// close any sub panels
$('#flDebugWindow').hide();
// close all panels
$('.panelContent').hide();
$('#flDebugToolbar li').removeClass('active');
// finally close toolbar
$('#flDebugToolbar').hide('fast');
$('#flDebugToolbarHandle').show();
// Unbind keydown
$(document).unbind('keydown.flDebug');
if (setCookie) {
$.cookie(COOKIE_NAME, 'hide', {
path: '/',
expires: 10
});
}
},
show_toolbar: function(animate) {
// Set up keybindings
$(document).bind('keydown.flDebug', function(e) {
if (e.keyCode == 27) {
fldt.close();
}
});
$('#flDebugToolbarHandle').hide();
if (animate) {
$('#flDebugToolbar').show('fast');
} else {
$('#flDebugToolbar').show();
}
$.cookie(COOKIE_NAME, null, {
path: '/',
expires: -1
});
},
toggle_arrow: function(elem) {
var uarr = String.fromCharCode(0x25b6);
var darr = String.fromCharCode(0x25bc);
elem.html(elem.html() == uarr ? darr : uarr);
},
load_href: function(href) {
$.get(href, function(data, status, xhr) {
document.open();
document.write(xhr.responseText);
document.close();
});
$.cookie = function(name, value, options) { if (typeof value != 'undefined') { options = options || {}; if (value === null) { value = ''; options.expires = -1; } var expires = ''; if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { var date; if (typeof options.expires == 'number') { date = new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires = '; expires=' + date.toUTCString(); } var path = options.path ? '; path=' + (options.path) : ''; var domain = options.domain ? '; domain=' + (options.domain) : ''; var secure = options.secure ? '; secure' : ''; document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue = null; if (document.cookie && document.cookie != '') { var cookies = document.cookie.split(';'); for (var i = 0; i < cookies.length; i++) { var cookie = $.trim(cookies[i]); if (cookie.substring(0, name.length + 1) == (name + '=')) { cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); break; } } } return cookieValue; } };
$('head').append('<link rel="stylesheet" href="'+DEBUG_TOOLBAR_STATIC_PATH+'css/toolbar.css?'+ Math.random() +'" type="text/css" />');
var COOKIE_NAME = 'fldt';
var COOKIE_NAME_ACTIVE = COOKIE_NAME +'_active';
var fldt = {
init: function() {
$('#flDebug').show();
var current = null;
$('#flDebugPanelList li a').click(function() {
if (!this.className) {
return false;
}
};
$(document).ready(function() {
fldt.init();
});
window.fldt = fldt;
current = $('#flDebug #' + this.className + '-content');
if (current.is(':visible')) {
$(document).trigger('close.flDebug');
$(this).parent().removeClass('flDebugActive');
} else {
$('.flDebugPanelContentParent').hide(); // Hide any that are already open
current.show();
$('#flDebugToolbar li').removeClass('flDebugActive');
$(this).parent().addClass('flDebugActive');
}
return false;
});
$('#flDebugPanelList li .flDebugSwitch').click(function() {
var $panel = $(this).parent();
var $this = $(this);
var dom_id = $panel.attr('id');
// Turn cookie content into an array of active panels
var active_str = $.cookie(COOKIE_NAME_ACTIVE);
var active = (active_str) ? active_str.split(';') : [];
active = $.grep(active, function(n,i) { return n != dom_id; });
if ($this.hasClass('flDebugActive')) {
$this.removeClass('flDebugActive');
$this.addClass('flDebugInactive');
} else {
active.push(dom_id);
$this.removeClass('flDebugInactive');
$this.addClass('flDebugActive');
}
if (active.length > 0) {
$.cookie(COOKIE_NAME_ACTIVE, active.join(';'), {
path: '/', expires: 10
});
} else {
$.cookie(COOKIE_NAME_ACTIVE, null, {
path: '/', expires: -1
});
}
});
$('#flDebug a.flDebugClose').click(function() {
$(document).trigger('close.flDebug');
$('#flDebugToolbar li').removeClass('flDebugActive');
return false;
});
$('#flDebug a.flDebugRemoteCall').click(function() {
$('#flDebugWindow').load(this.href, {}, function() {
$('#flDebugWindow a.flDebugBack').click(function() {
$(this).parent().parent().hide();
return false;
});
});
$('#flDebugWindow').show();
return false;
});
$('#flDebugTemplatePanel a.flDebugTemplateShowContext').click(function() {
fldt.toggle_arrow($(this).children('.flDebugToggleArrow'))
fldt.toggle_content($(this).parent().next());
return false;
});
$('#flDebugSQLPanel a.flDebugShowStacktrace').click(function() {
fldt.toggle_content($('.flDebugHideStacktraceDiv', $(this).parents('tr')));
return false;
});
$('#flDebugHideToolBarButton').click(function() {
fldt.hide_toolbar(true);
return false;
});
$('#flDebugShowToolBarButton').click(function() {
fldt.show_toolbar();
return false;
});
$(document).bind('close.flDebug', function() {
// If a sub-panel is open, close that
if ($('#flDebugWindow').is(':visible')) {
$('#flDebugWindow').hide();
return;
}
// If a panel is open, close that
if ($('.flDebugPanelContentParent').is(':visible')) {
$('.flDebugPanelContentParent').hide();
return;
}
// Otherwise, just minimize the toolbar
if ($('#flDebugToolbar').is(':visible')) {
fldt.hide_toolbar(true);
return;
}
});
if ($.cookie(COOKIE_NAME)) {
fldt.hide_toolbar(false);
} else {
fldt.show_toolbar(false);
}
$('#flDebug table.flDebugTablesorter').each(function() {
var headers = {};
$(this).find('thead th').each(function(idx, elem) {
headers[idx] = $(elem).data();
});
$(this).tablesorter({headers: headers});
})
.bind('sortEnd', function() {
$(this).find('tbody tr').each(function(idx, elem) {
var even = idx % 2 === 0;
$(elem)
.toggleClass('flDebugEven', even)
.toggleClass('flDebugOdd', !even);
});
});
},
toggle_content: function(elem) {
if (elem.is(':visible')) {
elem.hide();
} else {
elem.show();
}
},
close: function() {
$(document).trigger('close.flDebug');
return false;
},
hide_toolbar: function(setCookie) {
// close any sub panels
$('#flDebugWindow').hide();
// close all panels
$('.flDebugPanelContentParent').hide();
$('#flDebugToolbar li').removeClass('flDebugActive');
// finally close toolbar
$('#flDebugToolbar').hide('fast');
$('#flDebugToolbarHandle').show();
// Unbind keydown
$(document).unbind('keydown.flDebug');
if (setCookie) {
$.cookie(COOKIE_NAME, 'hide', {
path: '/',
expires: 10
});
}
},
show_toolbar: function(animate) {
// Set up keybindings
$(document).bind('keydown.flDebug', function(e) {
if (e.keyCode == 27) {
fldt.close();
}
});
$('#flDebugToolbarHandle').hide();
if (animate) {
$('#flDebugToolbar').show('fast');
} else {
$('#flDebugToolbar').show();
}
$.cookie(COOKIE_NAME, null, {
path: '/',
expires: -1
});
},
toggle_arrow: function(elem) {
var uarr = String.fromCharCode(0x25b6);
var darr = String.fromCharCode(0x25bc);
elem.html(elem.html() == uarr ? darr : uarr);
},
load_href: function(href) {
$.get(href, function(data, status, xhr) {
document.open();
document.write(xhr.responseText);
document.close();
});
return false;
},
$: $
};
$(document).ready(function() {
fldt.init();
});
window.fldt = fldt;
})(jQuery.noConflict(true));

View File

@@ -1,56 +1,57 @@
<div id="flDebug" style="display:none;">
<script type="text/javascript">var DEBUG_TOOLBAR_STATIC_PATH = '{{ static_path }}'</script>
<script type="text/javascript" src="{{ static_path }}js/jquery.js"></script>
<script type="text/javascript" src="{{ static_path }}js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="{{ static_path }}js/toolbar.js"></script>
<script type="text/javascript">var DEBUG_TOOLBAR_STATIC_PATH = '{{ static_path }}'</script>
<script type="text/javascript" src="{{ static_path }}js/jquery.js"></script>
<script type="text/javascript" src="{{ static_path }}js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="{{ static_path }}js/toolbar.js"></script>
<div style="display: none;" id="flDebugToolbar">
<ol id="flDebugPanelList">
{% if panels %}
<li><a id="flHideToolBarButton" href="#" title="Hide Toolbar">Hide &raquo;</a></li>
{% else %}
<li id="flDebugButton">DEBUG</li>
{% endif %}
{% for panel in panels %}
<li id="{{ panel.dom_id() }}">
{% if panel.has_content %}
<a href="{{ panel.url()|default("#") }}" title="{{ panel.title() }}" class="{{ panel.dom_id() }}">
{% else %}
<div class="contentless">
{% endif %}
<div style="display: none;" id="flDebugToolbar">
<ol id="flDebugPanelList">
{% if panels %}
<li><a id="flDebugHideToolBarButton" href="#" title="Hide Toolbar">Hide &raquo;</a></li>
{% else %}
<li id="flDebugButton">DEBUG</li>
{% endif %}
{{ panel.nav_title() }}
{% if panel.nav_subtitle() %}<br /><small>{{ panel.nav_subtitle() }}</small>{% endif %}
{% for panel in panels %}
<li id="{{ panel.dom_id() }}">
{% if panel.has_content %}
<a href="{{ panel.url()|default("#") }}" title="{{ panel.title() }}" class="{{ panel.dom_id() }}">
{% else %}
<div class="flDebugContentless">
{% endif %}
{% if panel.has_content %}
</a>
{% else %}
</div>
{% endif %}
{% if panel.user_activate %}
<span class="switch {{ 'active' if panel.is_active else 'inactive' }}" title="Enable or disable the panel"></span>
{% endif %}
</li>
{% endfor %}
</ol>
{{ panel.nav_title() }}
{% if panel.nav_subtitle() %}<br /><small>{{ panel.nav_subtitle() }}</small>{% endif %}
{% if panel.has_content %}
</a>
{% else %}
</div>
{% endif %}
{% if panel.user_activate %}
<span class="flDebugSwitch {{ 'flDebugActive' if panel.is_active else 'flDebugInactive' }}" title="Enable or disable the panel"></span>
{% endif %}
</li>
{% endfor %}
</ol>
</div>
<div style="display:none;" id="flDebugToolbarHandle">
<a title="Show Toolbar" id="flDebugShowToolBarButton" href="#">&laquo;</a>
</div>
{% for panel in panels %}
{% if panel.has_content %}
<div id="{{ panel.dom_id() }}-content" class="flDebugPanelContentParent">
<div class="flDebugPanelTitle">
<a href="" class="flDebugClose">Close</a>
<h3>{{ panel.title()|safe }}</h3>
</div>
<div class="flDebugPanelContent">
<div class="flDebugScroll">
{{ panel.content()|safe }}
</div>
</div>
</div>
<div style="display:none;" id="flDebugToolbarHandle">
<a title="Show Toolbar" id="flShowToolBarButton" href="#">&laquo;</a>
</div>
{% for panel in panels %}
{% if panel.has_content %}
<div id="{{ panel.dom_id() }}-content" class="panelContent">
<div class="flDebugPanelTitle">
<a href="" class="flDebugClose">Close</a>
<h3>{{ panel.title()|safe }}</h3>
</div>
<div class="flDebugPanelContent">
<div class="scroll">
{{ panel.content()|safe }}
</div>
</div>
</div>
{% endif %}
{% endfor %}
<div id="flDebugWindow" class="panelContent"></div>
{% endif %}
{% endfor %}
<div id="flDebugWindow" class="flDebugPanelContentParent"></div>
</div>

View File

@@ -0,0 +1,16 @@
<table>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in config|dictsort %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key }}</td>
<td><code>{{ value|printable }}</code></td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -0,0 +1,16 @@
<table>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in g_content|dictsort %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|escape }}</td>
<td>{{ value|escape }}</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -1,16 +1,16 @@
<table>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in headers.iteritems() %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|escape }}</td>
<td>{{ value|escape }}</td>
</tr>
{% endfor %}
</tbody>
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in headers|dictsort %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|escape }}</td>
<td>{{ value|escape }}</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -1,26 +1,26 @@
{% if records %}
<table>
<thead>
<tr>
<th>Level</th>
<th>Time</th>
<th>Message</th>
<th>Location</th>
</tr>
</thead>
<tbody>
{% for record in records %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ record.level }}</td>
<td>{{ record.time }}</td>
<td>{{ record.message }}</td>
<td title="{{ record.file_long }}:{{ record.line }}">{{ record.file }}:{{ record.line }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table>
<thead>
<tr>
<th>Level</th>
<th>Time</th>
<th>Message</th>
<th>Location</th>
</tr>
</thead>
<tbody>
{% for record in records %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ record.level }}</td>
<td>{{ record.time }}</td>
<td>{{ record.message }}</td>
<td title="{{ record.file_long }}:{{ record.line }}">{{ record.file }}:{{ record.line }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No messages logged.</p>
<p>No messages logged.</p>
{% endif %}

View File

@@ -1,25 +1,24 @@
<table id="debug_toolbar_profiler_table" class="tablesorter">
<thead>
<tr>
<th>Calls</th>
<th>Total Time (ms)</th>
<th>Per Call (ms)</th>
<th>Cumulative Time (ms)</th>
<th>Per Call (ms)</th>
<th>Function</th>
</tr>
</thead>
<tbody>
{% for row in function_calls %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ row.ncalls }}</td>
<td>{{ row.tottime }}</td>
<td>{{ '%.4f'|format(row.percall) }}</td>
<td>{{ row.cumtime }}</td>
<td>{{ '%.4f'|format(row.percall_cum) }}</td>
<td title="{{ row.filename_long }}">{{ row.filename|escape }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table id="flDebugProfilerTable" class="flDebugTablesorter">
<thead>
<tr>
<th data-sorter="digit">Calls</th>
<th>Total Time (ms)</th>
<th>Per Call (ms)</th>
<th>Cumulative Time (ms)</th>
<th>Per Call (ms)</th>
<th data-sorter="text">Function</th>
</tr>
</thead>
<tbody>
{% for row in function_calls %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ row.ncalls }}</td>
<td>{{ row.tottime }}</td>
<td>{{ '%.4f'|format(row.percall) }}</td>
<td>{{ row.cumtime }}</td>
<td>{{ '%.4f'|format(row.percall_cum) }}</td>
<td title="{{ row.filename_long }}">{{ row.filename|escape }}</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -1,104 +1,104 @@
<h4>View information</h4>
<table>
<thead>
<tr>
<th>View Function</th>
<th>args</th>
<th>kwargs</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ view_func }}</td>
<td>{{ view_args|default("None") }}</td>
<td>
{% if view_kwargs.items() %}
{% for k, v in view_kwargs.items() %}
{{ k }}={{ v }}{% if not loop.last %}, {% endif %}
{% endfor %}
{% else %}
None
{% endif %}
</td>
</tr>
</tbody>
<thead>
<tr>
<th>View Function</th>
<th>args</th>
<th>kwargs</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ view_func }}</td>
<td>{{ view_args|default("None") }}</td>
<td>
{% if view_kwargs.items() %}
{% for k, v in view_kwargs.items() %}
{{ k }}={{ v }}{% if not loop.last %}, {% endif %}
{% endfor %}
{% else %}
None
{% endif %}
</td>
</tr>
</tbody>
</table>
{% macro show_map(map) %}
<table>
<colgroup>
<col style="width:20%"/>
<col/>
</colgroup>
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in map %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|printable }}</td>
<td>{{ value|printable }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table>
<colgroup>
<col style="width:20%"/>
<col/>
</colgroup>
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in map %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|printable }}</td>
<td>{{ value|printable }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endmacro %}
<h4>COOKIES Variables</h4>
{% if cookies %}
{{ show_map(cookies) }}
{{ show_map(cookies) }}
{% else %}
<p>No COOKIE data</p>
<p>No COOKIE data</p>
{% endif %}
<h4>SESSION Variables</h4>
{% if session %}
{{ show_map(session) }}
{{ show_map(session) }}
{% else %}
<p>No SESSION data</p>
<p>No SESSION data</p>
{% endif %}
{% macro show_multi_map(map) %}
<table>
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in map %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|printable }}</td>
<td>
{%- set sep = joiner() -%}
{%- for v in value -%}
{{ sep() }}{{ v|printable }}
{%- endfor -%}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<table>
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in map %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|printable }}</td>
<td>
{%- set sep = joiner() -%}
{%- for v in value -%}
{{ sep() }}{{ v|printable }}
{%- endfor -%}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endmacro %}
<h4>GET Variables</h4>
{% if get %}
{{ show_multi_map(get) }}
{{ show_multi_map(get) }}
{% else %}
<p>No GET data</p>
<p>No GET data</p>
{% endif %}
<h4>POST Variables</h4>
{% if post %}
{{ show_multi_map(post) }}
{{ show_multi_map(post) }}
{% else %}
<p>No POST data</p>
<p>No POST data</p>
{% endif %}

View File

@@ -0,0 +1,28 @@
<table>
<thead>
<tr>
<th>URL route</th>
<th>Endpoint name</th>
<th>HTTP methods</th>
<th>Is alias</th>
<th>Redirect to</th>
</tr>
</thead>
<tbody>
{% if routes %}
{% for route in routes|sort(attribute='rule') %}
<tr>
<td>{{ route.rule }}</td>
<td>{{ route.endpoint }}</td>
<td>{{ route.methods|sort|join(', ') }}</td>
<td>{{ route.alias }}</td>
<td>{{ route.redirect_to }}</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td>No routes have been configured.</td>
</tr>
{% endif %}
</tbody>
</table>

View File

@@ -1,68 +1,31 @@
<table>
<thead>
<tr>
<th>&nbsp;(ms)</th>
<th>Action</th>
<th>Context</th>
<th>Query</th>
</tr>
</thead>
<tbody>
{% for query in queries %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ '%.4f'|format(query.duration) }}</td>
<td>
{% if query.params %}
{% if query.is_select %}
<a class="remoteCall" href="/_debug_toolbar/views/sqlalchemy/sql_select?sql={{ query.raw_sql|urlencode }}&amp;params={{ query.params|urlencode }}&amp;duration={{ query.duration|urlencode }}&amp;hash={{ query.hash }}">SELECT</a><br />
<a class="remoteCall" href="/_debug_toolbar/views/sqlalchemy/sql_explain?sql={{ query.raw_sql|urlencode }}&amp;params={{ query.params|urlencode }}&amp;duration={{ query.duration|urlencode }}&amp;hash={{ query.hash }}">EXPLAIN</a><br />
{% if is_mysql %}
<a class="remoteCall" href="/__debug__/sql_profile/?sql={{ query.raw_sql|urlencode }}&amp;params={{ query.params|urlencode }}&amp;duration={{ query.duration|urlencode }}&amp;hash={{ query.hash }}">PROFILE</a><br />
{% endif %}
{% endif %}
{% endif %}
</td>
<td title="{{ query.context_long }}">
<table class="flDebugTablesorter">
<thead>
<tr>
<th>&nbsp;(ms)</th>
<th>Action</th>
<th>Context</th>
<th>Query</th>
</tr>
</thead>
<tbody>
{% for query in queries %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ '%.4f'|format(query.duration * 1000) }}</td>
<td>
{% if query.signed_query %}
<a class="flDebugRemoteCall" href="{{ url_for('debugtoolbar.sql_select', explain=False, query=query.signed_query, duration=query.duration )}}">SELECT</a><br />
<a class="flDebugRemoteCall" href="{{ url_for('debugtoolbar.sql_select', explain=True, query=query.signed_query, duration=query.duration )}}">EXPLAIN</a><br />
{% endif %}
</td>
<td title="{{ query.context_long }}">
{{ query.context }}
</td>
<td class="syntax">
<div class="flDebugSqlWrap">
<div class="flDebugSql">{{ query.sql|safe }}</div>
{#
{% if query.stacktrace %}
<div class="djSQLHideStacktraceDiv" style="display:none;">
<table>
<tr>
<th>{% trans "Line" %}</th>
<th>{% trans "Method" %}</th>
<th>{% trans "File" %}</th>
</tr>
{% for file, line, method in query.stacktrace %}
<tr>
<td>{{ line }}</td>
<td><code>{{ method|escape }}</code></td>
<td><code>{{ file|escape }}</code></td>
</tr>
{% endfor %}
</table>
{% if query.template_info %}
<table>
{% for line in query.template_info.context %}
<tr>
<td>{{ line.num }}</td>
<td><code style="font-family: monospace;{% if line.highlight %}background-color: lightgrey{% endif %}">{{ line.content }}</code></td>
</tr>
{% endfor %}
</table>
<p><strong>{{ query.template_info.name|default:"(unknown)" }}</strong></p>
{% endif %}
</div>
{% endif %}
<span class="djDebugLineChart{% if query.is_slow %} djDebugLineChartWarning{% endif %}" style="width:{{ query.width_ratio }}%; left:{{ query.start_offset }}%;"></span>
#}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</td>
<td class="flDebugSyntax">
<div class="flDebugSqlWrap">
<div class="flDebugSql">{{ query.sql }}</div>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -0,0 +1,44 @@
<h4>Queries Unavailable</h4>
<p>
The toolbar was unable to fetch the SQLAlchemy queries for this request.
To enable the SQLAlchemy query display, please:
</p>
<ol>
{% if not sqlalchemy_available %}
<li>
<h5>Install required libraries:</h5>
<ul>
<li>Flask-SQLAlchemy</li>
</ul>
</li>
{% endif %}
{% if not extension_used %}
<li>
<h5>Configure Flask-SQLAlchemy:</h5>
<p>
The Flask-SQLAlchemy extension needs to be configured for this application.
Please see the <a href="https://flask-sqlalchemy.palletsprojects.com/en/master/quickstart/">
Flask-SQLAlchemy documentation</a> for details.
</p>
</li>
{% endif %}
{% if not recording_enabled %}
<li>
<h5>Enable query recording:</h5>
<p>
Since this app is not currently running in <code>DEBUG</code> mode, Flask-SQLAlchemy will not record queries by default. To enable query recording in non-debug mode, set the following configuration value:
</p>
<pre>app.config['SQLALCHEMY_RECORD_QUERIES'] = True</pre>
<p>
See the
<a href="https://flask-sqlalchemy.palletsprojects.com/en/master/api/#flask_sqlalchemy.get_debug_queries">
documention of Flask-SQLAlchemy's <code>get_debug_queries()</code></a>
for additional details.
</p>
</li>
{% endif %}
</ol>

View File

@@ -1,33 +0,0 @@
<div class="flDebugPanelTitle">
<a class="flDebugClose flDebugBack" href="">Back</a>
<h3>SQL Explained</h3>
</div>
<div class="flDebugPanelContent">
<div class="scroll">
<dl>
<dt>Executed SQL</dt>
<dd>{{ sql|safe }}</dd>
<dt>Time</dt>
<dd>{{ '%.4f'|format(duration) }} ms</dd>
</dl>
<table class="flSqlExplain">
<thead>
<tr>
{% for h in headers %}
<th>{{ h|upper }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in result %}
<tr class="{{ loop.cycle('fjDebugOdd', 'fjDebugEven') }}">
{% for column in row %}
<td>{{ column }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>

View File

@@ -1,37 +1,36 @@
<div class="flDebugPanelTitle">
<a class="flDebugClose flDebugBack" href="">Back</a>
<h3>SQL Explained</h3>
<a class="flDebugClose flDebugBack" href="">Back</a>
<h3>SQL Details</h3>
</div>
<div class="flDebugPanelContent">
<div class="scroll">
<dl>
<dt>Executed SQL</dt>
<dd>{{ sql|safe }}</dd>
<dt>Time</dt>
<dd>{{ '%.4f'|format(duration) }} ms</dd>
</dl>
{% if result %}
<table class="flSqlSelect">
<thead>
<tr>
{% for h in headers %}
<th>{{ h|upper }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in result %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
{% for column in row %}
<td>{{ column }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Empty set</p>
{% endif %}
</div>
<div class="scroll">
<dl>
<dt>Executed SQL</dt>
<dd>{{ sql }}</dd>
<dt>Original query duration</dt>
<dd>{{ '%.4f'|format(duration * 1000) }} ms</dd>
</dl>
{% if result %}
<table class="flDebugSelect">
<thead>
<tr>
{% for h in headers %}
<th>{{ h|upper }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in result %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
{% for column in row %}
<td>{{ column }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Empty set</p>
{% endif %}
</div>
</div>

View File

@@ -1,26 +1,26 @@
{% if templates %}
{% if editable %}
{% if editable %}
<a href="/_debug_toolbar/views/template/{{ key }}" onclick="return fldt.load_href(this.href);">Edit templates</a>
{% endif %}
{% for template in templates %}
<h4>{{ template.template.name }}</h4>
<table>
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for k, v in template.context|dictsort %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ k }}</td>
<td>{{ v|printable }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
{% endif %}
{% for template in templates %}
<h4>{{ template.template.name }}</h4>
<table>
<thead>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for k, v in template.context|dictsort %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ k }}</td>
<td>{{ v|printable }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
{% else %}
<p>No template rendered</p>
<p>No template rendered</p>
{% endif %}

View File

@@ -18,46 +18,46 @@
{% set toolbar_height = 25 %}
{% set editor_width = request.cookies.get('fldt_editor_size')|int(40) %}
#panel, #editor, #preview, #splitter, #toolbar {
#flDebugPanel, #flDebugEditor, #flDebugPreview, #flDebugSplitter, #flDebugToolbar {
box-sizing: border-box;
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
border: none;
}
#panel, #preview { position: fixed; }
#panel > div { position: absolute; }
#flDebugPanel, #flDebugPreview { position: fixed; }
#flDebugPanel > div { position: absolute; }
#panel { width: {{ editor_width }}%; height: 100%; top: 0; left: 0; bottom: 0; }
#toolbar { top: 0; width: 100%; height: {{ toolbar_height }}px; border-bottom: 1px solid black; padding: 2px 4px; }
#editor { top: {{ toolbar_height }}px; bottom: 0; width: 100%; }
#preview { top: 0; bottom: 0; right: 0; height: 100%; width: {{ 100 - editor_width }}%; }
#flDebugPanel { width: {{ editor_width }}%; height: 100%; top: 0; left: 0; bottom: 0; }
#flDebugToolbar { top: 0; width: 100%; height: {{ toolbar_height }}px; border-bottom: 1px solid black; padding: 2px 4px; }
#flDebugEditor { top: {{ toolbar_height }}px; bottom: 0; width: 100%; }
#flDebugPreview { top: 0; bottom: 0; right: 0; height: 100%; width: {{ 100 - editor_width }}%; }
/* need a dummy element over the page so that drag events don't get captured by the preview iframe */
#drag-handler { display: none; position: fixed; width: 100%; height: 100%; z-index: 1000; }
#splitter { width: 8px; height: 100%; top: 0; bottom: 0; right: -1px; z-index: 999; cursor: e-resize; border-right: 1px solid black; }
#flDebugDragHandler { display: none; position: fixed; width: 100%; height: 100%; z-index: 1000; }
#flDebugSplitter { width: 8px; height: 100%; top: 0; bottom: 0; right: -1px; z-index: 999; cursor: e-resize; border-right: 1px solid black; }
.CodeMirror, .CodeMirror-scroll { height: 100%; }
.syntax-error { background: red !important; }
#toolbar button { margin: 0; }
#save { float: left; }
#close { float: right; }
#flDebugToolbar button { margin: 0; }
#flDebugSave { float: left; }
#flDebugClose { float: right; }
{% endwith %}
</style>
</head>
<body>
<div id="drag-handler"></div>
<div id="panel">
<div id="toolbar">
<button id="save">Save</button>
<button id="close">Close</button>
<div id="flDebugDragHandler"></div>
<div id="flDebugPanel">
<div id="flDebugToolbar">
<button id="flDebugSave">Save</button>
<button id="flDebugClose">Close</button>
</div>
<div id="editor">
<div id="flDebugEditor">
<textarea name="{{ templates[0].name }}" id="code">{{ templates[0].source }}</textarea>
</div>
<div id="splitter"></div>
<div id="flDebugSplitter"></div>
</div>
<iframe id="preview"></iframe>
<iframe id="flDebugPreview"></iframe>
<script src="{{ static_path }}codemirror/codemirror.js"></script>
<script src="{{ static_path }}codemirror/util/closetag.js"></script>
@@ -68,11 +68,11 @@
<script src="{{ static_path }}codemirror/mode/htmlmixed/htmlmixed.js"></script>
<script src="{{ static_path }}codemirror/mode/jinja2/jinja2.js"></script>
<script>{% raw %}
$('#drag-handler')
$('#flDebugDragHandler')
.mousemove(function(e) {
var size = 100 * e.pageX / $(document).width();
$('#panel').css('width', size + '%');
$('#preview').css('width', (100 - size) + '%');
$('#flDebugPanel').css('width', size + '%');
$('#flDebugPreview').css('width', (100 - size) + '%');
return false;
})
.mouseup(function(e) {
@@ -82,12 +82,12 @@
return false;
});
$('#splitter').mousedown(function() {
$('#drag-handler').show();
$('#flDebugSplitter').mousedown(function() {
$('#flDebugDragHandler').show();
return false;
});
$('#save').click(function() {
$('#flDebugSave').click(function() {
$.ajax({
type: 'POST'
, url: document.baseURI + '/save'
@@ -95,7 +95,7 @@
});
});
$('#close').click(function() {
$('#flDebugClose').click(function() {
document.location = document.location;
});
@@ -117,7 +117,7 @@
}
});
var previewFrame = document.getElementById('preview');
var previewFrame = document.getElementById('flDebugPreview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
var errorLine = null;

View File

@@ -1,21 +1,21 @@
<table>
<colgroup>
<col style="width:20%"/>
<col/>
</colgroup>
<thead>
<tr>
<th>Resource</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in rows %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|escape }}</td>
<td>{{ value|escape }}</td>
</tr>
{% endfor %}
</tbody>
<colgroup>
<col style="width:20%"/>
<col/>
</colgroup>
<thead>
<tr>
<th>Resource</th>
<th>Value</th>
</tr>
</thead>
<tbody>
{% for key, value in rows %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|escape }}</td>
<td>{{ value|escape }}</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -0,0 +1,33 @@
<h4>Installed Packages</h4>
<p>
Installation paths relative to:
</p>
<pre>
{{ python_lib }}
</pre>
<table>
<thead>
<tr>
<th>Package</th>
<th>Version</th>
<th>Installed Path</th>
</tr>
</thead>
<tbody>
{% for package in packages %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ package.project_name }}</td>
<td>{{ package.version }}</td>
<td>{{ relpath(package.location, python_lib) }}</td>
</tr>
{% else %}
<tr>
<td>setuptools</td>
<td>NOT INSTALLED</td>
<td>Install setuptools to display installed packages and version information</td>
</tr>
{% endfor %}
</tbody>
</table>

View File

@@ -1,15 +1,15 @@
<html>
<head>
<title>Redirect intercepted</title>
</head>
<body>
<h1>Redirect ({{ redirect_code }})</h1>
<p>Location: <a href="{{ redirect_to }}">{{ redirect_to }}</a></p>
<p class="notice">
The Flask Debug Toolbar has intercepted a redirect to the above URL for
debug viewing purposes. You can click the above link to continue with the
redirect as normal. If you'd like to disable this feature, you can set the
config variable <code>DEBUG_TB_INTERCEPT_REDIRECTS</code> to <code>False</code>.
</p>
</body>
<head>
<title>Redirect intercepted</title>
</head>
<body>
<h1>Redirect ({{ redirect_code }})</h1>
<p>Location: <a href="{{ redirect_to }}">{{ redirect_to }}</a></p>
<p class="flDebugNotice">
The Flask Debug Toolbar has intercepted a redirect to the above URL for
debug viewing purposes. You can click the above link to continue with the
redirect as normal. If you'd like to disable this feature, you can set the
config variable <code>DEBUG_TB_INTERCEPT_REDIRECTS</code> to <code>False</code>.
</p>
</body>
</html>

View File

@@ -1,27 +1,15 @@
import urllib
try:
from urllib.parse import unquote
except ImportError:
from urllib import unquote
from flask import url_for, current_app
from werkzeug.utils import import_string
class DebugToolbar(object):
# default config settings
config = {
'DEBUG_TB_INTERCEPT_REDIRECTS': True,
'DEBUG_TB_PANELS': (
'flask_debugtoolbar.panels.versions.VersionDebugPanel',
'flask_debugtoolbar.panels.timer.TimerDebugPanel',
'flask_debugtoolbar.panels.headers.HeaderDebugPanel',
'flask_debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flask_debugtoolbar.panels.template.TemplateDebugPanel',
'flask_debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
'flask_debugtoolbar.panels.logger.LoggingPanel',
'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel',
)
}
panel_classes = []
_cached_panel_classes = {}
def __init__(self, request, jinja_env):
self.jinja_env = jinja_env
@@ -34,36 +22,20 @@ class DebugToolbar(object):
self.create_panels()
@classmethod
def load_panels(cls, app):
cls.config.update(app.config)
for panel_path in cls.config['DEBUG_TB_PANELS']:
dot = panel_path.rindex('.')
panel_module, panel_classname = panel_path[:dot], panel_path[dot+1:]
try:
mod = __import__(panel_module, {}, {}, [''])
except ImportError, e:
app.logger.warning('Disabled %s due to ImportError: %s', panel_classname, e)
continue
panel_class = getattr(mod, panel_classname)
cls.panel_classes.append(panel_class)
def create_panels(self):
"""
Populate debug panels
"""
activated = self.request.cookies.get('fldt_active', '')
activated = urllib.unquote(activated).split(';')
activated = unquote(activated).split(';')
for panel_class in self.panel_classes:
panel_instance = panel_class(
context=self.template_context,
jinja_env=self.jinja_env)
for panel_class in self._iter_panels(current_app):
panel_instance = panel_class(jinja_env=self.jinja_env,
context=self.template_context)
if panel_instance.dom_id() in activated:
panel_instance.is_active = True
self.panels.append(panel_instance)
def render_toolbar(self):
@@ -73,4 +45,33 @@ class DebugToolbar(object):
template = self.jinja_env.get_template('base.html')
return template.render(**context)
@classmethod
def load_panels(cls, app):
for panel_class in cls._iter_panels(app):
# just loop to make sure they've been loaded
pass
@classmethod
def _iter_panels(cls, app):
for panel_path in app.config['DEBUG_TB_PANELS']:
panel_class = cls._import_panel(app, panel_path)
if panel_class is not None:
yield panel_class
@classmethod
def _import_panel(cls, app, path):
cache = cls._cached_panel_classes
try:
return cache[path]
except KeyError:
pass
try:
panel_class = import_string(path)
except ImportError as e:
app.logger.warning('Disabled %s due to ImportError: %s', path, e)
panel_class = None
cache[path] = panel_class
return panel_class

View File

@@ -1,5 +1,8 @@
import itertools
import os.path
import sys
import io
import gzip
try:
from pygments import highlight
@@ -11,46 +14,85 @@ try:
except ImportError:
HAVE_PYGMENTS = False
try:
import sqlparse
HAVE_SQLPARSE = True
except ImportError:
HAVE_SQLPARSE = False
from flask import current_app, Markup
from flask import current_app
def format_fname(value):
# If the value is not an absolute path, the it is a builtin or
# a relative file (thus a project file).
# If the value has a builtin prefix, return it unchanged
if value.startswith(('{', '<')):
return value
value = os.path.normpath(value)
# If the file is absolute, try normalizing it relative to the project root
# to handle it as a project file
if os.path.isabs(value):
value = _shortest_relative_path(
value, [current_app.root_path], os.path)
# If the value is a relative path, it is a project file
if not os.path.isabs(value):
if value.startswith(('{', '<')):
return value
if value.startswith('.' + os.path.sep):
return value
return '.' + os.path.sep + value
return os.path.join('.', value)
# If the file is absolute and within the project root handle it as
# a project file
if value.startswith(current_app.root_path):
return "." + value[len(current_app.root_path):]
# Otherwise, normalize other paths relative to sys.path
return '<%s>' % _shortest_relative_path(value, sys.path, os.path)
# Loop through sys.path to find the longest match and return
# the relative path from there.
paths = sys.path
prefix = None
prefix_len = 0
for path in sys.path:
new_prefix = os.path.commonprefix([path, value])
if len(new_prefix) > prefix_len:
prefix = new_prefix
prefix_len = len(prefix)
if not prefix.endswith(os.path.sep):
prefix_len -= 1
path = value[prefix_len:]
return '<%s>' % path
def _shortest_relative_path(value, paths, path_module):
relpaths = _relative_paths(value, paths, path_module)
return min(itertools.chain(relpaths, [value]), key=len)
def _relative_paths(value, paths, path_module):
for path in paths:
try:
relval = path_module.relpath(value, path)
except ValueError:
# on Windows, relpath throws a ValueError for
# paths with different drives
continue
if not relval.startswith(path_module.pardir):
yield relval
def decode_text(value):
"""
Decode a text-like value for display.
Unicode values are returned unchanged. Byte strings will be decoded
with a text-safe replacement for unrecognized characters.
"""
if isinstance(value, bytes):
return value.decode('ascii', 'replace')
else:
return value
def format_sql(query, args):
if HAVE_SQLPARSE:
query = sqlparse.format(query, reindent=True, keyword_case='upper')
if not HAVE_PYGMENTS:
return query
return decode_text(query)
return highlight(
return Markup(highlight(
query,
SqlLexer(encoding='utf-8'),
HtmlFormatter(encoding='utf-8', noclasses=True, style=PYGMENT_STYLE))
SqlLexer(),
HtmlFormatter(noclasses=True, style=PYGMENT_STYLE)))
def gzip_compress(data, compresslevel=6):
buff = io.BytesIO()
with gzip.GzipFile(fileobj=buff, mode='wb', compresslevel=compresslevel) as f:
f.write(data)
return buff.getvalue()
def gzip_decompress(data):
with gzip.GzipFile(fileobj=io.BytesIO(data), mode='rb') as f:
return f.read()

6
pyproject.toml Normal file
View File

@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"

35
setup.cfg Normal file
View File

@@ -0,0 +1,35 @@
[metadata]
name = Flask-DebugToolbar
version = 0.12.0
author = Michael van Tellingen
author_email = michaelvantellingen@gmail.com
maintainer = Matt Good
maintainer_email = matt@matt-good.net
description = A toolbar overlay for debugging Flask applications.
long_description = file: README.rst
long_description_content_type = text/x-rst
keywords = flask, debug, toolbar
url = https://github.com/flask-debugtoolbar/flask-debugtoolbar
project_urls =
Changelog = https://github.com/jeffwidman/cqlsh#changelog
Documentation = https://github.com/flask-debugtoolbar/flask-debugtoolbar/blob/master/CHANGES.rst
classifiers =
Development Status :: 4 - Beta
Environment :: Web Environment
Framework :: Flask
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Topic :: Internet :: WWW/HTTP :: Dynamic Content
Topic :: Software Development :: Libraries :: Python Modules
[options]
packages = find:
package_dir = = flask_debugtoolbar
include_package_data = True
python_requires = >=2.7
# Dependencies are in setup.py for GitHub's dependency graph.
[options.packages.find]
where = flask_debugtoolbar

View File

@@ -1,46 +1,12 @@
import os
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
try:
README = open(os.path.join(here, 'README.rst')).read()
CHANGES = open(os.path.join(here, 'CHANGES.rst')).read()
except:
README = ''
CHANGES = ''
from setuptools import setup
# Metadata goes in setup.cfg. These are here for GitHub's dependency graph.
setup(
name='Flask-DebugToolbar',
version='0.7.1',
url='http://github.com/mgood/flask-debugtoolbar',
license='BSD',
author='Michael van Tellingen',
author_email='michaelvantellingen@gmail.com',
maintainer='Matt Good',
maintainer_email='matt@matt-good.net',
description='A port of the Django debug toolbar to Flask',
long_description=README + '\n\n' + CHANGES,
zip_safe=False,
platforms='any',
include_package_data=True,
packages=['flask_debugtoolbar',
'flask_debugtoolbar.panels'
],
name="Flask-DebugToolbar",
install_requires=[
'Flask>=0.8',
'Blinker',
'itsdangerous',
'werkzeug',
],
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)

34
test/basic_app.py Normal file
View File

@@ -0,0 +1,34 @@
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_debugtoolbar import DebugToolbarExtension
app = Flask('basic_app')
app.config['SECRET_KEY'] = 'abc123'
# TODO: This can be removed once flask_sqlalchemy 3.0 ships
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# make sure these are printable in the config panel
app.config['BYTES_VALUE'] = b'\x00'
app.config['UNICODE_VALUE'] = u'\uffff'
toolbar = DebugToolbarExtension(app)
db = SQLAlchemy(app)
class Foo(db.Model):
__tablename__ = 'foo'
id = db.Column(db.Integer, primary_key=True)
@app.before_first_request
def setup():
db.create_all()
@app.route('/')
def index():
Foo.query.filter_by(id=1).all()
return render_template('basic_app.html')

6
test/conftest.py Normal file
View File

@@ -0,0 +1,6 @@
import pytest
@pytest.fixture(autouse=True)
def mock_env_development(monkeypatch):
monkeypatch.setenv("FLASK_ENV", "development")

View File

@@ -0,0 +1,4 @@
<!doctype html>
<html>
<body>Hello world</body>
</html>

41
test/test_toolbar.py Normal file
View File

@@ -0,0 +1,41 @@
import sys
import pytest
from flask_debugtoolbar import _printable
def load_app(name):
app = __import__(name).app
app.config['TESTING'] = True
return app.test_client()
def test_basic_app():
app = load_app('basic_app')
index = app.get('/')
assert index.status_code == 200
assert b'<div id="flDebug"' in index.data
@pytest.mark.skipif(sys.version_info >= (3,),
reason='test only applies to Python 2')
def test_printable_unicode():
class UnicodeRepr(object):
def __repr__(self):
return u'\uffff'
printable = _printable(UnicodeRepr())
assert "raised UnicodeEncodeError: 'ascii' codec" in printable
@pytest.mark.skipif(sys.version_info >= (3,),
reason='test only applies to Python 2')
def test_printable_non_ascii():
class NonAsciiRepr(object):
def __repr__(self):
return 'a\xffb'
printable = u'%s' % _printable(NonAsciiRepr())
# should replace \xff with the unicode ? character
assert printable == u'a\ufffdb'

122
test/test_utils.py Normal file
View File

@@ -0,0 +1,122 @@
import ntpath
import posixpath
from flask import Markup
import pytest
from flask_debugtoolbar.utils import (_relative_paths, _shortest_relative_path,
format_sql, decode_text, HAVE_PYGMENTS)
@pytest.mark.parametrize('value,paths,expected,path_module', [
# should yield relative path to the parent directory
('/foo/bar', ['/foo'], ['bar'], posixpath),
('c:\\foo\\bar', ['c:\\foo'], ['bar'], ntpath),
# should not yield result if no path is a parent directory
('/foo/bar', ['/baz'], [], posixpath),
('c:\\foo\\bar', ['c:\\baz'], [], ntpath),
# should only yield relative paths for parent directories
('/foo/bar', ['/foo', '/baz'], ['bar'], posixpath),
('c:\\foo\\bar', ['c:\\foo', 'c:\\baz'], ['bar'], ntpath),
# should yield all results when multiple parents match
('/foo/bar/baz', ['/foo', '/foo/bar'], ['bar/baz', 'baz'], posixpath),
('c:\\foo\\bar\\baz', ['c:\\foo', 'c:\\foo\\bar'],
['bar\\baz', 'baz'], ntpath),
# should ignore case differences on windows
('c:\\Foo\\bar', ['c:\\foo'], ['bar'], ntpath),
# should preserve original case
('/Foo/Bar', ['/Foo'], ['Bar'], posixpath),
('c:\\Foo\\Bar', ['c:\\foo'], ['Bar'], ntpath),
])
def test_relative_paths(value, paths, expected, path_module):
assert list(_relative_paths(value, paths, path_module)) == expected
@pytest.mark.parametrize('value,paths,expected,path_module', [
# should yield relative path to the parent directory
('/foo/bar', ['/foo'], 'bar', posixpath),
('c:\\foo\\bar', ['c:\\foo'], 'bar', ntpath),
# should return the original value if no path is a parent directory
('/foo/bar', ['/baz'], '/foo/bar', posixpath),
('c:\\foo\\bar', ['c:\\baz'], 'c:\\foo\\bar', ntpath),
# should yield shortest result when multiple parents match
('/foo/bar/baz', ['/foo', '/foo/bar'], 'baz', posixpath),
('c:\\foo\\bar\\baz', ['c:\\foo', 'c:\\foo\\bar'], 'baz', ntpath),
])
def test_shortest_relative_path(value, paths, expected, path_module):
assert _shortest_relative_path(value, paths, path_module) == expected
def test_decode_text_unicode():
value = u'\uffff'
decoded = decode_text(value)
assert decoded == value
def test_decode_text_ascii():
value = 'abc'
assert decode_text(value.encode('ascii')) == value
def test_decode_text_non_ascii():
value = b'abc \xff xyz'
assert isinstance(value, bytes)
decoded = decode_text(value)
assert not isinstance(decoded, bytes)
assert decoded.startswith('abc')
assert decoded.endswith('xyz')
@pytest.fixture()
def no_pygments(monkeypatch):
monkeypatch.setattr('flask_debugtoolbar.utils.HAVE_PYGMENTS', False)
def test_format_sql_no_pygments(no_pygments):
sql = 'select 1'
assert format_sql(sql, {}) == sql
def test_format_sql_no_pygments_non_ascii(no_pygments):
sql = b"select '\xff'"
formatted = format_sql(sql, {})
assert formatted.startswith(u"select '")
def test_format_sql_no_pygments_escape_html(no_pygments):
sql = 'select x < 1'
formatted = format_sql(sql, {})
assert not isinstance(formatted, Markup)
assert Markup('%s') % formatted == 'select x &lt; 1'
@pytest.mark.skipif(not HAVE_PYGMENTS,
reason='test requires the "Pygments" library')
def test_format_sql_pygments():
sql = 'select 1'
html = format_sql(sql, {})
assert isinstance(html, Markup)
assert html.startswith('<div')
assert 'select' in html
assert '1' in html
@pytest.mark.skipif(not HAVE_PYGMENTS,
reason='test requires the "Pygments" library')
def test_format_sql_pygments_non_ascii():
sql = b"select 'abc \xff xyz'"
html = format_sql(sql, {})
assert isinstance(html, Markup)
assert html.startswith('<div')
assert 'select' in html
assert 'abc' in html
assert 'xyz' in html

19
tox.ini Normal file
View File

@@ -0,0 +1,19 @@
[tox]
envlist = py27,py36,py37,py38,stylecheck
[testenv]
deps =
pytest
Flask-SQLAlchemy
Pygments
commands =
pytest
[testenv:stylecheck]
deps =
pycodestyle
commands =
pycodestyle flask_debugtoolbar test
[pycodestyle]
max-line-length = 100