From 4c19e2aee48069568020d4e923ba85a4ea599d15 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sat, 31 Oct 2015 12:02:49 -0400 Subject: Try a different strategy for setting and testing output encodings --- coverage/misc.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'coverage/misc.py') diff --git a/coverage/misc.py b/coverage/misc.py index 36e4fe9c..db6298b6 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -6,7 +6,9 @@ import errno import hashlib import inspect +import locale import os +import sys import types from coverage import env @@ -149,6 +151,18 @@ def file_be_gone(path): raise +def output_encoding(outfile=None): + """Determine the encoding to use for output written to `outfile` or stdout.""" + if outfile is None: + outfile = sys.stdout + encoding = ( + getattr(outfile, "encoding", None) or + getattr(sys.__stdout__, "encoding", None) or + locale.getpreferredencoding() + ) + return encoding + + class Hasher(object): """Hashes Python data into md5.""" def __init__(self): -- cgit v1.2.1