[Lxml-checkins] r54966 - in lxml/trunk: . src/lxml/html

scoder at codespeak.net scoder at codespeak.net
Mon May 19 23:59:47 CEST 2008


Author: scoder
Date: Mon May 19 23:59:46 2008
New Revision: 54966

Modified:
   lxml/trunk/   (props changed)
   lxml/trunk/src/lxml/html/__init__.py
   lxml/trunk/test.py
Log:
 r4224 at delle:  sbehnel | 2008-05-18 13:36:07 +0200
 Py3 syntax fixes


Modified: lxml/trunk/src/lxml/html/__init__.py
==============================================================================
--- lxml/trunk/src/lxml/html/__init__.py	(original)
+++ lxml/trunk/src/lxml/html/__init__.py	Mon May 19 23:59:46 2008
@@ -191,7 +191,7 @@
             if default:
                 return default[0]
             else:
-                raise KeyError, id
+                raise KeyError(id)
 
     def text_content(self):
         """
@@ -1392,7 +1392,7 @@
     fn = os.tempnam() + '.html'
     write_doc(fn, method="html")
     url = 'file://' + fn.replace(os.path.sep, '/')
-    print url
+    print(url)
     webbrowser.open(url)
     
 ################################################################################

Modified: lxml/trunk/test.py
==============================================================================
--- lxml/trunk/test.py	(original)
+++ lxml/trunk/test.py	Mon May 19 23:59:46 2008
@@ -71,10 +71,16 @@
 import getopt
 import unittest
 import traceback
-from sets import Set
+try:
+    set
+except NameError:
+    from sets import Set as set
 
 __metaclass__ = type
 
+def stderr(text):
+    sys.stderr.write(text)
+    sys.stderr.write("\n")
 
 class Options:
     """Configurable properties of the test runner."""
@@ -169,7 +175,7 @@
                         results.append(path)
             return
         if '__init__.py' not in files:
-            print >> sys.stderr, "%s is not a package" % dir
+            stderr("%s is not a package" % dir)
             return
         for file in files:
             if file.startswith('test') and file.endswith('.py'):
@@ -236,7 +242,7 @@
     """Returns a set of test case classes used in a test suite."""
     if not isinstance(suite, unittest.TestSuite):
         raise TypeError('not a TestSuite', suite)
-    results = Set()
+    results = set()
     for test in suite._tests:
         if isinstance(test, unittest.TestCase):
             results.add(test.__class__)
@@ -259,16 +265,14 @@
         if test_suite is None:
             continue
         if cfg.warn_omitted:
-            all_classes = Set(get_all_test_cases(module))
+            all_classes = set(get_all_test_cases(module))
             classes_in_suite = get_test_classes_from_testsuite(test_suite)
             difference = all_classes - classes_in_suite
             for test_class in difference:
                 # surround the warning with blank lines, otherwise it tends
                 # to get lost in the noise
-                print >> sys.stderr
-                print >> sys.stderr, ("%s: WARNING: %s not in test suite"
+                stderr("\n%s: WARNING: %s not in test suite\n"
                                       % (file, test_class.__name__))
-                print >> sys.stderr
         if (cfg.level is not None and
             getattr(test_suite, 'level', 0) > cfg.level):
             continue
@@ -280,7 +284,7 @@
 def get_test_hooks(test_files, cfg, tracer=None):
     """Returns a list of test hooks from a given list of test modules."""
     results = []
-    dirs = Set(map(os.path.dirname, test_files))
+    dirs = set(map(os.path.dirname, test_files))
     for dir in list(dirs):
         if os.path.basename(dir) == 'ftests':
             dirs.add(os.path.join(os.path.dirname(dir), 'tests'))
@@ -425,7 +429,7 @@
             self.stream.writeln()
         if not result.wasSuccessful():
             self.stream.write("FAILED (")
-            failed, errored = map(len, (result.failures, result.errors))
+            failed, errored = list(map(len, (result.failures, result.errors)))
             if failed:
                 self.stream.write("failures=%d" % failed)
             if errored:
@@ -447,8 +451,8 @@
 
     # Environment
     if sys.version_info < (2, 3):
-        print >> sys.stderr, '%s: need Python 2.3 or later' % argv[0]
-        print >> sys.stderr, 'your python is %s' % sys.version
+        stderr('%s: need Python 2.3 or later' % argv[0])
+        stderr('your python is %s' % sys.version)
         return 1
 
     # Defaults
@@ -476,7 +480,7 @@
                                     'level=', 'all-levels', 'coverage'])
     for k, v in opts:
         if k == '-h':
-            print __doc__
+            print(__doc__)
             return 0
         elif k == '-v':
             cfg.verbosity += 1
@@ -509,22 +513,22 @@
             try:
                 cfg.level = int(v)
             except ValueError:
-                print >> sys.stderr, '%s: invalid level: %s' % (argv[0], v)
-                print >> sys.stderr, 'run %s -h for help'
+                stderr('%s: invalid level: %s' % (argv[0], v))
+                stderr('run %s -h for help')
                 return 1
         elif k == '--all-levels':
             cfg.level = None
         else:
-            print >> sys.stderr, '%s: invalid option: %s' % (argv[0], k)
-            print >> sys.stderr, 'run %s -h for help'
+            stderr('%s: invalid option: %s' % (argv[0], k))
+            stderr('run %s -h for help')
             return 1
     if args:
         cfg.pathname_regex = args[0]
     if len(args) > 1:
         cfg.test_regex = args[1]
     if len(args) > 2:
-        print >> sys.stderr, '%s: too many arguments: %s' % (argv[0], args[2])
-        print >> sys.stderr, 'run %s -h for help'
+        stderr('%s: too many arguments: %s' % (argv[0], args[2]))
+        stderr('run %s -h for help')
         return 1
     if not cfg.unit_tests and not cfg.functional_tests:
         cfg.unit_tests = True
@@ -564,11 +568,11 @@
     success = True
     if cfg.list_files:
         baselen = len(cfg.basedir) + 1
-        print "\n".join([fn[baselen:] for fn in test_files])
+        print("\n".join([fn[baselen:] for fn in test_files]))
     if cfg.list_tests:
-        print "\n".join([test.id() for test in test_cases])
+        print("\n".join([test.id() for test in test_cases]))
     if cfg.list_hooks:
-        print "\n".join([str(hook) for hook in test_hooks])
+        print("\n".join([str(hook) for hook in test_hooks]))
     if cfg.run_tests:
         runner = CustomTestRunner(cfg, test_hooks)
         suite = unittest.TestSuite()


More information about the lxml-checkins mailing list