Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (2)
Update python exception syntax for Python 3.6 compatibility
· cc04ebb4
Brian May
authored
Jun 18, 2018
cc04ebb4
Merge branch 'bam/security-tracker-update_python_exceptions'
· bb1cdf7f
Salvatore Bonaccorso
authored
Jul 14, 2018
bb1cdf7f
Show whitespace changes
Inline
Side-by-side
bin/apt-update-file
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
-%
02
d
-%
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
-%
02
d
-%
02
d
"
% (year, month, int(day)), name, desc)
def finishBug(self, bug):
...
...
lib/python/debian_support.py
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
View file @
bb1cdf7f
...
...
@@ -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
):
...
...