Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started 3.x support

  • Loading branch information...
commit 9bab8e2c8204cdd6e4aa3b4cdb40fb9ff2f492fc 1 parent b9bc413
@mitsuhiko authored
View
3  Makefile
@@ -8,6 +8,9 @@ clean-pyc:
test:
@python setup.py test
+toxtest:
+ @tox
+
bench:
@python benchmark/run.py
View
16 logbook/base.py
@@ -45,6 +45,19 @@
_missing = object()
+# on python 3 we can savely assume that frame filenames will be in
+# unicode, on Python 2 we have to apply a trick.
+if sys.version_info >= (3, 0):
+ def _convert_frame_filename(fn):
+ return fn
+else:
+ def _convert_frame_filename(fn):
+ if isinstance(fn, unicode):
+ fn = fn.decode(sys.getfilesystemencoding() or 'utf-8',
+ 'replace')
+ return fn
+
+
def level_name_property():
"""Returns a property that reflects the level as name from
the internal level attribute.
@@ -521,8 +534,7 @@ def filename(self):
fn = cf.f_code.co_filename
if fn[:1] == '<' and fn[-1:] == '>':
return fn
- return os.path.abspath(fn).decode(sys.getfilesystemencoding()
- or 'utf-8', 'replace')
+ return _convert_frame_filename(os.path.abspath(fn))
@cached_property
def lineno(self):
View
6 logbook/helpers.py
@@ -126,10 +126,10 @@ def to_safe_json(data):
"""Makes a data structure safe for JSON silently discarding invalid
objects from nested structures. This also converts dates.
"""
- def _convert(obj):
+ def _convert(obj, _py2=sys.version_info < (3, 0)):
if obj is None:
return None
- elif isinstance(obj, str):
+ elif _py2 and isinstance(obj, str):
return obj.decode('utf-8', 'replace')
elif isinstance(obj, (bool, int, long, float, unicode)):
return obj
@@ -142,7 +142,7 @@ def _convert(obj):
elif isinstance(obj, dict):
rv = {}
for key, value in obj.iteritems():
- if isinstance(key, str):
+ if _py2 and isinstance(key, str):
key = key.decode('utf-8', 'replace')
else:
key = unicode(key)
View
4 setup.py
@@ -112,11 +112,9 @@ def run_setup(with_binary):
description='A logging replacement for Python',
long_description=__doc__,
packages=['logbook', 'logbook.testsuite'],
+ test_suite='logbook.testsuite.suite',
zip_safe=False,
platforms='any',
- tests_require='''
- SQLAlchemy>=0.6
- ''',
cmdclass=cmdclass,
features=features,
**extra
View
3  test_logbook.py
@@ -1,3 +0,0 @@
-import unittest
-from logbook.testsuite import suite
-unittest.main(defaultTest='suite')
View
7 tox.ini
@@ -2,5 +2,10 @@
envlist=py25,py26,py27,py31
[testenv]
-deps=SQLAlchemy
+deps=
+ SQLAlchemy
+ simplejson
commands=make test
+
+[testenv:py31]
+deps=
Please sign in to comment.
Something went wrong with that request. Please try again.