mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-18 20:47:54 +00:00
Work with newer versions of Eliot
This commit is contained in:
parent
22192b5e09
commit
4b75b7c6e8
@ -125,5 +125,5 @@ if sys.platform == "win32":
|
||||
initialize()
|
||||
|
||||
from eliot import to_file
|
||||
from allmydata.util.eliotutil import eliot_json_encoder
|
||||
to_file(open("eliot.log", "wb"), encoder=eliot_json_encoder)
|
||||
from allmydata.util.eliotutil import BytesEliotJSONEncoder
|
||||
to_file(open("eliot.log", "wb"), encoder=BytesEliotJSONEncoder)
|
||||
|
@ -29,6 +29,7 @@ from eliot import (
|
||||
ILogger,
|
||||
)
|
||||
from eliot.testing import (
|
||||
MemoryLogger,
|
||||
swap_logger,
|
||||
check_for_errors,
|
||||
)
|
||||
@ -38,7 +39,7 @@ from twisted.python.monkey import (
|
||||
)
|
||||
|
||||
from ..util.eliotutil import (
|
||||
MemoryLogger,
|
||||
BytesEliotJSONEncoder
|
||||
)
|
||||
|
||||
_NAME = Field.for_types(
|
||||
@ -146,7 +147,7 @@ def with_logging(
|
||||
"""
|
||||
@wraps(test_method)
|
||||
def run_with_logging(*args, **kwargs):
|
||||
validating_logger = MemoryLogger()
|
||||
validating_logger = MemoryLogger(encoder=BytesEliotJSONEncoder)
|
||||
original = swap_logger(None)
|
||||
try:
|
||||
swap_logger(_TwoLoggers(original, validating_logger))
|
||||
|
@ -3,17 +3,6 @@ Tools aimed at the interaction between Tahoe-LAFS implementation and Eliot.
|
||||
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from __future__ import (
|
||||
unicode_literals,
|
||||
print_function,
|
||||
absolute_import,
|
||||
division,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"MemoryLogger",
|
||||
@ -26,11 +15,6 @@ __all__ = [
|
||||
"capture_logging",
|
||||
]
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.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_text
|
||||
|
||||
from sys import (
|
||||
stdout,
|
||||
)
|
||||
@ -42,6 +26,7 @@ from logging import (
|
||||
)
|
||||
from json import loads
|
||||
|
||||
from six import ensure_text
|
||||
from zope.interface import (
|
||||
implementer,
|
||||
)
|
||||
@ -65,7 +50,7 @@ from eliot.testing import (
|
||||
MemoryLogger,
|
||||
capture_logging,
|
||||
)
|
||||
from eliot.json import EliotJSONEncoder as eliot_json_encoder
|
||||
from eliot.json import EliotJSONEncoder
|
||||
|
||||
from eliot._validation import (
|
||||
ValidationError,
|
||||
@ -94,6 +79,15 @@ from twisted.internet.defer import (
|
||||
from twisted.application.service import Service
|
||||
|
||||
|
||||
class BytesEliotJSONEncoder(EliotJSONEncoder):
|
||||
"""Support encoding bytes."""
|
||||
|
||||
def default(self, o):
|
||||
if isinstance(o, bytes):
|
||||
return o.decode("utf-8", "backslashreplace")
|
||||
return EliotJSONEncoder.default(self, o)
|
||||
|
||||
|
||||
def validateInstanceOf(t):
|
||||
"""
|
||||
Return an Eliot validator that requires values to be instances of ``t``.
|
||||
@ -310,7 +304,7 @@ class _DestinationParser(object):
|
||||
rotateLength=rotate_length,
|
||||
maxRotatedFiles=max_rotated_files,
|
||||
)
|
||||
return lambda reactor: FileDestination(get_file(), eliot_json_encoder)
|
||||
return lambda reactor: FileDestination(get_file(), encoder=BytesEliotJSONEncoder)
|
||||
|
||||
|
||||
_parse_destination_description = _DestinationParser().parse
|
||||
|
Loading…
Reference in New Issue
Block a user