[Python-checkins] CVS: python/dist/src/Lib site.py,1.10,1.11

Marc-Andre Lemburg python-dev@python.org
Wed, 7 Jun 2000 02:12:12 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv17610/Lib
Modified Files:
	site.py 
Log Message:
Marc-Andre Lemburg <mal@lemburg.com>:
Added support to set the default encoding of strings
at startup time to the values defined by the C locale.
The sys.setdefaultencoding() API is deleted after having
set up the encoding, so that user code cannot subsequentely
change the setting. This effectively means that only site.py
may alter the default setting.
Index: site.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/site.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** site.py	1998年11月25日 15:57:47	1.10
--- site.py	2000年06月07日 09:12:09	1.11
***************
*** 120,127 ****
 del exit
 
 try:
! import sitecustomize # Run arbitrary site specific code
 except ImportError:
! pass # No site customization module
 
 def _test():
--- 120,162 ----
 del exit
 
+ #
+ # Set the string encoding used by the Unicode implementation to the
+ # encoding used by the default locale of this system. If the default
+ # encoding cannot be determined or is unkown, it defaults to 'ascii'.
+ #
+ def locale_aware_defaultencoding():
+ import locale
+ code, encoding = locale.get_default()
+ if encoding is None:
+ encoding = 'ascii'
+ try:
+ sys.setdefaultencoding(encoding)
+ except LookupError:
+ sys.setdefaultencoding('ascii')
+ 
+ if 1:
+ # Enable to support locale aware default string encodings.
+ locale_aware_defaultencoding()
+ elif 0:
+ # Enable to switch off string to Unicode coercion and implicit
+ # Unicode to string conversion.
+ sys.setdefaultencoding('undefined')
+ elif 0:
+ # Enable to hard-code a site specific default string encoding.
+ sys.setdefaultencoding('ascii')
+ 
+ #
+ # Run custom site specific code, if available.
+ #
 try:
! import sitecustomize
 except ImportError:
! pass
! 
! #
! # Remove sys.setdefaultencoding() so that users cannot change the
! # encoding after initialization.
! #
! del sys.setdefaultencoding
 
 def _test():

AltStyle によって変換されたページ (->オリジナル) /