Re: Locale breakage on alpha

Quest <[email protected]> Sun, 16 Mar 2003 21:59:11 +0100
Newsgroups gmane.comp.python.snake-farm.user
Organization Pantheon
Message-ID <[email protected]>
Quest <[email protected]> writes:

> Not quite sure about this yet, but the test_unicode_file seems to
> break because you don't have a locale set (for a change):
>
>   [ 15:02 ] - locale
>   LANG=POSIX
>   LC_CTYPE="sv_SE"
>   LC_NUMERIC="sv_SE"
>   LC_TIME="sv_SE"
>   LC_COLLATE="sv_SE"
>   LC_MONETARY="sv_SE"
>   LC_MESSAGES="sv_SE"
>   LC_ALL=sv_SE
>
>   [ 15:02 ] - ./python ../python/dist/src/Lib/test/regrtest.py
>   test_unicode_file
>   test_unicode_file
>   1 test OK.
>
>   [ 15:09 ] - LC_ALL=C ./python ../python/dist/src/Lib/test/regrtest.py
>     -v test_unicode_file
>   test_unicode_file
>   test test_unicode_file crashed -- exceptions.UnicodeEncodeError:
>     'ascii' codec can't encode characters in position 6-7: ordinal not
>     in range(128)
>   Traceback (most recent call last):
>     File "../python/dist/src/Lib/test/regrtest.py", line 390, in runtest
>       the_package = __import__(abstest, globals(), locals(), [])
>     File "/mp/slaskdisk/tmp/quest/python/dist/src/Lib/test/test_unicode_file.py",
>     line 9, in ?
>       TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING)
>   UnicodeEncodeError: 'ascii' codec can't encode characters in position
>     6-7: ordinal not in range(128)
>   1 test failed:
>       test_unicode_file

It seems this has to do with the function sys.getfilesystemencoding()
which returns different encodings depending on locale:

  [ 20:34 ] - ./python
  Python 2.3a2+ (#1, Mar 13 2003, 19:27:26)
  [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> sys.getfilesystemencoding()
  'ISO-8859-1'

  [ 20:36 ] - LC_ALL=C ./python
  Python 2.3a2+ (#1, Mar 13 2003, 19:27:26)
  [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import sys
  >>> sys.getfilesystemencoding()
  'ANSI_X3.4-1968'

The exception is raised within this try block:

  try:
      TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING)
  except (ImportError, TypeError):
      # Either the file system encoding is None, or the file name
      # cannot be encoded in the file system encoding.
      raise TestSkipped("No Unicode filesystem semantics on this platform.")

Maybe the UnicodeEncodeError should be caught here instead (in
addition)?

The same error appears on my debian/linux/intel-box.
--
Anders "Quest" Qvist
http://www.lysator.liu.se/~sfarmer