pyrepl/pyrepl python_reader.py,1.6,1.7 unix_console.py,1.7,1.8

[email protected] Fri, 16 May 2003 15:31:50 +0200 (MEST)
Newsgroups gmane.comp.python.pyrepl.checkins
Message-ID <[email protected]>
Update of /cvs/pyrepl/pyrepl/pyrepl
In directory thoth.codespeak.net:/tmp/cvs-serv14055

Modified Files:
	python_reader.py unix_console.py 
Log Message:
Make a stab at guessing the encoding to use.

This should perhaps be in a convenience function somewhere...


Index: python_reader.py
===================================================================
RCS file: /cvs/pyrepl/pyrepl/pyrepl/python_reader.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** python_reader.py	16 May 2003 13:18:01 -0000	1.6
--- python_reader.py	16 May 2003 13:31:48 -0000	1.7
***************
*** 314,318 ****
          else:
              from pyrepl.unix_console import UnixConsole
!             con = UnixConsole(0, 1, None)
          print "Python", sys.version, "on", sys.platform
          print 'Type "copyright", "credits" or "license" for more information.'
--- 314,337 ----
          else:
              from pyrepl.unix_console import UnixConsole
!             try:
!                 import locale
!             except ImportError:
!                 encoding = None
!             else:
!                 if hasattr(locale, 'nl_langinfo') \
!                        and hasattr(locale, 'CODESET'):
!                     encoding = locale.nl_langinfo(locale.CODESET)
!                 elif os.environ.get('TERM_PROGRAM') == 'Apple_Terminal':
!                     # /me whistles innocently...
!                     code = int(os.popen(
!                         "defaults read com.apple.Terminal StringEncoding"
!                         ).read())
!                     if code == 4:
!                         encoding = 'utf-8'
!                     else:
!                         encoding = None
!                 else:
!                     encoding = None # so you get ASCII...
!             con = UnixConsole(0, 1, None, encoding)
          print "Python", sys.version, "on", sys.platform
          print 'Type "copyright", "credits" or "license" for more information.'

Index: unix_console.py
===================================================================
RCS file: /cvs/pyrepl/pyrepl/pyrepl/unix_console.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** unix_console.py	16 May 2003 13:18:01 -0000	1.7
--- unix_console.py	16 May 2003 13:31:48 -0000	1.8
***************
*** 114,118 ****
      def __init__(self, f_in=0, f_out=1, term=None, encoding=None):
          if encoding is None:
!             encoding = 'utf-8'#sys.getdefaultencoding()
              
          self.encoding = encoding
--- 114,118 ----
      def __init__(self, f_in=0, f_out=1, term=None, encoding=None):
          if encoding is None:
!             encoding = sys.getdefaultencoding()
              
          self.encoding = encoding