Gentoo Archives: gentoo-portage-dev

From: Ali Polatel <hawking@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH 3/6] Replace has_key() with the in operator (portage.dbapi)
Date: Tue, 01 Jul 2008 11:27:28
Message-Id: 1214911614-31263-3-git-send-email-hawking@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 2/6] Replace has_key() with the in operator (portage.cache) by Ali Polatel
1 ---
2 pym/portage/dbapi/__init__.py | 2 +-
3 pym/portage/dbapi/bintree.py | 2 +-
4 pym/portage/dbapi/vartree.py | 16 ++++++++--------
5 pym/portage/dbapi/virtual.py | 8 ++++----
6 4 files changed, 14 insertions(+), 14 deletions(-)
7
8 diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py
9 index ba37c86..510999a 100644
10 --- a/pym/portage/dbapi/__init__.py
11 +++ b/pym/portage/dbapi/__init__.py
12 @@ -167,7 +167,7 @@ class dbapi(object):
13
14 def invalidentry(self, mypath):
15 if mypath.endswith('portage_lockfile'):
16 - if not os.environ.has_key("PORTAGE_MASTER_PID"):
17 + if "PORTAGE_MASTER_PID" not in os.environ:
18 writemsg("Lockfile removed: %s\n" % mypath, 1)
19 unlockfile((mypath, None, None))
20 else:
21 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
22 index f795d98..9e2ea5a 100644
23 --- a/pym/portage/dbapi/bintree.py
24 +++ b/pym/portage/dbapi/bintree.py
25 @@ -693,7 +693,7 @@ class binarytree(object):
26 #writemsg(green(" -- DONE!\n\n"))
27
28 for mypkg in self.remotepkgs.keys():
29 - if not self.remotepkgs[mypkg].has_key("CATEGORY"):
30 + if "CATEGORY" not in self.remotepkgs[mypkg]:
31 #old-style or corrupt package
32 writemsg("!!! Invalid remote binary package: "+mypkg+"\n",
33 noiselevel=-1)
34 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py
35 index 8b4093a..65cb5c3 100644
36 --- a/pym/portage/dbapi/vartree.py
37 +++ b/pym/portage/dbapi/vartree.py
38 @@ -82,7 +82,7 @@ class PreservedLibsRegistry(object):
39 """
40 cp = "/".join(catpkgsplit(cpv)[:2])
41 cps = cp+":"+slot
42 - if len(paths) == 0 and self._data.has_key(cps) \
43 + if len(paths) == 0 and cps in self._data \
44 and self._data[cps][0] == cpv and int(self._data[cps][1]) == int(counter):
45 del self._data[cps]
46 elif len(paths) > 0:
47 @@ -596,7 +596,7 @@ class vardbapi(dbapi):
48 mystat = os.stat(self.getpath(mysplit[0]))[stat.ST_MTIME]
49 except OSError:
50 mystat = 0
51 - if use_cache and self.cpcache.has_key(mycp):
52 + if use_cache and mycp in self.cpcache:
53 cpc = self.cpcache[mycp]
54 if cpc[0] == mystat:
55 return cpc[1][:]
56 @@ -624,7 +624,7 @@ class vardbapi(dbapi):
57 self._cpv_sort_ascending(returnme)
58 if use_cache:
59 self.cpcache[mycp] = [mystat, returnme[:]]
60 - elif self.cpcache.has_key(mycp):
61 + elif mycp in self.cpcache:
62 del self.cpcache[mycp]
63 return returnme
64
65 @@ -720,7 +720,7 @@ class vardbapi(dbapi):
66 mykey = dep_getkey(mydep)
67 mycat = catsplit(mykey)[0]
68 if not use_cache:
69 - if self.matchcache.has_key(mycat):
70 + if mycat in self.matchcache:
71 del self.mtdircache[mycat]
72 del self.matchcache[mycat]
73 return list(self._iter_match(mydep,
74 @@ -730,11 +730,11 @@ class vardbapi(dbapi):
75 except (IOError, OSError):
76 curmtime=0
77
78 - if not self.matchcache.has_key(mycat) or not self.mtdircache[mycat]==curmtime:
79 + if mycat not in self.matchcache or not self.mtdircache[mycat]==curmtime:
80 # clear cache entry
81 self.mtdircache[mycat] = curmtime
82 self.matchcache[mycat] = {}
83 - if not self.matchcache[mycat].has_key(mydep):
84 + if mydep not in self.matchcache[mycat]:
85 mymatch = list(self._iter_match(mydep,
86 self.cp_list(mydep.cp, use_cache=use_cache)))
87 self.matchcache[mycat][mydep] = mymatch
88 @@ -1266,7 +1266,7 @@ class vartree(object):
89 myprovides = {}
90 for node in self.getallcpv():
91 for mykey in self.get_provide(node):
92 - if myprovides.has_key(mykey):
93 + if mykey in myprovides:
94 myprovides[mykey] += [node]
95 else:
96 myprovides[mykey] = [node]
97 @@ -2687,7 +2687,7 @@ class dblink(object):
98 #if we have a file containing previously-merged config file md5sums, grab it.
99 conf_mem_file = os.path.join(destroot, CONFIG_MEMORY_FILE)
100 cfgfiledict = grabdict(conf_mem_file)
101 - if self.settings.has_key("NOCONFMEM"):
102 + if "NOCONFMEM" in self.settings:
103 cfgfiledict["IGNORE"]=1
104 else:
105 cfgfiledict["IGNORE"]=0
106 diff --git a/pym/portage/dbapi/virtual.py b/pym/portage/dbapi/virtual.py
107 index 444b536..bf90f30 100644
108 --- a/pym/portage/dbapi/virtual.py
109 +++ b/pym/portage/dbapi/virtual.py
110 @@ -40,7 +40,7 @@ class fakedbapi(dbapi):
111 return result[:]
112
113 def cpv_exists(self, mycpv):
114 - return self.cpvdict.has_key(mycpv)
115 + return mycpv in self.cpvdict
116
117 def cp_list(self, mycp, use_cache=1):
118 cachelist = self._match_cache.get(mycp)
119 @@ -94,9 +94,9 @@ class fakedbapi(dbapi):
120 """Removes a cpv from the list of available packages."""
121 self._clear_cache()
122 mycp = cpv_getkey(mycpv)
123 - if self.cpvdict.has_key(mycpv):
124 + if mycpv in self.cpvdict:
125 del self.cpvdict[mycpv]
126 - if not self.cpdict.has_key(mycp):
127 + if mycp not in self.cpdict:
128 return
129 while mycpv in self.cpdict[mycp]:
130 del self.cpdict[mycp][self.cpdict[mycp].index(mycpv)]
131 @@ -129,4 +129,4 @@ class testdbapi(object):
132 fake_api = dir(dbapi)
133 for call in fake_api:
134 if not hasattr(self, call):
135 - setattr(self, call, f)
136 \ No newline at end of file
137 + setattr(self, call, f)
138 --
139 1.5.6.1
140
141 --
142 gentoo-portage-dev@l.g.o mailing list

Replies