#NEWLINE# def detect_console_encoding( ) : #NEWLINE# #INDENT# '\n    Try to find the most capable encoding supported by the console.\n    slighly modified from the way IPython handles the same issue.\n    ' #NEWLINE# import locale #NEWLINE# global _initial_defencoding #NEWLINE# encoding = None #NEWLINE# try : #NEWLINE# #INDENT# encoding = ( sys . stdout . encoding or sys . stdin . encoding ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( ( not encoding ) or ( 'ascii' in encoding . lower ( ) ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# encoding = locale . getpreferredencoding ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not _initial_defencoding ) or ( 'ascii' in encoding . lower ( ) ) ) : #NEWLINE# #INDENT# encoding = sys . getdefaultencoding ( ) #NEWLINE# #UNINDENT# if ( not _initial_defencoding ) : #NEWLINE# #INDENT# _initial_defencoding = sys . getdefaultencoding ( ) #NEWLINE# #UNINDENT# return encoding