Added more Windows version names (thanks to Thomas Heller).

Fixed bug in platform() cache (thanks to Brett Cannon).

(Restored Python 1.5.2 compatibility.)
This commit is contained in:
Marc-André Lemburg 2004-03-25 18:35:12 +00:00
parent 9001cde559
commit 91e83e209d
1 changed files with 23 additions and 29 deletions

View File

@ -31,7 +31,7 @@
# Colin Kong, Trent Mick # Colin Kong, Trent Mick
# #
# History: # History:
# 1.0.2 - fix a bug with caching of value for platform() # 1.0.2 - added more Windows support
# 1.0.1 - reformatted to make doc.py happy # 1.0.1 - reformatted to make doc.py happy
# 1.0.0 - reformatted a bit and checked into Python CVS # 1.0.0 - reformatted a bit and checked into Python CVS
# 0.8.0 - added sys.version parser and various new access # 0.8.0 - added sys.version parser and various new access
@ -457,7 +457,11 @@ def win32_ver(release='',version='',csd='',ptype=''):
""" """
# XXX Is there any way to find out the processor type on WinXX ? # XXX Is there any way to find out the processor type on WinXX ?
# XXX Is win32 available on Windows CE ? # XXX Is win32 available on Windows CE ?
#
# Adapted from code posted by Karl Putland to comp.lang.python. # Adapted from code posted by Karl Putland to comp.lang.python.
#
# The mappings between reg. values and release names can be found
# here: http://msdn.microsoft.com/library/en-us/sysinfo/base/osversioninfo_str.asp
# Import the needed APIs # Import the needed APIs
try: try:
@ -479,8 +483,12 @@ def win32_ver(release='',version='',csd='',ptype=''):
if maj == 4: if maj == 4:
if min == 0: if min == 0:
release = '95' release = '95'
else: elif min == 10:
release = '98' release = '98'
elif min == 90:
release = 'Me'
else:
release = 'postMe'
elif maj == 5: elif maj == 5:
release = '2000' release = '2000'
elif plat == VER_PLATFORM_WIN32_NT: elif plat == VER_PLATFORM_WIN32_NT:
@ -488,7 +496,14 @@ def win32_ver(release='',version='',csd='',ptype=''):
if maj <= 4: if maj <= 4:
release = 'NT' release = 'NT'
elif maj == 5: elif maj == 5:
release = '2000' if min == 0:
release = '2000'
elif min == 1:
release = 'XP'
elif min == 2:
release = '2003Server'
else:
release = 'post2003'
else: else:
if not release: if not release:
# E.g. Win3.1 with win32s # E.g. Win3.1 with win32s
@ -1136,10 +1151,7 @@ def python_compiler():
### The Opus Magnum of platform strings :-) ### The Opus Magnum of platform strings :-)
_platform_cache_terse = None _platform_cache = {}
_platform_cache_not_terse = None
_platform_aliased_cache_terse = None
_platform_aliased_cache_not_terse = None
def platform(aliased=0, terse=0): def platform(aliased=0, terse=0):
@ -1160,17 +1172,9 @@ def platform(aliased=0, terse=0):
absolute minimum information needed to identify the platform. absolute minimum information needed to identify the platform.
""" """
global _platform_cache_terse, _platform_cache_not_terse result = _platform_cache.get((aliased, terse), None)
global _platform_aliased_cache_terse, _platform_aliased_cache_not_terse if result is not None:
return result
if not aliased and terse and (_platform_cache_terse is not None):
return _platform_cache_terse
elif not aliased and not terse and (_platform_cache_not_terse is not None):
return _platform_cache_not_terse
elif terse and _platform_aliased_cache_terse is not None:
return _platform_aliased_cache_terse
elif not terse and _platform_aliased_cache_not_terse is not None:
return _platform_aliased_cache_not_terse
# Get uname information and then apply platform specific cosmetics # Get uname information and then apply platform specific cosmetics
# to it... # to it...
@ -1226,17 +1230,7 @@ def platform(aliased=0, terse=0):
bits,linkage = architecture(sys.executable) bits,linkage = architecture(sys.executable)
platform = _platform(system,release,machine,processor,bits,linkage) platform = _platform(system,release,machine,processor,bits,linkage)
if aliased and terse: _platform_cache[(aliased, terse)] = platform
_platform_aliased_cache_terse = platform
elif aliased and not terse:
_platform_aliased_cache_not_terse = platform
elif terse:
pass
else:
if terse:
_platform_cache_terse = platform
else:
_platform_cache_not_terse = platform
return platform return platform
### Command line interface ### Command line interface