Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added support for Python 3 #1

Merged
merged 1 commit into from

2 participants

@FSX

Hi,

I added support for Python 3 and tested it in Python 3.3. Python 2.* has not been tested, because I don't have an environment set up. Once dependency has been added, six for convenience.

@sramana sramana merged commit c959f76 into sramana:master
@sramana
Owner

@FSX Thanks for the patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2012
  1. @FSX
This page is out of date. Refresh to see the latest.
View
7 bottle_debugtoolbar/__init__.py
@@ -1,5 +1,6 @@
import os
+import six
import bottle
from jinja2 import Environment, PackageLoader
from bottle_debugtoolbar.toolbar import DebugToolbar
@@ -57,7 +58,7 @@ def setup(self, app):
self.jinja_env.filters['printable'] = _printable
self.app.route(path='/_debug_toolbar/static/<filename:path>',
- name='_debug_toolbar.static',
+ name='_debug_toolbar.static',
callback=self.send_static_file)
def apply(self, callback, route):
@@ -100,7 +101,7 @@ def send_static_file(self, filename):
def process_request(self, view_func, view_kwargs):
if not self._show_toolbar():
return
-
+
self.debug_toolbar = DebugToolbar(bottle.request, self.jinja_env)
for panel in self.debug_toolbar.panels:
@@ -132,7 +133,7 @@ def process_response(self, content):
# toolbar to the returned html response.
if (bottle.response.status_code == 200
and bottle.response.headers['content-type'].startswith('text/html')
- and isinstance(content, basestring)):
+ and isinstance(content, six.string_types)):
for panel in self.debug_toolbar.panels:
panel.process_response(bottle.request, content)
View
2  bottle_debugtoolbar/templates/panels/headers.html
@@ -6,7 +6,7 @@
</tr>
</thead>
<tbody>
- {% for key, value in headers.iteritems() %}
+ {% for key, value in headers.items() %}
<tr class="{{ loop.cycle('flDebugOdd', 'flDebugEven') }}">
<td>{{ key|escape }}</td>
<td>{{ value|escape }}</td>
View
19 bottle_debugtoolbar/toolbar.py
@@ -1,8 +1,21 @@
import logging
-import urllib
+
+import six
import bottle
+if six.PY3:
+ import urllib.parse
+
+ def unquote(text):
+ return urllib.parse.unquote(text)
+else:
+ import urllib
+
+ def unquote(text):
+ return urllib.unquote(text)
+
+
class DebugToolbar(object):
panel_classes = []
@@ -25,7 +38,7 @@ def load_panels(cls, config):
try:
mod = __import__(panel_module, {}, {}, [''])
- except ImportError, e:
+ except ImportError as e:
logging.warning('Disabled %s due to ImportError: %s', panel_classname, e)
continue
panel_class = getattr(mod, panel_classname)
@@ -36,7 +49,7 @@ 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(
View
20 bottle_debugtoolbar/urls.py
@@ -1,19 +1,27 @@
+import six
+
+
+if six.PY3:
+ nrange = range
+else:
+ nrange = xrange
+
#: list of characters that are always safe in URLs.
_always_safe = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'
'abcdefghijklmnopqrstuvwxyz'
'0123456789_.-')
_safe_map = dict((c, c) for c in _always_safe)
-for i in xrange(0x80):
+for i in nrange(0x80):
c = chr(i)
if c not in _safe_map:
_safe_map[c] = '%%%02X' % i
-_safe_map.update((chr(i), '%%%02X' % i) for i in xrange(0x80, 0x100))
+_safe_map.update((chr(i), '%%%02X' % i) for i in nrange(0x80, 0x100))
_safemaps = {}
def _quote(s, safe='/', _join=''.join):
- assert isinstance(s, str), 'quote only works on bytes'
+ assert isinstance(s, six.string_types), 'quote only works on bytes'
if not s or not s.rstrip(_always_safe + safe):
return s
try:
@@ -22,7 +30,7 @@ def _quote(s, safe='/', _join=''.join):
safe_map = _safe_map.copy()
safe_map.update([(c, c) for c in safe])
_safemaps[safe] = quoter = safe_map.__getitem__
- return _join(map(quoter, s))
+ return _join(list(map(quoter, s)))
def _quote_plus(s, safe=''):
@@ -39,8 +47,8 @@ def url_quote_plus(s, charset='utf-8', safe=''):
:param charset: the charset to be used.
:param safe: an optional sequence of safe characters.
"""
- if isinstance(s, unicode):
+ if isinstance(s, six.text_type):
s = s.encode(charset)
- elif not isinstance(s, str):
+ elif not isinstance(s, six.string_types):
s = str(s)
return _quote_plus(s, safe=safe)
View
5 bottle_debugtoolbar/utils.py
@@ -2,6 +2,9 @@
import os.path
import sys
+import six
+
+
try:
from pygments import highlight
from pygments.formatters import HtmlFormatter
@@ -69,7 +72,7 @@ def replace_insensitive(string, target, replacement):
def _printable(value):
- if isinstance(value, unicode):
+ if isinstance(value, six.text_type):
return value.encode('unicode_escape')
elif isinstance(value, str):
return value.encode('string_escape')
View
5 setup.py
@@ -12,7 +12,7 @@
setup(
name='Bottle-DebugToolbar',
- version='0.4',
+ version='0.5',
url='http://github.com/sramana/bottle-debugtoolbar',
license='BSD',
author='Ramana Varanasi',
@@ -27,7 +27,8 @@
],
install_requires=[
'bottle>=0.11.2',
- 'jinja2>=2.6'
+ 'jinja2>=2.6',
+ 'six'
],
classifiers=[
'Development Status :: 4 - Beta',
Something went wrong with that request. Please try again.