Merge pull request #63 from defuz/pep8

PEP8 formatting
This commit is contained in:
Matt Good
2013-12-02 16:20:27 -08:00
14 changed files with 36 additions and 33 deletions

View File

@@ -22,16 +22,19 @@ db = SQLAlchemy(app)
toolbar = DebugToolbarExtension(app)
class ExampleModel(db.Model):
__tablename__ = 'examples'
value = db.Column(db.String(100), primary_key=True)
@app.route('/')
def index():
app.logger.info("Hello there")
ExampleModel.query.get(1)
return render_template('index.html')
@app.route('/redirect')
def redirect_example():
@@ -44,4 +47,3 @@ if __name__ == "__main__":
manager = Manager(app)
manager.run()

View File

@@ -17,13 +17,14 @@ 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
@@ -79,7 +80,7 @@ class DebugToolbarExtension(object):
app.dispatch_request = self.dispatch_request
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')
@@ -171,7 +172,7 @@ class DebugToolbarExtension(object):
# link to the target.
if current_app.config['DEBUG_TB_INTERCEPT_REDIRECTS']:
if (response.status_code in self._redirect_codes and
not real_request.is_xhr):
not real_request.is_xhr):
redirect_to = response.location
redirect_code = response.status_code
if redirect_to:
@@ -186,8 +187,8 @@ 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')):
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)

View File

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

View File

@@ -1,16 +1,16 @@
"""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
has_content = False # If content returns something, set to true in subclass
# 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 +57,3 @@ class DebugPanel(object):
def process_response(self, request, response):
pass

View File

@@ -1,5 +1,6 @@
from flask import current_app
from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x

View File

@@ -12,13 +12,14 @@ 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)
@@ -87,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')
return "%s message%s" % \
(len(handler.get_records()), (len(handler.get_records()) == 1) and '' or 's')
def title(self):
return _('Log Messages')
@@ -111,5 +113,3 @@ class LoggingPanel(DebugPanel):
context.update({'records': records})
return self.render('panels/logger.html', context)

View File

@@ -118,6 +118,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).
@@ -37,11 +38,11 @@ class RequestVarsDebugPanel(DebugPanel):
'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]',
'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

@@ -1,4 +1,3 @@
try:
from flask.ext.sqlalchemy import get_debug_queries, SQLAlchemy
except ImportError:
@@ -51,11 +50,10 @@ class SQLAlchemyDebugPanel(DebugPanel):
"""
name = 'SQLAlchemy'
@property
def has_content(self):
if not json_available or not sqlalchemy_available:
return True # will display an error message
return True # will display an error message
return bool(get_debug_queries())
def process_request(self, request):
@@ -101,10 +99,11 @@ class SQLAlchemyDebugPanel(DebugPanel):
'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, params = load_query(request.args['query'])
@@ -118,6 +117,7 @@ def sql_select():
'duration': float(request.args['duration']),
})
@module.route('/sqlalchemy/sql_explain', methods=['GET', 'POST'])
def sql_explain():
statement, params = load_query(request.args['query'])

View File

@@ -5,7 +5,10 @@ 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, render_template_string,
Response, current_app, abort, url_for
)
from flask_debugtoolbar import module
from flask_debugtoolbar.panels import DebugPanel

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
@@ -91,4 +92,3 @@ class TimerDebugPanel(DebugPanel):
})
return self.render('panels/timer.html', context)

View File

@@ -3,6 +3,7 @@ from flask_debugtoolbar.panels import DebugPanel
_ = lambda x: x
class VersionDebugPanel(DebugPanel):
"""
Panel that displays the Flask version.
@@ -24,5 +25,3 @@ class VersionDebugPanel(DebugPanel):
def content(self):
return None

View File

@@ -14,6 +14,7 @@ except ImportError:
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).
@@ -45,6 +46,7 @@ def format_fname(value):
path = value[prefix_len:]
return '<%s>' % path
def format_sql(query, args):
if not HAVE_PYGMENTS:
return query
@@ -53,4 +55,3 @@ def format_sql(query, args):
query,
SqlLexer(encoding='utf-8'),
HtmlFormatter(encoding='utf-8', noclasses=True, style=PYGMENT_STYLE))

View File

@@ -14,4 +14,4 @@ toolbar = DebugToolbarExtension(app)
@app.route('/')
def index():
return render_template('basic_app.html')
return render_template('basic_app.html')