[issue3410] platform.version() don't work as expected in Vista in portuguese

Marc-Andre Lemburg report at bugs.python.org
Mon Jul 6 12:49:35 CEST 2009


Marc-Andre Lemburg <mal at egenix.com> added the comment:

Ezio Melotti wrote:
> Ezio Melotti <ezio.melotti at gmail.com> added the comment:
> 
> On the Vista machine that returned ('', '6.0.6002', 'SP2',
> 'Multiprocessor Free') there is ActiveState's Python 2.5.2 that includes
> the pywin32 extension.
> 
> I managed to run pdb on it and the result was http://dpaste.com/hold/63642/
> Python 2.5 doesn't have any check for Vista, and in win32_ver(), inside
> the "elif plat == VER_PLATFORM_WIN32_NT:" it only checks for maj <= 4
> and maj == 5. Vista is 6 and 'release' remains unset [1]. In Py 2.6
> there's also if maj == 6 [2] (and now maj == 7 should be added too).

Ah, that makes sense: Vista support only got added in Python 2.6.
We cannot add that support to Python 2.5, since that branch is
closed.

Note however that platform.py does work with multiple Python versions,
so you can always copy the module from a later version and hand-replace
the one from the original distribution with an updated one.

> However, I also tried to run what the OP said and indeed I found some
> problem. With pdb.run('platform._syscmd_ver()'), on Vista in English I get:
> -> info = pipe.read()
> (Pdb) s
>> c:\program files\python26\lib\platform.py(493)_syscmd_ver()
> -> if pipe.close():
> (Pdb) info
> '\nMicrosoft Windows [Version 6.0.6002]\n'
> ...
> -> m = _ver_output.match(info)
> (Pdb) s
>> c:\program files\python26\lib\platform.py(511)_syscmd_ver()
> -> if m is not None:
> (Pdb) m
> <_sre.SRE_Match object at 0x0000000002812AE0>
> (Pdb) m.groups()
> ('Microsoft', 'Windows', '6.0.6002')
> 
> where _ver_output = re.compile(r'(?:([\w ]+) ([\w.]+) '
>                          '.*'
>                          'Version ([\d.]+))')
> 
> In non-English versions instead the regex doesn't match:
> -> if pipe.close():
> (Pdb) p info
> '\nMicrosoft Windows [Versione 6.0.6002]\n'
> ...
>> c:\program files\python25\lib\platform.py(420)_syscmd_ver()
> -> m = _ver_output.match(info)
> (Pdb) n
>> c:\program files\python25\lib\platform.py(421)_syscmd_ver()
> -> if m:
> (Pdb) m
> (Pdb)

Thanks for checking.

> Since 'Version' is translated, the regex fails if the translation is
> different because it checks specifically for the word 'Version'.
> Replacing it with \S+ as the OP suggested sounds like a reasonable
> solution. It is possible that even other versions of Windows (e.g. XP)
> have 'Version' translated, can you reproduce it with your German XP?

Interesting. In the German XP uses 'Version' as well, so the regexp
matches just fine.

I'll correct the regexp to only try matching on 'Ver\w+'.

> Later I can try on another non-English XP and see if the regex match.
> 
> [1]: /python/branches/release25-maint/Lib/platform.py?view=markup
> [2]: /python/branches/release26-maint/Lib/platform.py?view=markup

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3410>
_______________________________________


More information about the Python-bugs-list mailing list