Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of https://github.com/xadhoom/twistar

  • Loading branch information...
commit 28365444dc4b841f87ea4dfeb9e8b2e71c3a0d02 2 parents 60b81a7 + 6eef4e0
@xadhoom authored
Showing with 18 additions and 1 deletion.
  1. +7 −1 twistar/dbconfig/base.py
  2. +11 −0 twistar/tests/test_dbconfig.py
View
8 twistar/dbconfig/base.py
@@ -24,6 +24,12 @@ class InteractionBase:
LOG = False
includeBlankInInsert = True
+
+ def _maybe_encode(self, s, encoding='utf-8'):
+ if isinstance(s, basestring):
+ return s.encode(encoding)
+ return str(s)
+
def log(self, query, args, kwargs):
"""
@@ -34,7 +40,7 @@ def log(self, query, args, kwargs):
return
log.msg("TWISTAR query: %s" % query)
if len(args) > 0:
- log.msg("TWISTAR args: %s" % ",".join(map(lambda x: str(x), *args)))
+ log.msg("TWISTAR args: %s" % ",".join(map(self._maybe_encode, *args)))
elif len(kwargs) > 0:
log.msg("TWISTAR kargs: %s" % str(kwargs))
View
11 twistar/tests/test_dbconfig.py
@@ -3,6 +3,7 @@
from twisted.internet.defer import inlineCallbacks
from twistar.registry import Registry
+from twistar.dbconfig.base import InteractionBase
from utils import *
@@ -138,3 +139,13 @@ def test_colname_escaping(self):
for key, value in args.items():
self.assertEqual(value, ctest[key])
+
+
+ def test_unicode_logging(self):
+ ustr = u'\N{SNOWMAN}'
+
+ InteractionBase.LOG = True
+ InteractionBase().log(ustr, [ustr], {ustr: ustr})
+ InteractionBase.LOG = False
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.