Here are the examples of the python api sys.__stdout__.encoding taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
3
Example 1
def main():
from calibre.utils.logging import default_log
parser = option_parser()
options, args = parser.parse_args()
if len(args) != 1:
parser.print_help()
raise SystemExit(1)
with open(args[0], 'rb') as f:
raw = f.read()
enc = sys.__stdout__.encoding or 'utf-8'
if options.verbose:
default_log.filter_level = default_log.DEBUG
print (Docuement(raw, default_log,
debug=options.verbose,
keep_elements=options.keep_elements).summary().encode(enc,
'replace'))
3
Example 2
def write(self, string):
''' A wrapper for self.stdout.write to avoid problems with unicode:
A bug in Python 2.6 results in self.stdout.write using
'default' unicode encoding, which can be ascii. This breaks
when the module encounters unicode characters.
Thus we've got to wrap the call :(
see http://stackoverflow.com/questions/8016236/python-unicode-handling-differences-between-print-and-sys-stdout-write
'''
if isinstance(string, unicode):
string = string.encode(sys.__stdout__.encoding)
sys.__stdout__.write(string)
0
Example 3
def test_43581(self):
# Can't use sys.stdout, as this is a cStringIO object when
# the test runs under regrtest.
self.assertTrue(sys.__stdout__.encoding == sys.__stderr__.encoding)
0
Example 4
def console_to_str(s):
try:
return s.decode(sys.__stdout__.encoding)
except UnicodeDecodeError:
return s.decode('utf_8')
0
Example 5
def test_43581(self):
# Can't use sys.stdout, as this is a StringIO object when
# the test runs under regrtest.
self.assertEqual(sys.__stdout__.encoding, sys.__stderr__.encoding)
0
Example 6
def console_to_str(s):
try:
return s.decode(sys.__stdout__.encoding)
except UnicodeDecodeError:
return s.decode('utf-8')