sys.__stdout__.encoding

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 7

Example 1

Project: calibre Source File: readability.py
Function: main
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'))

Example 2

Project: OpenWatch Source File: organize_recordings.py
Function: write
    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)

Example 3

Project: pymo Source File: test_sys.py
Function: test_43581
    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)

Example 4

Project: pip Source File: __init__.py
Function: console_to_str
    def console_to_str(s):
        try:
            return s.decode(sys.__stdout__.encoding)
        except UnicodeDecodeError:
            return s.decode('utf_8')

Example 5

Project: TrustRouter Source File: test_sys.py
Function: test_43581
    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)

Example 6

Project: pyp2rpm Source File: utils.py
Function: console_to_str
    def console_to_str(s):
        try:
            return s.decode(sys.__stdout__.encoding)
        except UnicodeDecodeError:
            return s.decode('utf-8')