Merged revisions 61672,61674,61676-61678,61681,61683-61684 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61672 | brett.cannon | 2008-03-20 17:13:48 +0100 (Do, 20 Mär 2008) | 2 lines

  Gave Jerry Seutter svn access for general Python development.
........
  r61674 | marc-andre.lemburg | 2008-03-20 18:31:36 +0100 (Do, 20 Mär 2008) | 7 lines

  If Mark Hammonds win32 tools are not available, try to use the _winreg module
  and sys.getwindowsversion() to get at the Windows version info.

  For the machine and processor uname() values, use the environment variables
  for these on Windows XP and later.
........
  r61676 | marc-andre.lemburg | 2008-03-20 18:55:31 +0100 (Do, 20 Mär 2008) | 5 lines

  Add documentation for updated Windows support in win32_ver().

  Add documentation for linux_distribution() API.
........
  r61677 | marc-andre.lemburg | 2008-03-20 19:08:00 +0100 (Do, 20 Mär 2008) | 2 lines

  Add news items for platform module changes.
........
  r61678 | marc-andre.lemburg | 2008-03-20 19:58:14 +0100 (Do, 20 Mär 2008) | 3 lines

  Clarfiy the availability of the extended support for win32_ver() in Py2.6.
........
  r61681 | andrew.kuchling | 2008-03-20 23:49:26 +0100 (Do, 20 Mär 2008) | 1 line

  Add lots of items
........
  r61683 | eric.smith | 2008-03-21 00:04:04 +0100 (Fr, 21 Mär 2008) | 1 line

  Fixed PEP name.
........
  r61684 | eric.smith | 2008-03-21 00:56:08 +0100 (Fr, 21 Mär 2008) | 1 line

  Comment how 'from __future__ import print_function' operates in 3.0.
........
diff --git a/Lib/platform.py b/Lib/platform.py
index c2f34b5..2c289d2 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -89,7 +89,7 @@
 
 __copyright__ = """
     Copyright (c) 1999-2000, Marc-Andre Lemburg; mailto:mal@lemburg.com
-    Copyright (c) 2000-2007, eGenix.com Software GmbH; mailto:info@egenix.com
+    Copyright (c) 2000-2008, eGenix.com Software GmbH; mailto:info@egenix.com
 
     Permission to use, copy, modify, and distribute this software and its
     documentation for any purpose and without fee or royalty is hereby granted,
@@ -525,7 +525,13 @@
         In case this fails, default is returned.
 
     """
-    from win32api import RegQueryValueEx
+    try:
+        # Use win32api if available
+        from win32api import RegQueryValueEx
+    except ImportError:
+        # On Python 2.0 and later, emulate using _winreg
+        import _winreg
+        RegQueryValueEx = _winreg.QueryValueEx
     try:
         return RegQueryValueEx(key,name)
     except:
@@ -545,9 +551,9 @@
         means the OS version uses debugging code, i.e. code that
         checks arguments, ranges, etc. (Thomas Heller).
 
-        Note: this function only works if Mark Hammond's win32
-        package is installed and obviously only runs on Win32
-        compatible platforms.
+        Note: this function works best with Mark Hammond's win32
+        package installed, but also on Python 2.3 and later. It
+        obviously only runs on Win32 compatible platforms.
 
     """
     # XXX Is there any way to find out the processor type on WinXX ?
@@ -561,11 +567,29 @@
     # Import the needed APIs
     try:
         import win32api
+        from win32api import RegQueryValueEx, RegOpenKeyEx, \
+             RegCloseKey, GetVersionEx
+        from win32con import HKEY_LOCAL_MACHINE, VER_PLATFORM_WIN32_NT, \
+             VER_PLATFORM_WIN32_WINDOWS, VER_NT_WORKSTATION
     except ImportError:
-        return release,version,csd,ptype
-    from win32api import RegQueryValueEx,RegOpenKeyEx,RegCloseKey,GetVersionEx
-    from win32con import HKEY_LOCAL_MACHINE,VER_PLATFORM_WIN32_NT,\
-                         VER_PLATFORM_WIN32_WINDOWS
+        # Emulate the win32api module using Python APIs
+        try:
+            sys.getwindowsversion
+        except AttributeError:
+            # No emulation possible, so return the defaults...
+            return release,version,csd,ptype
+        else:
+            # Emulation using _winreg (added in Python 2.0) and
+            # sys.getwindowsversion() (added in Python 2.3)
+            import _winreg
+            GetVersionEx = sys.getwindowsversion
+            RegQueryValueEx = _winreg.QueryValueEx
+            RegOpenKeyEx = _winreg.OpenKeyEx
+            RegCloseKey = _winreg.CloseKey
+            HKEY_LOCAL_MACHINE = _winreg.HKEY_LOCAL_MACHINE
+            VER_PLATFORM_WIN32_WINDOWS = 1
+            VER_PLATFORM_WIN32_NT = 2
+            VER_NT_WORKSTATION = 1
 
     # Find out the registry key and some general version infos
     maj,min,buildno,plat,csd = GetVersionEx()
@@ -602,11 +626,18 @@
         elif maj == 6:
             if min == 0:
                 # Per http://msdn2.microsoft.com/en-us/library/ms724429.aspx
-                productType = GetVersionEx(1)[8]
-                if productType == 1: # VER_NT_WORKSTATION
+                try:
+                    productType = GetVersionEx(1)[8]
+                except TypeError:
+                    # sys.getwindowsversion() doesn't take any arguments, so
+                    # we cannot detect 2008 Server that way.
+                    # XXX Add some other means of detecting 2008 Server ?!
                     release = 'Vista'
                 else:
-                    release = '2008Server'
+                    if productType == VER_NT_WORKSTATION:
+                        release = 'Vista'
+                    else:
+                        release = '2008Server'
             else:
                 release = 'post2008Server'
     else:
@@ -617,9 +648,9 @@
 
     # Open the registry key
     try:
-        keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE,regkey)
+        keyCurVer = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regkey)
         # Get a value to make sure the key exists...
-        RegQueryValueEx(keyCurVer,'SystemRoot')
+        RegQueryValueEx(keyCurVer, 'SystemRoot')
     except:
         return release,version,csd,ptype
 
@@ -1044,10 +1075,12 @@
             release,version,csd,ptype = win32_ver()
             if release and version:
                 use_syscmd_ver = 0
-            # XXX Should try to parse the PROCESSOR_* environment variables
+            # Try to use the PROCESSOR_* environment variables
             # available on Win XP and later; see
             # http://support.microsoft.com/kb/888731 and
             # http://www.geocities.com/rick_lively/MANUALS/ENV/MSWIN/PROCESSI.HTM
+            machine = os.environ.get('PROCESSOR_ARCHITECTURE', '')
+            processor = os.environ.get('PROCESSOR_IDENTIFIER', machine)
 
         # Try the 'ver' system command available on some
         # platforms