mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-05-04 18:12:59 +00:00
Always use native strings as keys.
This commit is contained in:
parent
dd5092f656
commit
feb85f4c4a
@ -9,7 +9,7 @@ from __future__ import absolute_import
|
|||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
from future.utils import PY2
|
from future.utils import PY2, native_str
|
||||||
if PY2:
|
if PY2:
|
||||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
|
||||||
@ -154,3 +154,17 @@ class Log(unittest.TestCase):
|
|||||||
obj.log("four")
|
obj.log("four")
|
||||||
self.assertEqual([m[2] for m in self.messages],
|
self.assertEqual([m[2] for m in self.messages],
|
||||||
["grand", "par1", "par2", "msg1", "msg1"])
|
["grand", "par1", "par2", "msg1", "msg1"])
|
||||||
|
|
||||||
|
def test_native_string_keys(self):
|
||||||
|
"""Keyword argument keys are all native strings."""
|
||||||
|
class LoggingObject17(tahoe_log.PrefixingLogMixin):
|
||||||
|
pass
|
||||||
|
|
||||||
|
obj = LoggingObject17()
|
||||||
|
# Native string by default:
|
||||||
|
obj.log(hello="world")
|
||||||
|
# Will be Unicode on Python 2:
|
||||||
|
obj.log(**{"my": "message"})
|
||||||
|
for message in self.messages:
|
||||||
|
for k in message[-1].keys():
|
||||||
|
self.assertIsInstance(k, native_str)
|
||||||
|
@ -11,6 +11,7 @@ from __future__ import unicode_literals
|
|||||||
from future.utils import PY2
|
from future.utils import PY2
|
||||||
if PY2:
|
if PY2:
|
||||||
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||||
|
from six import ensure_str
|
||||||
|
|
||||||
from pyutil import nummedobj
|
from pyutil import nummedobj
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ class LogMixin(object):
|
|||||||
pmsgid = self._parentmsgid
|
pmsgid = self._parentmsgid
|
||||||
if pmsgid is None:
|
if pmsgid is None:
|
||||||
pmsgid = self._grandparentmsgid
|
pmsgid = self._grandparentmsgid
|
||||||
|
kwargs = {ensure_str(k): v for (k, v) in kwargs.items()}
|
||||||
msgid = log.msg(msg, facility=facility, parent=pmsgid, *args, **kwargs)
|
msgid = log.msg(msg, facility=facility, parent=pmsgid, *args, **kwargs)
|
||||||
if self._parentmsgid is None:
|
if self._parentmsgid is None:
|
||||||
self._parentmsgid = msgid
|
self._parentmsgid = msgid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user