mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 07:06:41 +00:00
Let me write unicode to stdout on Python 2
This commit is contained in:
parent
4db8c2209b
commit
24e7dcfcd8
@ -21,6 +21,26 @@ from allmydata.scripts.common_http import BadResponse
|
||||
from allmydata.util.abbreviate import abbreviate_space, abbreviate_time
|
||||
from allmydata.util.encodingutil import argv_to_abspath
|
||||
|
||||
if PY2:
|
||||
_print = print
|
||||
def print(*args, **kwargs):
|
||||
"""
|
||||
Builtin ``print``-alike that will even write unicode not encodeable using
|
||||
the specified output file's encoding.
|
||||
"""
|
||||
out = kwargs.pop("file", None)
|
||||
if out is None:
|
||||
from sys import stdout as out
|
||||
encoding = out.encoding or "ascii"
|
||||
def ensafe(o):
|
||||
if isinstance(o, unicode):
|
||||
return o.encode(encoding, errors="replace").decode(encoding)
|
||||
return o
|
||||
return _print(
|
||||
*(ensafe(a) for a in args),
|
||||
file=out,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def _get_request_parameters_for_fragment(options, fragment, method, post_args):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user