diff options
| author | Bastian Blank <waldi@debian.org> | 2014-01-02 22:18:35 +0000 |
|---|---|---|
| committer | Bastian Blank <waldi@debian.org> | 2014-01-02 22:18:35 +0000 |
| commit | b142d22431f4a50358390eec7aaa994e7869cd35 (patch) | |
| tree | 5a46db5d92c8a0b8bc24378777bbcd789482c44d /debian/lib | |
| parent | fb642c8e06e196f54ee68ef23a57153897c7be69 (diff) | |
| download | kernel_replicant_linux-b142d22431f4a50358390eec7aaa994e7869cd35.tar.gz kernel_replicant_linux-b142d22431f4a50358390eec7aaa994e7869cd35.tar.bz2 kernel_replicant_linux-b142d22431f4a50358390eec7aaa994e7869cd35.zip | |
debian/lib/python/debian_linux: More Python 3 support.
svn path=/dists/trunk/linux/; revision=20954
Diffstat (limited to 'debian/lib')
| -rw-r--r-- | debian/lib/python/debian_linux/debian.py | 52 | ||||
| -rw-r--r-- | debian/lib/python/debian_linux/gencontrol.py | 17 |
2 files changed, 35 insertions, 34 deletions
diff --git a/debian/lib/python/debian_linux/debian.py b/debian/lib/python/debian_linux/debian.py index 532b5d3e8643..160c9630f4b3 100644 --- a/debian/lib/python/debian_linux/debian.py +++ b/debian/lib/python/debian_linux/debian.py @@ -1,8 +1,8 @@ import collections -import itertools import os.path -import six import re +import six +import six.moves from . import utils @@ -86,11 +86,9 @@ $ self.upstream = match.group("upstream") self.revision = match.group("revision") - def __unicode__(self): - return self.complete - def __str__(self): - return unicode(self).encode('utf-8') + return self.complete + __unicode__ = __str__ @property def complete(self): @@ -189,8 +187,9 @@ class PackageArchitecture(collections.MutableSet): def __len__(self): return self._data.__len__() - def __unicode__(self): + def __str__(self): return u' '.join(sorted(self)) + __unicode__ = __str__ def add(self, value): self._data.add(value) @@ -199,7 +198,7 @@ class PackageArchitecture(collections.MutableSet): self._data.discard(value) def extend(self, value): - if isinstance(value, basestring): + if isinstance(value, six.string_types): for i in re.split('\s', value.strip()): self.add(i) else: @@ -217,7 +216,7 @@ class PackageDescription(object): self.append(long) self.append_short(short) - def __unicode__(self): + def __str__(self): wrap = utils.TextWrapper(width=74, fix_sentence_endings=True).wrap short = u', '.join(self.short) long_pars = [] @@ -225,6 +224,7 @@ class PackageDescription(object): long_pars.append(wrap(i)) long = u'\n .\n '.join([u'\n '.join(i) for i in long_pars]) return short + u'\n ' + long + __unicode__ = __str__ def append(self, str): str = str.strip() @@ -249,8 +249,9 @@ class PackageRelation(list): if value: self.extend(value, override_arches) - def __unicode__(self): - return u', '.join((unicode(i) for i in self)) + def __str__(self): + return u', '.join(six.text_type(i) for i in self) + __unicode__ = __str__ def _search_value(self, value): for i in self: @@ -259,7 +260,7 @@ class PackageRelation(list): return None def append(self, value, override_arches=None): - if isinstance(value, basestring): + if isinstance(value, six.string_types): value = PackageRelationGroup(value, override_arches) elif not isinstance(value, PackageRelationGroup): raise ValueError(u"got %s" % type(value)) @@ -270,7 +271,7 @@ class PackageRelation(list): super(PackageRelation, self).append(value) def extend(self, value, override_arches=None): - if isinstance(value, basestring): + if isinstance(value, six.string_types): value = (j.strip() for j in re.split(u',', value.strip())) for i in value: self.append(i, override_arches) @@ -281,31 +282,32 @@ class PackageRelationGroup(list): if value: self.extend(value, override_arches) - def __unicode__(self): - return u' | '.join((unicode(i) for i in self)) + def __str__(self): + return u' | '.join(six.text_type(i) for i in self) + __unicode__ = __str__ def _search_value(self, value): - for i, j in itertools.izip(self, value): + for i, j in six.moves.zip(self, value): if i.name != j.name or i.version != j.version: return None return self def _update_arches(self, value): - for i, j in itertools.izip(self, value): + for i, j in six.moves.zip(self, value): if i.arches: for arch in j.arches: if arch not in i.arches: i.arches.append(arch) def append(self, value, override_arches=None): - if isinstance(value, basestring): + if isinstance(value, six.string_types): value = PackageRelationEntry(value, override_arches) elif not isinstance(value, PackageRelationEntry): raise ValueError super(PackageRelationGroup, self).append(value) def extend(self, value, override_arches=None): - if isinstance(value, basestring): + if isinstance(value, six.string_types): value = (j.strip() for j in re.split('\|', value.strip())) for i in value: self.append(i, override_arches) @@ -352,11 +354,12 @@ class PackageRelationEntry(object): def __neg__(self): return self.__class__(self.operators_text[self.operators_neg[self._op]]) - def __unicode__(self): + def __str__(self): return self.operators_text[self._op] + __unicode__ = __str__ def __init__(self, value=None, override_arches=None): - if not isinstance(value, basestring): + if not isinstance(value, six.string_types): raise ValueError self.parse(value) @@ -364,13 +367,14 @@ class PackageRelationEntry(object): if override_arches: self.arches = list(override_arches) - def __unicode__(self): + def __str__(self): ret = [self.name] if self.operator is not None and self.version is not None: - ret.extend((u' (', unicode(self.operator), u' ', self.version, u')')) + ret.extend((u' (', six.text_type(self.operator), u' ', self.version, u')')) if self.arches: ret.extend((u' [', u' '.join(self.arches), u']')) return u''.join(ret) + __unicode__ = __str__ def parse(self, value): match = self._re.match(value) @@ -423,7 +427,7 @@ class Package(dict): def iterkeys(self): keys = set(self.keys()) - for i in self._fields.iterkeys(): + for i in self._fields.keys(): if i in self: keys.remove(i) yield i diff --git a/debian/lib/python/debian_linux/gencontrol.py b/debian/lib/python/debian_linux/gencontrol.py index 9aa240e147b7..7024a484886b 100644 --- a/debian/lib/python/debian_linux/gencontrol.py +++ b/debian/lib/python/debian_linux/gencontrol.py @@ -1,4 +1,5 @@ import codecs +import six from collections import OrderedDict from .debian import * @@ -29,9 +30,7 @@ class Makefile(object): self.rules[i] = self.Rule(i) def write(self, out): - r = self.rules.keys() - r.sort() - for i in r: + for i in sorted(self.rules.keys()): self.rules[i].write(out) class Rule(object): @@ -70,7 +69,7 @@ class MakeFlags(dict): return "%s(%s)" % (self.__class__.__name__, repr) def __str__(self): - return ' '.join(["%s='%s'" % i for i in sorted(self.iteritems())]) + return ' '.join("%s='%s'" % i for i in sorted(self.items())) def copy(self): return self.__class__(super(MakeFlags, self).copy()) @@ -138,9 +137,7 @@ class Gencontrol(object): i = extra_arches.get(arch, []) i.append(package) extra_arches[arch] = i - archs = extra_arches.keys() - archs.sort() - for arch in archs: + for arch in sorted(extra_arches.keys()): cmds = [] for i in extra_arches[arch]: cmds.append("$(MAKE) -f debian/rules.real install-dummy ARCH='%s' DH_OPTIONS='-p%s'" % (arch, i['Package'])) @@ -278,10 +275,10 @@ class Gencontrol(object): def subst(match): return vars[match.group(1)] - return re.sub(r'@([-_a-z]+)@', subst, unicode(s)) + return re.sub(r'@([-_a-z]+)@', subst, six.text_type(s)) def write(self, packages, makefile): - self.write_control(packages.itervalues()) + self.write_control(packages.values()) self.write_makefile(makefile) def write_config(self): @@ -293,7 +290,7 @@ class Gencontrol(object): self.write_rfc822(codecs.open("debian/control", 'w', 'utf-8'), list) def write_makefile(self, makefile): - f = file("debian/rules.gen", 'w') + f = open("debian/rules.gen", 'w') makefile.write(f) f.close() |
