diff options
| -rw-r--r-- | apt/cache.py | 16 | ||||
| -rw-r--r-- | apt/package.py | 10 | ||||
| -rw-r--r-- | aptsources/distinfo.py | 6 | ||||
| -rw-r--r-- | aptsources/distro.py | 12 | ||||
| -rw-r--r-- | aptsources/sourceslist.py | 4 | ||||
| -rw-r--r-- | doc/examples/all_deps.py | 4 | ||||
| -rwxr-xr-x | doc/examples/configisc.py | 2 | ||||
| -rwxr-xr-x | doc/examples/records.py | 2 | ||||
| -rw-r--r-- | tests/test_aptsources.py | 4 | ||||
| -rwxr-xr-x | utils/get_ubuntu_mirrors_from_lp.py | 2 |
10 files changed, 30 insertions, 32 deletions
diff --git a/apt/cache.py b/apt/cache.py index 340b5696..576ef8c6 100644 --- a/apt/cache.py +++ b/apt/cache.py @@ -60,7 +60,7 @@ class Cache(object): def _runCallbacks(self, name): """ internal helper to run a callback """ - if self._callbacks.has_key(name): + if name in self._callbacks: for callback in self._callbacks[name]: callback() @@ -105,8 +105,8 @@ class Cache(object): yield self._dict[pkgname] raise StopIteration - def has_key(self, key): - return self._dict.has_key(key) + def __contains__(self, key): + return (key in self._dict) def __len__(self): return len(self._dict) @@ -251,7 +251,7 @@ class Cache(object): def connect(self, name, callback): """ connect to a signal, currently only used for cache_{post,pre}_{changed,open} """ - if not self._callbacks.has_key(name): + if name not in self._callbacks: self._callbacks[name] = [] self._callbacks[name].append(callback) @@ -304,8 +304,8 @@ class FilteredCache(object): def keys(self): return self._filtered.keys() - def has_key(self, key): - return self._filtered.has_key(key) + def __contains__(self, key): + return (key in self._filtered) def _reapplyFilter(self): " internal helper to refilter " @@ -335,7 +335,7 @@ class FilteredCache(object): def __getattr__(self, key): " we try to look exactly like a real cache " #print "getattr: %s " % key - if self.__dict__.has_key(key): + if key in self.__dict__: return self.__dict__[key] else: return getattr(self.cache, key) @@ -356,7 +356,7 @@ if __name__ == "__main__": c = Cache(apt.progress.OpTextProgress()) c.connect("cache_pre_change", cache_pre_changed) c.connect("cache_post_change", cache_post_changed) - print c.has_key("aptitude") + print ("aptitude" in c) p = c["aptitude"] print p.name print len(c) diff --git a/apt/package.py b/apt/package.py index 7f060b04..445b36ad 100644 --- a/apt/package.py +++ b/apt/package.py @@ -66,8 +66,8 @@ class Record(object): raise KeyError return k - def has_key(self, key): - return self._rec.has_key(key) + def __contains__(self, key): + return (key in self._rec) class Package(object): @@ -146,7 +146,7 @@ class Package(object): depends_list = [] depends = ver.DependsList for t in ["PreDepends", "Depends"]: - if not depends.has_key(t): + if t not in depends: continue for depVerList in depends[t]: base_deps = [] @@ -178,9 +178,7 @@ class Package(object): if not self._lookupRecord(): return None sec = apt_pkg.ParseSection(self._records.Record) - if sec.has_key("Architecture"): - return sec["Architecture"] - return None + return sec.get("Architecture", None) architecture = property(architecture) def _downloadable(self, useCandidate=True): diff --git a/aptsources/distinfo.py b/aptsources/distinfo.py index a309a548..74a280ae 100644 --- a/aptsources/distinfo.py +++ b/aptsources/distinfo.py @@ -61,7 +61,7 @@ class Template: def is_mirror(self, url): ''' Check if a given url of a repository is a valid mirror ''' proto, hostname, dir = split_url(url) - if self.mirror_set.has_key(hostname): + if hostname in self.mirror_set: return self.mirror_set[hostname].has_repository(proto, dir) else: return False @@ -224,7 +224,7 @@ class DistInfo: template.match_uri = value elif (field == 'MirrorsFile' or field == 'MirrorsFile-%s' % self.arch): - if not map_mirror_sets.has_key(value): + if value not in map_mirror_sets: mirror_set = {} try: mirror_data = filter(match_mirror_line.match, @@ -237,7 +237,7 @@ class DistInfo: location = match_loc.sub(r"\1", line) continue (proto, hostname, dir) = split_url(line) - if mirror_set.has_key(hostname): + if hostname in mirror_set: mirror_set[hostname].add_repository(proto, dir) else: mirror_set[hostname] = Mirror( diff --git a/aptsources/distro.py b/aptsources/distro.py index 0bf8aba9..350feb65 100644 --- a/aptsources/distro.py +++ b/aptsources/distro.py @@ -187,7 +187,7 @@ class Distribution: if mirror_template: self.nearest_server = mirror_template % country_code - if self.countries.has_key(country_code): + if country_code in self.countries: self.country = self.countries[country_code] self.country_code = country_code @@ -199,7 +199,7 @@ class Distribution: l = server.find(".archive.ubuntu.com") if i != -1 and l != -1: country = server[i+len("://"):l] - if self.countries.has_key(country): + if country in self.countries: # TRANSLATORS: %s is a country return _("Server for %s") % \ gettext.dgettext("iso_3166", @@ -292,7 +292,7 @@ class Distribution: """ # if we don't that distro, just reutnr (can happen for e.g. # dapper-update only in deb-src - if not comps_per_dist.has_key(source.dist): + if source.dist not in comps_per_dist: return # if we have seen this component already for this distro, # return (nothing to do @@ -311,12 +311,12 @@ class Distribution: comps_per_sdist = {} for s in sources: if s.type == self.binary_type: - if not comps_per_dist.has_key(s.dist): + if s.dist not in comps_per_dist: comps_per_dist[s.dist] = set() map(comps_per_dist[s.dist].add, s.comps) for s in self.source_code_sources: if s.type == self.source_type: - if not comps_per_sdist.has_key(s.dist): + if s.dist not in comps_per_sdist: comps_per_sdist[s.dist] = set() map(comps_per_sdist[s.dist].add, s.comps) @@ -412,7 +412,7 @@ class DebianDistribution(Distribution): l = server.find(".debian.org") if i != -1 and l != -1: country = server[i+len("://ftp."):l] - if self.countries.has_key(country): + if country in self.countries: # TRANSLATORS: %s is a country return _("Server for %s") % gettext.dgettext( "iso_3166", self.countries[country].rstrip()).rstrip() diff --git a/aptsources/sourceslist.py b/aptsources/sourceslist.py index be17cd1f..a0346267 100644 --- a/aptsources/sourceslist.py +++ b/aptsources/sourceslist.py @@ -368,7 +368,7 @@ class SourcesList: open(path, "w").write(header) return for source in self.list: - if not files.has_key(source.file): + if source.file not in files: files[source.file] = open(source.file, "w") files[source.file].write(source.str()) for f in files: @@ -386,7 +386,7 @@ class SourcesList: # source entries if source.template.child == True: key = source.template - if not used_child_templates.has_key(key): + if key not in used_child_templates: used_child_templates[key] = [] temp = used_child_templates[key] temp.append(source) diff --git a/doc/examples/all_deps.py b/doc/examples/all_deps.py index 2feeb125..2ed0207f 100644 --- a/doc/examples/all_deps.py +++ b/doc/examples/all_deps.py @@ -10,10 +10,10 @@ def dependencies(cache, pkg, deps, key="Depends"): if candver == None:
return deps
dependslist = candver.DependsList
- if dependslist.has_key(key):
+ if key in dependslist:
for depVerList in dependslist[key]:
for dep in depVerList:
- if cache.has_key(dep.TargetPkg.Name):
+ if TargetPkg.Name in cache:
if pkg.name != dep.TargetPkg.Name and \
not dep.TargetPkg.Name in deps:
deps.add(dep.TargetPkg.Name)
diff --git a/doc/examples/configisc.py b/doc/examples/configisc.py index 1d5965f5..dc3c2f33 100755 --- a/doc/examples/configisc.py +++ b/doc/examples/configisc.py @@ -27,7 +27,7 @@ apt_pkg.ReadConfigFileISC(Cnf, ConfigFile[0]) # print "%s \"%s\";" % (I, Cnf[I]) # bind8 config file.. -if Cnf.has_key("Zone"): +if "Zone" in Cnf: print "Zones: ", Cnf.SubTree("zone").List() for I in Cnf.List("zone"): SubCnf = Cnf.SubTree(I) diff --git a/doc/examples/records.py b/doc/examples/records.py index a7a87727..a0fc8dc4 100755 --- a/doc/examples/records.py +++ b/doc/examples/records.py @@ -7,7 +7,7 @@ cache = apt.Cache() for pkg in cache: if not pkg.candidateRecord: continue - if pkg.candidateRecord.has_key("Task"): + if "Task" in pkg.candidateRecord: print "Pkg %s is part of '%s'" % ( pkg.name, pkg.candidateRecord["Task"].split()) #print pkg.candidateRecord diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py index 3e2f7ac5..9f439899 100644 --- a/tests/test_aptsources.py +++ b/tests/test_aptsources.py @@ -104,7 +104,7 @@ class TestAptSources(unittest.TestCase): "edgy" in entry.dist): for c in entry.comps: if c == comp: - if not found.has_key(entry.dist): + if entry.dist not in found: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) @@ -121,7 +121,7 @@ class TestAptSources(unittest.TestCase): entry.template.name == "edgy"): for c in entry.comps: if c == comp: - if not found.has_key(entry.dist): + if entry.dist not in found: found[entry.dist] = 0 found[entry.dist] += 1 #print "".join([s.str() for s in sources]) diff --git a/utils/get_ubuntu_mirrors_from_lp.py b/utils/get_ubuntu_mirrors_from_lp.py index 59ddd84e..b912f28d 100755 --- a/utils/get_ubuntu_mirrors_from_lp.py +++ b/utils/get_ubuntu_mirrors_from_lp.py @@ -70,7 +70,7 @@ def find(split): country = re.search(r"<strong>(.+?)</strong>", split) if not country: return - if countries.has_key(country.group(1)): + if country.group(1) in countries: lines.append("#LOC:%s" % countries[country.group(1)].upper()) else: lines.append("#LOC:%s" % country.group(1)) |
