Permalink
Browse files

Py3 Support

  • Loading branch information...
amol- committed Jul 24, 2016
1 parent 7863075 commit 13662578a6d4e7ef58f3371e4119212fba4b2f44
@@ -1,4 +1,5 @@
-from initialize import DebugBar, enable_debugbar
+from .initialize import DebugBar, enable_debugbar
+
def plugme(app_config, options):
app_config['debugbar.inventing'] = options.get('inventing', False)
@@ -10,11 +10,10 @@
from tg import app_globals, config, expose, request
from tg.controllers import TGController, WSGIAppController
from webob.exc import HTTPBadRequest
-from utils import format_sql, format_json
-from sections import __sections__
+from .utils import format_sql, format_json
+from .sections import __sections__
-statics_path = os.path.join(
- os.path.split(sys.modules['tgext.debugbar'].__file__)[0], 'statics')
+STATICS_PATH = os.path.join(os.path.split(sys.modules['tgext.debugbar'].__file__)[0], 'statics')
try:
@@ -32,7 +31,7 @@
class StaticsController(TGController):
- _directory_app = DirectoryApp(statics_path)
+ _directory_app = DirectoryApp(STATICS_PATH)
@expose()
def _default(self, *args):
@@ -3,6 +3,7 @@
from markupsafe import Markup
from tg import config, request, url
+from tg._compat import unicode_text
from tg.render import render
try:
@@ -66,7 +67,7 @@ def __call__(self):
continue
log.log(logging.DEBUG, 'Enabling Section: %s' % sec.name)
- for hook_name, hooks in sec.hooks.iteritems():
+ for hook_name, hooks in sec.hooks.items():
for handler in hooks:
if hook_name == 'startup':
handler()
@@ -91,7 +92,7 @@ def render_first(self, response):
def render_bars(self, response):
page = response.get('response')
- if (not page or not isinstance(page, unicode)
+ if (not page or not isinstance(page, unicode_text)
or 'text/html' not in response['content_type']
or request.headers.get(
'X-Requested-With') == 'XMLHttpRequest'):
@@ -1,10 +1,10 @@
-from sqla import SQLADebugSection
-from timing import TimingDebugSection
-from request_vars import RequestDebugSection
-from controllers import ControllersDebugSection
-from logmessages import LoggingDebugSection
-from mingorm import MingDebugSection
-from inventing import InventingDebugSection
+from .sqla import SQLADebugSection
+from .timing import TimingDebugSection
+from .request_vars import RequestDebugSection
+from .controllers import ControllersDebugSection
+from .logmessages import LoggingDebugSection
+from .mingorm import MingDebugSection
+from .inventing import InventingDebugSection
__sections__ = [
TimingDebugSection(),
@@ -1,6 +1,7 @@
import inspect
import tg
+from tg._compat import unicode_text
from tg.controllers.decoratedcontroller import DecoratedController
from tg.i18n import ugettext as _
from tg.render import render
@@ -43,7 +44,7 @@ def title(self):
def content(self):
controllers = odict()
map_controllers('', get_root_controller(), controllers)
- return unicode(render(
+ return unicode_text(render(
dict(controllers=controllers),
tg.config['debugbar.engine'], 'tgext.debugbar.sections.templates.controllers!html'
).split('\n', 1)[-1])
@@ -1,6 +1,7 @@
import hashlib, re, logging, os, time
from datetime import datetime
+from tg._compat import unicode_text
from tg import config, tmpl_context
from tg.render import render
from tg.i18n import ugettext as _
@@ -45,7 +46,7 @@ def on_after_render(response, *args, **kw):
template = response.get('template_name')
page = response.get('response')
- if content_type and 'text/html' in content_type and template and isinstance(page, unicode):
+ if content_type and 'text/html' in content_type and template and isinstance(page, unicode_text):
m = hashlib.md5()
m.update(page.encode('utf-8'))
m = m.hexdigest() + _reload_datetime
@@ -3,6 +3,7 @@
import threading
import tg
+from tg._compat import unicode_text
from tg.i18n import ugettext as _
from tg.render import render
@@ -50,8 +51,11 @@ def title(self):
def content(self):
records = []
for record in self.get_and_clear():
+ msg = record.getMessage()
+ if isinstance(msg, bytes):
+ msg = msg.decode('utf-8', 'ignore')
records.append({
- 'message': record.getMessage().decode('utf-8', 'ignore'),
+ 'message': msg,
'time': datetime.datetime.fromtimestamp(record.created),
'level': record.levelname,
'file': format_fname(record.pathname),
@@ -60,7 +64,7 @@ def content(self):
})
records = reversed(records)
- return unicode(render(
+ return unicode_text(render(
dict(records=records),
tg.config['debugbar.engine'], 'tgext.debugbar.sections.templates.logging!html'
).split('\n', 1)[-1])
@@ -1,6 +1,8 @@
import time
import inspect
+from tg._compat import unicode_text
+
try:
import json
except:
@@ -122,7 +124,7 @@ def content(self):
})
delattr(request, 'tgdb_ming_cursors')
- return unicode(render(
+ return unicode_text(render(
dict(queries=data, tg=tg),
config['debugbar.engine'], 'tgext.debugbar.sections.templates.ming!html'
).split('\n', 1)[-1])
@@ -1,6 +1,7 @@
from pprint import saferepr
import tg
+from tg._compat import unicode_text
from tg.i18n import ugettext as _
from tg.render import render
@@ -41,7 +42,7 @@ def content(self):
attr_dict = request.environ.get('webob.adhoc_attrs', {}).copy()
attr_dict['response'] = repr(response.__dict__)
- for entry in attr_dict.keys():
+ for entry in list(attr_dict.keys()):
if entry.startswith('tgdb_'):
del attr_dict[entry]
@@ -51,14 +52,14 @@ def content(self):
vars['Cookies'] = [(k, request.cookies.get(k))
for k in request.cookies]
vars['Headers'] = [(k, saferepr(v))
- for k, v in request.environ.iteritems()
+ for k, v in request.environ.items()
if k.startswith('HTTP_') or k in request_header_filter]
vars['Request Attributes'] = [(k, saferepr(v))
- for k, v in attr_dict.iteritems() if not callable(v)]
+ for k, v in attr_dict.items() if not callable(v)]
vars['Environ'] = [(k, saferepr(v))
- for k, v in request.environ.iteritems()]
+ for k, v in request.environ.items()]
- return unicode(render(
+ return unicode_text(render(
dict(vars=vars),
tg.config['debugbar.engine'], 'tgext.debugbar.sections.templates.request!html'
).split('\n', 1)[-1])
@@ -6,6 +6,8 @@
import logging
import datetime
+from tg._compat import unicode_text
+
try:
import json
except:
@@ -127,6 +129,6 @@ def content(self):
if isinstance(data, str):
return data
- return unicode(render(dict(queries=data, tg=tg),
+ return unicode_text(render(dict(queries=data, tg=tg),
config['debugbar.engine'],
'tgext.debugbar.sections.templates.sqla!html').split('\n', 1)[-1])
@@ -8,7 +8,7 @@ <h1>Mounted Controllers</h1>
<th>Controller</th>
<th>Exposed Methods</th>
</tr>
- <tr py:for="i, entry in enumerate(controllers.iteritems())"
+ <tr py:for="i, entry in enumerate(controllers.items())"
class="${'tgdb_row_odd' if i%2 else 'tgdb_row_even'} tgdb_row">
<td><strong py:content="entry[0]" /></td>
<td py:content="entry[1]['controller']" />
@@ -1,7 +1,7 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
py:strip="True">
-<div py:for="title, entries in vars.iteritems()">
+<div py:for="title, entries in vars.items()">
<h1 py:content="title" />
<p py:if="not entries">Nothing here.</p>
<table class="tgdb_table" py:if="entries">
@@ -8,7 +8,7 @@ <h1>Timing</h1>
<th>Action</th>
<th>Time Spent</th>
</tr>
- <tr py:for="i, entry in enumerate(vars.iteritems())"
+ <tr py:for="i, entry in enumerate(vars.items())"
class="${'tgdb_row_even' if i%2 else 'tgdb_row_odd'} tgdb_row">
<td><strong py:content="entry[0]" /></td>
<td py:content="u'%.4f\xa0ms' % entry[1]" />
@@ -1,6 +1,7 @@
import time, threading
from tg import request, config
+from tg._compat import unicode_text
from tg.i18n import ugettext as _
from tg.render import render
@@ -140,7 +141,7 @@ def title(self):
def content(self):
try:
- return unicode(render(dict(
+ return unicode_text(render(dict(
render_info=request.tgdb_render_info,
stats=request.tgdb_profiling_stats,
function_calls=request.tgdb_profiling_function_calls,
View
@@ -48,7 +48,7 @@ def format_sql(query):
return highlight(
query,
SqlLexer(encoding='utf-8'),
- HtmlFormatter(encoding='utf-8', noclasses=True, style=SQL_STYLE))
+ HtmlFormatter(encoding='utf-8', noclasses=True, style=SQL_STYLE)).decode('utf-8')
def format_json(json):
@@ -59,7 +59,7 @@ def format_json(json):
return highlight(
json,
MongoLexer(encoding='utf-8'),
- HtmlFormatter(encoding='utf-8', noclasses=True, style=JSON_STYLE))
+ HtmlFormatter(encoding='utf-8', noclasses=True, style=JSON_STYLE)).decode('utf-8')
def common_segment_count(path, value):

0 comments on commit 1366257

Please sign in to comment.