[python-debian/master 02/36] Avoid various old syntactic forms which are no longer present in Python 3. All of these work from at least Python 2.6.
Colin Watson
cjwatson at canonical.com
Mon Oct 8 07:41:19 UTC 2012
---
examples/deb822/grep-maintainer | 2 +-
examples/debtags/wxssearch | 1 -
lib/debian/arfile.py | 14 +++++++-------
lib/debian/deb822.py | 13 ++++++-------
lib/debian/debian_support.py | 32 +++++++++++++++-----------------
tests/test_deb822.py | 9 ---------
6 files changed, 29 insertions(+), 42 deletions(-)
diff --git a/examples/deb822/grep-maintainer b/examples/deb822/grep-maintainer
index 24f2f84..53a956c 100755
--- a/examples/deb822/grep-maintainer
+++ b/examples/deb822/grep-maintainer
@@ -19,7 +19,7 @@ try:
except IndexError:
print >>sys.stderr, "Usage: grep-maintainer REGEXP"
sys.exit(1)
-except re.error, e:
+except re.error as e:
print >>sys.stderr, "Error in the regexp: %s" % (e,)
sys.exit(1)
diff --git a/examples/debtags/wxssearch b/examples/debtags/wxssearch
index 4fb3c4c..a0aeb37 100755
--- a/examples/debtags/wxssearch
+++ b/examples/debtags/wxssearch
@@ -248,7 +248,6 @@ class Results(wx.ListCtrl):
def model_changed(self, event):
self.packages = sorted(self.model.subcoll.iter_packages())
- self.packages.sort()
self.SetItemCount(len(self.packages))
self.resize_columns()
event.Skip()
diff --git a/lib/debian/arfile.py b/lib/debian/arfile.py
index 9ad757e..c9cb87a 100644
--- a/lib/debian/arfile.py
+++ b/lib/debian/arfile.py
@@ -53,10 +53,10 @@ class ArFile(object):
elif self.__fileobj:
fp = self.__fileobj
else:
- raise ArError, "Unable to open valid file"
+ raise ArError("Unable to open valid file")
if fp.read(GLOBAL_HEADER_LENGTH) != GLOBAL_HEADER:
- raise ArError, "Unable to find global header"
+ raise ArError("Unable to find global header")
while True:
newmember = ArMember.from_file(fp, self.__fname)
@@ -100,12 +100,12 @@ class ArFile(object):
def extractall():
""" Not (yet) implemented. """
- raise NotImpelementedError # TODO
+ raise NotImplementedError # TODO
def extract(self, member, path):
""" Not (yet) implemented. """
- raise NotImpelementedError # TODO
+ raise NotImplementedError # TODO
def extractfile(self, member):
""" Return a file object corresponding to the requested member. A member
@@ -171,10 +171,10 @@ class ArMember(object):
# sanity checks
if len(buf) < FILE_HEADER_LENGTH:
- raise IOError, "Incorrect header length"
+ raise IOError("Incorrect header length")
if buf[58:60] != FILE_MAGIC:
- raise IOError, "Incorrect file magic"
+ raise IOError("Incorrect file magic")
# http://en.wikipedia.org/wiki/Ar_(Unix)
#from to Name Format
@@ -263,7 +263,7 @@ class ArMember(object):
self.__fp.seek(self.__offset)
if whence < 2 and offset + self.__fp.tell() < self.__offset:
- raise IOError, "Can't seek at %d" % offset
+ raise IOError("Can't seek at %d" % offset)
if whence == 1:
self.__fp.seek(offset, 1)
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index 0d0be2c..a1a49ce 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -192,7 +192,7 @@ class Deb822Dict(object, UserDict.DictMixin):
# Always return unicode objects instead of strings
try:
value = value.decode(self.encoding)
- except UnicodeDecodeError, e:
+ except UnicodeDecodeError as e:
# Evidently, the value wasn't encoded with the encoding the
# user specified. Try detecting it.
warnings.warn('decoding from %s failed; attempting to detect '
@@ -234,8 +234,8 @@ class Deb822Dict(object, UserDict.DictMixin):
return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()])
def __eq__(self, other):
- mykeys = self.keys(); mykeys.sort()
- otherkeys = other.keys(); otherkeys.sort()
+ mykeys = sorted(self)
+ otherkeys = sorted(other)
if not mykeys == otherkeys:
return False
@@ -485,8 +485,7 @@ class Deb822(Deb822Dict):
if (s1 + s2).count(', '):
delim = ', '
- L = (s1 + delim + s2).split(delim)
- L.sort()
+ L = sorted((s1 + delim + s2).split(delim))
prev = merged = L[0]
@@ -621,7 +620,7 @@ class Deb822(Deb822Dict):
# _gpg_multivalued.__init__) which is small compared to Packages or
# Sources which contain no signature
if not hasattr(self, 'raw_text'):
- raise ValueError, "original text cannot be found"
+ raise ValueError("original text cannot be found")
if self.gpg_info is None:
self.gpg_info = GpgInfo.from_sequence(self.raw_text,
@@ -738,7 +737,7 @@ class GpgInfo(dict):
args.extend(["--keyring", k])
if "--keyring" not in args:
- raise IOError, "cannot access any of the given keyrings"
+ raise IOError("cannot access any of the given keyrings")
p = subprocess.Popen(args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
diff --git a/lib/debian/debian_support.py b/lib/debian/debian_support.py
index f0577ac..9f065ff 100644
--- a/lib/debian/debian_support.py
+++ b/lib/debian/debian_support.py
@@ -53,9 +53,9 @@ class ParseError(Exception):
return self.msg
def __repr__(self):
- return "ParseError(%s, %d, %s)" % (`self.filename`,
+ return "ParseError(%r, %d, %r)" % (self.filename,
self.lineno,
- `self.msg`)
+ self.msg)
def print_out(self, file):
"""Writes a machine-parsable error message to file."""
@@ -192,7 +192,7 @@ class NativeVersion(BaseVersion):
if not isinstance(other, BaseVersion):
try:
other = BaseVersion(str(other))
- except ValueError, e:
+ except ValueError as e:
raise ValueError("Couldn't convert %r to BaseVersion: %s"
% (other, e))
@@ -337,7 +337,7 @@ class PseudoEnum:
self._name = name
self._order = order
def __repr__(self):
- return '%s(%s)'% (self.__class__._name__, `name`)
+ return '%s(%r)' % (self.__class__._name__, self._name)
def __str__(self):
return self._name
def __cmp__(self, other):
@@ -392,7 +392,7 @@ def patches_from_ed_script(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: %r" % line)
(first, last, cmd) = match.groups()
first = int(first)
@@ -408,7 +408,7 @@ def patches_from_ed_script(source,
if cmd == 'a':
if last is not None:
- raise ValueError, "invalid patch argument: " + `line`
+ raise ValueError("invalid patch argument: %r" % line)
last = first
else: # cmd == c
first = first - 1
@@ -418,7 +418,7 @@ def patches_from_ed_script(source,
lines = []
for l in i:
if l == '':
- raise ValueError, "end of stream in command: " + `line`
+ raise ValueError("end of stream in command: %r" % line)
if l == '.\n' or l == '.':
break
lines.append(l)
@@ -561,7 +561,7 @@ def update_file(remote, local, verbose=None):
continue
if verbose:
- print "update_file: field %s ignored" % `field`
+ print "update_file: field %r ignored" % field
if not patches_to_apply:
if verbose:
@@ -569,17 +569,17 @@ def update_file(remote, local, verbose=None):
return download_file(remote, local)
for patch_name in patches_to_apply:
- print "update_file: downloading patch " + `patch_name`
+ print "update_file: downloading patch %r" % patch_name
patch_contents = download_gunzip_lines(remote + '.diff/' + patch_name
+ '.gz')
- if read_lines_sha1(patch_contents ) <> patch_hashes[patch_name]:
- raise ValueError, "patch %s was garbled" % `patch_name`
+ if read_lines_sha1(patch_contents ) != patch_hashes[patch_name]:
+ raise ValueError("patch %r was garbled" % patch_name)
patch_lines(lines, patches_from_ed_script(patch_contents))
new_hash = read_lines_sha1(lines)
- if new_hash <> remote_hash:
- raise ValueError, ("patch failed, got %s instead of %s"
- % (new_hash, remote_hash))
+ if new_hash != remote_hash:
+ raise ValueError("patch failed, got %s instead of %s"
+ % (new_hash, remote_hash))
replace_file(lines, local)
return lines
@@ -593,8 +593,6 @@ def merge_as_sets(*args):
for x in args:
for y in x:
s[y] = True
- l = s.keys()
- l.sort()
- return l
+ return sorted(s)
mergeAsSets = function_deprecated_by(merge_as_sets)
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index c3806bd..82c3540 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -29,15 +29,6 @@ sys.path.insert(0, '../lib/debian/')
import deb822
-# Keep the test suite compatible with python2.3 for now
-try:
- sorted
-except NameError:
- def sorted(iterable, cmp=None):
- tmp = iterable[:]
- tmp.sort(cmp)
- return tmp
-
UNPARSED_PACKAGE = '''\
Package: mutt
--
1.7.2.5
More information about the pkg-python-debian-commits
mailing list