Message184234
Tested on python-3.2 and python-3.3. platform.platform() looks for a file in /etc/ that looks like it will contain the name of the Linux distribution that python3 is running on. Once found, it reads the contents of the file to have a name for the Linux distribution. Most Linux distributions do create files inside of /etc/ with a single line which is the distribution name so this is a good heuristic. However, these files are created by the operating system vendor and so they can have a different encoding than the encoding of the locale the user uses. This means that if there are non-ascii characters inside the file, user code that invokes platform.platform() may throw a traceback.
Test:
$ LC_ALL=en_US.utf8 sudo echo ' Café' >> /etc/fedora-release
$ LC_ALL=C python3
>>> import platform
>>> platform.platform()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.2/platform.py", line 1538, in platform
distname,distversion,distid = dist('')
File "/usr/lib64/python3.2/platform.py", line 358, in dist
full_distribution_name=0)
File "/usr/lib64/python3.2/platform.py", line 329, in linux_distribution
firstline = f.readline()
File "/usr/lib64/python3.2/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 22: ordinal not in range(128)
It seems that the standard method of fixing these that we're promoting in python3 is to use surrogateescape. I'll provide a patch that does that. |
|
Date |
User |
Action |
Args |
2013-03-15 15:08:30 | a.badger | set | recipients:
+ a.badger |
2013-03-15 15:08:30 | a.badger | set | messageid: <1363360110.07.0.662014346708.issue17429@psf.upfronthosting.co.za> |
2013-03-15 15:08:30 | a.badger | link | issue17429 messages |
2013-03-15 15:08:29 | a.badger | create | |
|