homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients ajaksu2, kbk, methane, sgala
Date 2009年04月12日.11:04:18
SpamBayes Score 3.2164158e-07
Marked as misclassified No
Message-id <1239534260.19.0.349075523492.issue1542677@psf.upfronthosting.co.za>
In-reply-to
Content
How to use locale.getpreferredencoding() instead of 
locale.nl_langinfo(locale.CODESET).
--- IOBinding.py.back	Sun Apr 12 19:54:52 2009
+++ IOBinding.py	Sun Apr 12 20:02:58 2009
@@ -35,40 +35,16 @@
 # Encoding for file names
 filesystemencoding = sys.getfilesystemencoding()
 
-encoding = "ascii"
-if sys.platform == 'win32':
- # On Windows, we could use "mbcs". However, to give the user
- # a portable encoding name, we need to find the code page
- try:
- encoding = locale.getdefaultlocale()[1]
- codecs.lookup(encoding)
- except LookupError:
- pass
-else:
- try:
- # Different things can fail here: the locale module may not be
- # loaded, it may not offer nl_langinfo, or CODESET, or the
- # resulting codeset may be unknown to Python. We ignore all
- # these problems, falling back to ASCII
- encoding = locale.nl_langinfo(locale.CODESET)
- if encoding is None or encoding is '':
- # situation occurs on Mac OS X
- encoding = 'ascii'
- codecs.lookup(encoding)
- except (NameError, AttributeError, LookupError):
- # Try getdefaultlocale well: it parses environment variables,
- # which may give a clue. Unfortunately, getdefaultlocale has
- # bugs that can cause ValueError.
- try:
- encoding = locale.getdefaultlocale()[1]
- if encoding is None or encoding is '':
- # situation occurs on Mac OS X
- encoding = 'ascii'
- codecs.lookup(encoding)
- except (ValueError, LookupError):
- pass
+encoding = "utf-8"
 
-encoding = encoding.lower()
+preferredencoding = None
+try:
+ preferredencoding = locale.getpreferredencoding()
+ codecs.lookup(preferredencoding)
+ encoding = preferredencoding.lower()
+except LookupError:
+ pass
+del preferredencoding
 
 coding_re = re.compile("coding[:=]\s*([-\w_.]+)")
History
Date User Action Args
2009年04月12日 11:04:20methanesetrecipients: + methane, kbk, sgala, ajaksu2
2009年04月12日 11:04:20methanesetmessageid: <1239534260.19.0.349075523492.issue1542677@psf.upfronthosting.co.za>
2009年04月12日 11:04:19methanelinkissue1542677 messages
2009年04月12日 11:04:18methanecreate

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