Tarek Ziadé avatar Tarek Ziadé committed fcc6211

Merged revisions 70212 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
r70212 | tarek.ziade | 2009-03-07 01:32:45 +0100 (Sat, 07 Mar 2009) | 1 line

Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler
........

Comments (0)

Files changed (3)

Lib/distutils/msvc9compiler.py

 import os
 import subprocess
 import sys
-from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
-    CompileError, LibError, LinkError)
-from distutils.ccompiler import (CCompiler, gen_preprocess_options,
-    gen_lib_options)
+
+from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
+                             CompileError, LibError, LinkError
+from distutils.ccompiler import CCompiler, gen_preprocess_options, \
+                                gen_lib_options
 from distutils import log
 from distutils.util import get_platform
 
     """Helper class to read values from the registry
     """
 
-    @classmethod
     def get_value(cls, path, key):
         for base in HKEYS:
             d = cls.read_values(base, path)
             if d and key in d:
                 return d[key]
         raise KeyError(key)
+    get_value = classmethod(get_value)
 
-    @classmethod
     def read_keys(cls, base, key):
         """Return list of registry keys."""
         try:
             L.append(k)
             i += 1
         return L
+    read_keys = classmethod(read_keys)
 
-    @classmethod
     def read_values(cls, base, key):
         """Return dict of registry keys and values.
 
             d[cls.convert_mbcs(name)] = cls.convert_mbcs(value)
             i += 1
         return d
+    read_values = classmethod(read_values)
 
-    @staticmethod
     def convert_mbcs(s):
         dec = getattr(s, "decode", None)
         if dec is not None:
             except UnicodeError:
                 pass
         return s
+    convert_mbcs = staticmethod(convert_mbcs)
 
 class MacroExpander:
 
                                "sdkinstallrootv2.0")
             else:
                 raise KeyError("sdkinstallrootv2.0")
-        except KeyError as exc: #
+        except KeyError:
             raise DistutilsPlatformError(
             """Python was built with Visual Studio 2008;
 extensions must be built with a compiler than can generate compatible binaries.
                 try:
                     self.spawn([self.rc] + pp_opts +
                                [output_opt] + [input_opt])
-                except DistutilsExecError as msg:
+                except DistutilsExecError, msg:
                     raise CompileError(msg)
                 continue
             elif ext in self._mc_extensions:
                     self.spawn([self.rc] +
                                ["/fo" + obj] + [rc_file])
 
-                except DistutilsExecError as msg:
+                except DistutilsExecError, msg:
                     raise CompileError(msg)
                 continue
             else:
                 self.spawn([self.cc] + compile_opts + pp_opts +
                            [input_opt, output_opt] +
                            extra_postargs)
-            except DistutilsExecError as msg:
+            except DistutilsExecError, msg:
                 raise CompileError(msg)
 
         return objects
                 pass # XXX what goes here?
             try:
                 self.spawn([self.lib] + lib_args)
-            except DistutilsExecError as msg:
+            except DistutilsExecError, msg:
                 raise LibError(msg)
         else:
             log.debug("skipping %s (up-to-date)", output_filename)
             self.mkpath(os.path.dirname(output_filename))
             try:
                 self.spawn([self.linker] + ld_args)
-            except DistutilsExecError as msg:
+            except DistutilsExecError, msg:
                 raise LinkError(msg)
 
             # embed the manifest
             # will still consider the DLL up-to-date, but it will not have a
             # manifest.  Maybe we should link to a temp file?  OTOH, that
             # implies a build environment error that shouldn't go undetected.
-            mfid = 1 if target_desc == CCompiler.EXECUTABLE else 2
+            if target_desc == CCompiler.EXECUTABLE:
+                mfid = 1
+            else:
+                mfid = 2
             out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
             try:
                 self.spawn(['mt.exe', '-nologo', '-manifest',
                             temp_manifest, out_arg])
-            except DistutilsExecError as msg:
+            except DistutilsExecError, msg:
                 raise LinkError(msg)
         else:
             log.debug("skipping %s (up-to-date)", output_filename)

Lib/distutils/tests/test_msvc9compiler.py

         finally:
             msvc9compiler.find_vcvarsall = old_find_vcvarsall
 
+    def test_reg_class(self):
+        if sys.platform != 'win32':
+            # this test is only for win32
+            return
+
+        from distutils.msvc9compiler import Reg
+        self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx')
+
+        # looking for values that should exist on all
+        # windows registeries versions.
+        path = r'Software\Microsoft\Notepad'
+        v = Reg.get_value(path, "lfitalic")
+        self.assert_(v in (0, 1))
+
+        import _winreg
+        HKCU = _winreg.HKEY_CURRENT_USER
+        keys = Reg.read_keys(HKCU, 'xxxx')
+        self.assertEquals(keys, None)
+
+        keys = Reg.read_keys(HKCU, r'Software\Microsoft')
+        self.assert_('Notepad' in keys)
+
 def test_suite():
     return unittest.makeSuite(msvc9compilerTestCase)
 
 Library
 -------
 
+- Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler.
+  Original patch by Akira Kitada.
+
 - Issue #5334: array.fromfile() failed to insert values when EOFError was raised.
 
 - Issue #5385: Fixed mmap crash after resize failure on windows.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.