3 Commits
0.9.0 ... 0.9.1

Author SHA1 Message Date
Matt Good
6286dadc27 Version update for 0.9.1 release 2014-11-24 13:25:17 -08: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
6 changed files with 53 additions and 6 deletions

View File

@@ -1,8 +1,17 @@
Changes
=======
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:

View File

@@ -50,7 +50,7 @@ copyright = u'2012, Matt Good'
# The short X.Y version.
version = '0.9'
# The full version, including alpha/beta/rc tags.
release = '0.9.0'
release = '0.9.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@@ -30,7 +30,10 @@ def replace_insensitive(string, target, replacement):
def _printable(value):
try:
return repr(value)
value = repr(value)
if isinstance(value, bytes):
value = value.decode('ascii', 'replace')
return value
except Exception as e:
return '<repr(%s) raised %s: %s>' % (
object.__repr__(value), type(e).__name__, e)

View File

@@ -21,8 +21,13 @@ def query_signer():
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 statement.lower().strip().startswith('select'):
if not params or not is_select(statement):
return None
try:
@@ -38,7 +43,7 @@ def load_query(data):
abort(406)
# Make sure it is a select statement
if not statement.lower().strip().startswith('select'):
if not is_select(statement):
abort(406)
return statement, params

View File

@@ -14,7 +14,7 @@ except:
setup(
name='Flask-DebugToolbar',
version='0.9.0',
version='0.9.1',
url='http://flask-debugtoolbar.rtfd.org/',
license='BSD',
author='Michael van Tellingen',

View File

@@ -1,3 +1,10 @@
import sys
import pytest
from flask_debugtoolbar import _printable
def load_app(name):
app = __import__(name).app
app.config['TESTING'] = True
@@ -9,3 +16,26 @@ def test_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'