[Git][security-tracker-team/security-tracker][master] 2 commits: Update python exception syntax for Python 3.6 compatibility

Salvatore Bonaccorso carnil at debian.org
Sat Jul 14 13:56:44 BST 2018


Salvatore Bonaccorso pushed to branch master at Debian Security Tracker / security-tracker


Commits:
cc04ebb4 by Brian May at 2018-07-13T15:15:20+10:00
Update python exception syntax for Python 3.6 compatibility

- - - - -
bb1cdf7f by Salvatore Bonaccorso at 2018-07-14T14:56:11+02:00
Merge branch 'bam/security-tracker-update_python_exceptions'

- - - - -


14 changed files:

- bin/apt-update-file
- bin/check-syntax
- bin/contact-maintainers
- bin/list-queue
- bin/update-db
- bin/update-nvd
- check-external/unknown-packages.py
- lib/python/bugs.py
- lib/python/debian_support.py
- lib/python/sectracker/regexpcase.py
- lib/python/sectracker/xcollections.py
- lib/python/sectracker/xpickle.py
- lib/python/security_db.py
- lib/python/web_support.py


Changes:

=====================================
bin/apt-update-file
=====================================
--- a/bin/apt-update-file
+++ b/bin/apt-update-file
@@ -15,7 +15,7 @@ def setup_paths():
             return path
         idx = string.rfind(path, '/')
         if idx == -1:
-            raise ImportError, "could not setup paths"
+            raise ImportError("could not setup paths")
         path = path[0:idx]
 root_path = setup_paths()
 


=====================================
bin/check-syntax
=====================================
--- a/bin/check-syntax
+++ b/bin/check-syntax
@@ -14,7 +14,7 @@ def setup_paths():
             return path
         idx = string.rfind(path, '/')
         if idx == -1:
-            raise ImportError, "could not setup paths"
+            raise ImportError("could not setup paths")
         path = path[0:idx]
 root_path = setup_paths()
 
@@ -38,7 +38,7 @@ def do_parse(f):
                                      % r.name)
                 errors = True
             names[n] = r.name
-    except debian_support.ParseError, e:
+    except debian_support.ParseError as e:
         e.printOut(sys.stderr)
         errors = True
     if errors:


=====================================
bin/contact-maintainers
=====================================
--- a/bin/contact-maintainers
+++ b/bin/contact-maintainers
@@ -43,7 +43,7 @@ else:
         try:
             graph.parse('https://packages.qa.debian.org/{}/{}.rdf'
                         .format(re.match('((?:lib)?.)', pkg).group(1), pkg))
-        except urllib2.HTTPError, exc:
+        except urllib2.HTTPError as exc:
             if exc.code == 404:
                 raise ValueError("unknown package '{}'".format(pkg))
             raise


=====================================
bin/list-queue
=====================================
--- a/bin/list-queue
+++ b/bin/list-queue
@@ -180,7 +180,7 @@ def updatechanges(db, ondisk):
             try:
                 dist = changes["Distribution"]
                 debs = set(pkg["name"] for pkg in changes["Checksums-Sha1"])
-            except KeyError, e:
+            except KeyError as e:
                 raise IOError("missing key in " + repr(path) + ": "
                               + repr(e.args[0]))
             indb[path] = stat + (dist, debs)


=====================================
bin/update-db
=====================================
--- a/bin/update-db
+++ b/bin/update-db
@@ -14,7 +14,7 @@ def setup_paths():
             return path
         idx = string.rfind(path, '/')
         if idx == -1:
-            raise ImportError, "could not setup paths"
+            raise ImportError("could not setup paths")
         path = path[0:idx]
 os.chdir(setup_paths())
 
@@ -38,16 +38,16 @@ cursor = db.writeTxn()
 
 try:
     warnings = db.readBugs(cursor, 'data')
-except SyntaxError, e:
+except SyntaxError as e:
     if e.filename is None or e.lineno is None:
         print "error:", e
     else:
         print "%s:%d: %s" % (e.filename, e.lineno, e.msg)
     sys.exit(1)
-except debian_support.ParseError, e:
+except debian_support.ParseError as e:
     e.printOut(sys.stderr)
     sys.exit(1)
-except security_db.InsertError, e:
+except security_db.InsertError as e:
     for err in e.errors:
         print err
     sys.exit(1)
@@ -60,7 +60,7 @@ if warnings:
 
 try:
     db.readPackages(cursor, 'data/packages')
-except debian_support.ParseError, e:
+except debian_support.ParseError as e:
     e.printOut(sys.stderr)
     sys.exit(1)
 


=====================================
bin/update-nvd
=====================================
--- a/bin/update-nvd
+++ b/bin/update-nvd
@@ -14,7 +14,7 @@ def setup_paths():
             return path
         idx = string.rfind(path, '/')
         if idx == -1:
-            raise ImportError, "could not setup paths"
+            raise ImportError("could not setup paths")
         path = path[0:idx]
 os.chdir(setup_paths())
 


=====================================
check-external/unknown-packages.py
=====================================
--- a/check-external/unknown-packages.py
+++ b/check-external/unknown-packages.py
@@ -19,7 +19,7 @@ def setup_paths():
             return path
         idx = string.rfind(path, '/')
         if idx == -1:
-            raise ImportError, "could not setup paths"
+            raise ImportError("could not setup paths")
         path = path[0:idx]
 os.chdir(setup_paths())
 


=====================================
lib/python/bugs.py
=====================================
--- a/lib/python/bugs.py
+++ b/lib/python/bugs.py
@@ -65,12 +65,12 @@ class PackageNote:
             if type(release) == types.StringType:
                 release = debian_support.internRelease(release)
                 if release is None:
-                    raise ValueError, "invalid release"
+                    raise ValueError("invalid release")
             self.release = release
         if type(urgency) == types.StringType:
             urgency = internUrgency(urgency)
         if urgency is None:
-            raise ValueError, "invalid urgency"
+            raise ValueError("invalid urgency")
         self.urgency = urgency
         self.bugs = []
         self.package_kind = "unknown"
@@ -132,7 +132,7 @@ class PackageNoteFromDB(PackageNote):
             self.package_kind = package_kind
             self.loadBugs(cursor)
             return
-        raise ValueError, "invalid package note ID %d" % id
+        raise ValueError("invalid package note ID %d" % id)
 
 class PackageNoteParsed(PackageNote):
     """Subclass with a constructor that parses package notes."""
@@ -159,7 +159,7 @@ class PackageNoteParsed(PackageNote):
                     bugs.append(int(bug))
                     continue
 
-                raise SyntaxError , 'unknown package note %s\n' % `n`
+                raise SyntaxError('unknown package note %s\n' % repr(n))
         PackageNote.__init__(self, package, version, release, urgency)
         self.bugs = bugs
 
@@ -238,7 +238,7 @@ class BugBase:
                                 self.description, self.date or '',
                                 self.source_file, self.source_line))
             except apsw.ConstraintError:
-                raise ValueError, "bug name %s is not unique" % self.name
+                raise ValueError("bug name %s is not unique" % self.name)
 
         for (typ, c) in self.comments:
             cursor.execute("""INSERT INTO bugs_notes
@@ -254,8 +254,8 @@ class BugBase:
                 (source, target) VALUES (?, ?)""",
                                (self.name, x))
             except apsw.ConstraintError:
-                raise ValueError, \
-                      "cross reference to %s appears multiple times" % x
+                raise ValueError(
+                      "cross reference to %s appears multiple times" % x)
 
 class Bug(BugBase):
     """Class for bugs for which we have some data."""
@@ -332,7 +332,7 @@ class BugFromDB(Bug):
             if name_source == 'DSA' and 2 <= len(name_components) <= 3:
                 r = lookup_dsa('DSA-' + name_components[1])
             if r is None:
-                raise ValueError, "unknown bug " + `name`
+                raise ValueError("unknown bug " + repr(name))
 
         rdesc = cursor.getdescription()
         data = {}
@@ -467,7 +467,7 @@ class FileBase(debian_support.PackageFile):
         match = self.re_non_ascii.match(self.line)
         if match is not None:
             self.raiseSyntaxError('invalid non-printable character %s'
-                                  % `match.groups()[0]`)
+                                  % repr(match.groups()[0]))
 
     def rawRecords(self):
         """Generator which returns raw records.
@@ -546,13 +546,13 @@ class FileBase(debian_support.PackageFile):
                                 if re_entry.match(x):
                                     target.append(x)
                                 else:
-                                    self.raiseSyntaxError\
-                                        ("invalid cross reference " + `x`,
+                                    self.raiseSyntaxError(
+                                        "invalid cross reference " + repr(x),
                                          lineno)
                             return True
                         else:
                             self.raiseSyntaxError(
-                                "expected cross reference, got: " + `r`,
+                                "expected cross reference, got: " + repr(r),
                                 lineno)
                     else:
                         return False
@@ -640,11 +640,11 @@ class FileBase(debian_support.PackageFile):
                         else:
                             self.raiseSyntaxError(
                                 "invalid special version %s in package entry"
-                                % `r`, lineno)
+                                % repr(r), lineno)
                         continue
                     
                     self.raiseSyntaxError(
-                        "expected package entry, got: " + `r`, lineno)
+                        "expected package entry, got: " + repr(r), lineno)
 
                 if self.re_not_for_us_required.match(r):
                     match = self.re_not_for_us.match(r)
@@ -655,7 +655,7 @@ class FileBase(debian_support.PackageFile):
                         continue
                     else:
                         self.raiseSyntaxError("expected NOT-FOR-US entry, "
-                                              + "got: " + `r`, lineno)
+                                              + "got: " + repr(r), lineno)
 
                 match = self.re_reserved.match(r)
                 if match:
@@ -680,7 +680,7 @@ class FileBase(debian_support.PackageFile):
                     continue
 
                 self.raiseSyntaxError('expected CVE annotation, got: %s'
-                                      % `r`, lineno)
+                                      % repr(r), lineno)
                 break
 
             if cve_reserved:
@@ -759,7 +759,7 @@ class CVEFile(FileBase):
     def matchHeader(self, line):
         match = self.re_cve.match(line)
         if not match:
-            self.raiseSyntaxError("expected CVE record, got: %s" % `line`)
+            self.raiseSyntaxError("expected CVE record, got: %s" % repr(line))
             (record_name, description) = match.groups()
         (cve, desc) = match.groups()
         if desc:
@@ -820,13 +820,13 @@ class DSAFile(FileBase):
     def matchHeader(self, line):
         match = self.re_dsa.match(line)
         if not match:
-            self.raiseSyntaxError("expected %s record, got: %s" % (self.base, `line`))
+            self.raiseSyntaxError("expected %s record, got: %s" % (self.base, repr(line)))
             (record_name, description) = match.groups()
         (day, month, year, name, desc) = match.groups()
         try:
             month = self.month_names[month]
         except KeyError:
-            self.raiseSyntaxError("invalid month name %s" % `month`)
+            self.raiseSyntaxError("invalid month name %s" % repr(month))
         return ("%s-%02d-%s" % (year, month, day), name, desc)
 
     def finishBug(self, bug):
@@ -861,13 +861,13 @@ class DTSAFile(FileBase):
     def matchHeader(self, line):
         match = self.re_dsa.match(line)
         if not match:
-            self.raiseSyntaxError("expected DTSA record, got: %s" % `line`)
+            self.raiseSyntaxError("expected DTSA record, got: %s" % repr(line))
             (record_name, description) = match.groups()
         (month, day, year, name, desc) = match.groups()
         try:
             month = self.month_names[month]
         except KeyError:
-            self.raiseSyntaxError("invalid month name %s" % `month`)
+            self.raiseSyntaxError("invalid month name %s" % repr(month))
         return ("%s-%02d-%02d" % (year, month, int(day)), name, desc)
 
     def finishBug(self, bug):


=====================================
lib/python/debian_support.py
=====================================
--- a/lib/python/debian_support.py
+++ b/lib/python/debian_support.py
@@ -60,9 +60,9 @@ class ParseError(Exception):
         return self.msg
 
     def __repr__(self):
-        return "ParseError(%s, %d, %s)" % (`self.filename`,
+        return "ParseError(%s, %d, %s)" % (repr(self.filename),
                                            self.lineno,
-                                           `self.msg`)
+                                           repr(self.msg))
 
     def printOut(self, file):
         """Writes a machine-parsable error message to file."""
@@ -231,7 +231,7 @@ def patchesFromEdScript(source,
     for line in i:
         match = re_cmd.match(line)
         if match is None:
-            raise ValueError, "invalid patch command: " + `line`
+            raise ValueError("invalid patch command: " + repr(line))
 
         (first, last, cmd) = match.groups()
         first = int(first)
@@ -247,7 +247,7 @@ def patchesFromEdScript(source,
 
         if cmd == 'a':
             if last is not None:
-                raise ValueError, "invalid patch argument: " + `line`
+                raise ValueError("invalid patch argument: " + repr(line))
             last = first
         else:                           # cmd == c
             first = first - 1
@@ -257,7 +257,7 @@ def patchesFromEdScript(source,
         lines = []
         for l in i:
             if l == '':
-                raise ValueError, "end of stream in command: " + `line`
+                raise ValueError("end of stream in command: " + repr(line))
             if l == '.\n' or l == '.':
                 break
             lines.append(l)
@@ -392,7 +392,7 @@ def updateFile(remote, local, verbose=None):
         try:
             patch_contents = downloadGunzipLines(remote + '.diff/' + patch_name
                                                  + '.gz')
-        except IOError, e:
+        except IOError:
             return downloadFile(remote, local)
         if readLinesSHA1(patch_contents ) <> patch_hashes[patch_name]:
             if verbose:
@@ -449,7 +449,7 @@ class BinaryPackage(object):
                 if match is None:
                     raise SyntaxError(('package %s references '
                                        + 'invalid source package %s') %
-                                      (pkg_name, `contents`))
+                                      (pkg_name, repr(contents)))
                 (pkg_source, pkg_source_version) = match.groups()
             elif name == "architecture":
                 pkg_arch = contents


=====================================
lib/python/sectracker/regexpcase.py
=====================================
--- a/lib/python/sectracker/regexpcase.py
+++ b/lib/python/sectracker/regexpcase.py
@@ -74,7 +74,7 @@ class RegexpCase(object):
 
     def __call__(self, key, *args):
         if not self.maycall:
-            raise TypeError, "not all actions are callable"
+            raise TypeError("not all actions are callable")
         (groups, action) = self.match(key)
         if action is None:
             return None


=====================================
lib/python/sectracker/xcollections.py
=====================================
--- a/lib/python/sectracker/xcollections.py
+++ b/lib/python/sectracker/xcollections.py
@@ -80,7 +80,7 @@ def namedtuple(typename, field_names, verbose=False):
                      _property=property, _tuple=tuple)
     try:
         exec template in namespace
-    except SyntaxError, e:
+    except SyntaxError as e:
         raise SyntaxError(e.message + ':\n' + template)
     result = namespace[typename]
 


=====================================
lib/python/sectracker/xpickle.py
=====================================
--- a/lib/python/sectracker/xpickle.py
+++ b/lib/python/sectracker/xpickle.py
@@ -29,7 +29,7 @@ def safeunlink(path):
     No exception is thrown if the file does not exist."""
     try:
         _os.unlink(path)
-    except OSError, e:
+    except OSError as e:
         if e.errno != _errno.ENOENT:
             raise e
 


=====================================
lib/python/security_db.py
=====================================
--- a/lib/python/security_db.py
+++ b/lib/python/security_db.py
@@ -270,7 +270,7 @@ class DB:
                 if self.verbose:
                     print "DB: schema version mismatch: expected %d, got %d" \
                           % (self.schema_version, v)
-                raise SchemaMismatch, `v`
+                raise SchemaMismatch(repr(v))
             self._initViews(c)
             return
         assert False
@@ -732,7 +732,7 @@ class DB:
         for filename in glob.glob(directory + '/*_Sources'):
             match = re_sources.match(filename)
             if match is None:
-                raise ValueError, "invalid file name: " + `filename`
+                raise ValueError("invalid file name: " + repr(filename))
 
             (release, subrelease, archive) = match.groups()
             (unchanged, parsed) = self._parseFile(cursor, filename)
@@ -799,7 +799,7 @@ class DB:
         for filename in filenames:
             match = re_packages.match(filename)
             if match is None:
-                raise ValueError, "invalid file name: " + `filename`
+                raise ValueError("invalid file name: " + repr(filename))
 
             (release, subrelease, archive, architecture) = match.groups()
             if release == 'squeeze-lts':
@@ -814,7 +814,7 @@ class DB:
                 if source_version is None:
                     source_version = version
                 if arch <> 'all' and arch <> architecture:
-                    raise ValueError, ("invalid architecture %s for package %s"
+                    raise ValueError("invalid architecture %s for package %s"
                                        % (arch, name))
                 key = (name, release, subrelease, archive, version,
                        source, source_version)
@@ -836,7 +836,7 @@ class DB:
         l = packages.keys()
 
         if len(l) == 0:
-            raise ValueError, "no binary packages found"
+            raise ValueError("no binary packages found")
 
         l.sort()
         def gen():
@@ -913,7 +913,7 @@ class DB:
             for bug in source:
                 try:
                     bug.writeDB(cursor)
-                except ValueError, e:
+                except ValueError as e:
                     errors.append("%s: %d: error: %s"
                                   % (bug.source_file, bug.source_line, e))
             if errors:
@@ -1937,7 +1937,7 @@ class DB:
                 if match:
                     yield match.groups()
                 else:
-                    raise ValueError, "not a package: " + `line`
+                    raise ValueError("not a package: " + repr(line))
 
         cursor.executemany(
             "INSERT OR IGNORE INTO removed_packages (name) VALUES (?)", gen())


=====================================
lib/python/web_support.py
=====================================
--- a/lib/python/web_support.py
+++ b/lib/python/web_support.py
@@ -320,7 +320,7 @@ class Tag(HTMLBase):
         if self.re_name.match(name):
             return
         else:
-            raise ValueError, "invalid name: " + `name`
+            raise ValueError("invalid name: " + repr(name))
 
     def flatten(self, write):
         if self.contents:
@@ -552,13 +552,13 @@ class PathRouter:
                 else:
                     if element == '*':
                         if x + 1 <> len(p):
-                            raise ValueError, 'wildcard * in the middle of path'
+                            raise ValueError('wildcard * in the middle of path')
                         m['*'] = value
                         return
                     if element == '**':
                         if x + 1 <> len(p):
-                            raise ValueError, \
-                                  'wildcard ** in the middle of path'
+                            raise ValueError(
+                                  'wildcard ** in the middle of path')
                         m['**'] = value
                         return
 
@@ -566,7 +566,7 @@ class PathRouter:
                     m[element] = m_new
                     m = m_new
             else:
-                raise ValueError, "path contains empty element"
+                raise ValueError("path contains empty element")
         m[''] = value
 
     def get(self, path):
@@ -592,7 +592,7 @@ class PathRouter:
                         return (m['*'], tuple(p[x:]))
                     if m.has_key('**'):
                         return (m['**'], tuple(p[x:]))
-                    raise InvalidPath
+                    raise InvalidPath()
         try:
             result = m['']
         except KeyError:
@@ -601,7 +601,7 @@ class PathRouter:
             elif m.has_key('**'):
                 result = m['**']
             else:
-                raise InvalidPath
+                raise InvalidPath()
         return (result, ())
 
 class Result(object):



View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/b0120d237af70d17cb22a904b542d47d4fde04dc...bb1cdf7f4115028605341c2c1157010a8b91b737

-- 
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/compare/b0120d237af70d17cb22a904b542d47d4fde04dc...bb1cdf7f4115028605341c2c1157010a8b91b737
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-security-tracker-commits/attachments/20180714/8de9f927/attachment-0001.html>


More information about the debian-security-tracker-commits mailing list