diff options
author | Brian May <brian@linuxpenguins.xyz> | 2018-06-18 17:11:31 +1000 |
---|---|---|
committer | Brian May <brian@linuxpenguins.xyz> | 2018-07-13 15:15:20 +1000 |
commit | cc04ebb4f6ebbf80080b7990d710a55fd55a19a2 (patch) | |
tree | ea5ffabe533be6124b9c30bc82af3e23d08f10dc /lib | |
parent | 9889b3ebf70085d28f84371a931adcced2ff19fd (diff) |
Update python exception syntax for Python 3.6 compatibility
Diffstat (limited to 'lib')
-rw-r--r-- | lib/python/bugs.py | 42 | ||||
-rw-r--r-- | lib/python/debian_support.py | 14 | ||||
-rw-r--r-- | lib/python/sectracker/regexpcase.py | 2 | ||||
-rw-r--r-- | lib/python/sectracker/xcollections.py | 2 | ||||
-rw-r--r-- | lib/python/sectracker/xpickle.py | 2 | ||||
-rw-r--r-- | lib/python/security_db.py | 14 | ||||
-rw-r--r-- | lib/python/web_support.py | 14 |
7 files changed, 45 insertions, 45 deletions
diff --git a/lib/python/bugs.py b/lib/python/bugs.py index bcfa9b1ce5..84b0d4caed 100644 --- 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): diff --git a/lib/python/debian_support.py b/lib/python/debian_support.py index fb44bc5771..717705dcd2 100644 --- 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 diff --git a/lib/python/sectracker/regexpcase.py b/lib/python/sectracker/regexpcase.py index 47849686cb..f77d672770 100644 --- 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 diff --git a/lib/python/sectracker/xcollections.py b/lib/python/sectracker/xcollections.py index cf7528ad5b..4dbf38010e 100644 --- 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] diff --git a/lib/python/sectracker/xpickle.py b/lib/python/sectracker/xpickle.py index 216566e5ed..9a7296e4cc 100644 --- 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 diff --git a/lib/python/security_db.py b/lib/python/security_db.py index dcca00f9fd..efebe8b0ed 100644 --- 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()) diff --git a/lib/python/web_support.py b/lib/python/web_support.py index c28452d5a0..1e204d06bc 100644 --- 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): |