Prefer i in d over d.has_key(i)
authorChristian Ebert <blacktrash@gmx.net>
Sun, 20 Jan 2008 14:39:25 +0100
changeset 5915 d0576d065993
parent 5914 8e7796a990c5
child 5921 549a7ebe1607
Prefer i in d over d.has_key(i)
contrib/churn.py
hgext/keyword.py
hgext/patchbomb.py
mercurial/cmdutil.py
mercurial/dirstate.py
mercurial/filelog.py
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/hgwebdir_mod.py
mercurial/hgweb/protocol.py
mercurial/hgweb/webcommands.py
mercurial/httprepo.py
mercurial/keepalive.py
mercurial/localrepo.py
mercurial/templater.py
tests/coverage.py
--- a/contrib/churn.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/contrib/churn.py	Sun Jan 20 14:39:25 2008 +0100
@@ -114,11 +114,11 @@
         who, lines = __gather(ui, repo, node1, node2)
 
         # remap the owner if possible
-        if amap.has_key(who):
+        if who in amap:
             ui.note("using '%s' alias for '%s'\n" % (amap[who], who))
             who = amap[who]
 
-        if not stats.has_key(who):
+        if not who in stats:
             stats[who] = 0
         stats[who] += lines
 
--- a/hgext/keyword.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/hgext/keyword.py	Sun Jan 20 14:39:25 2008 +0100
@@ -243,7 +243,7 @@
     mf = ctx.manifest()
     if node is not None:   # commit
         _kwtemplater.commitnode = node
-        files = [f for f in ctx.files() if mf.has_key(f)]
+        files = [f for f in ctx.files() if f in mf]
         notify = ui.debug
     else:                  # kwexpand/kwshrink
         notify = ui.note
--- a/hgext/patchbomb.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/hgext/patchbomb.py	Sun Jan 20 14:39:25 2008 +0100
@@ -418,8 +418,7 @@
                 fp.close()
         elif opts.get('mbox'):
             ui.status('Writing ', m['Subject'], ' ...\n')
-            fp = open(opts.get('mbox'),
-                      m.has_key('In-Reply-To') and 'ab+' or 'wb+')
+            fp = open(opts.get('mbox'), 'In-Reply-To' in m and 'ab+' or 'wb+')
             date = util.datestr(date=start_time,
                                 format='%a %b %d %H:%M:%S %Y', timezone=False)
             fp.write('From %s %s\n' % (sender_addr, date))
--- a/mercurial/cmdutil.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/cmdutil.py	Sun Jan 20 14:39:25 2008 +0100
@@ -50,7 +50,7 @@
     """Return (aliases, command table entry) for command string."""
     choice = findpossible(ui, cmd, table)
 
-    if choice.has_key(cmd):
+    if cmd in choice:
         return choice[cmd]
 
     if len(choice) > 1:
--- a/mercurial/dirstate.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/dirstate.py	Sun Jan 20 14:39:25 2008 +0100
@@ -235,7 +235,7 @@
         self._changepath(f, 'n', True)
         s = os.lstat(self._join(f))
         self._map[f] = ('n', s.st_mode, s.st_size, s.st_mtime, 0)
-        if self._copymap.has_key(f):
+        if f in self._copymap:
             del self._copymap[f]
 
     def normallookup(self, f):
--- a/mercurial/filelog.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/filelog.py	Sun Jan 20 14:39:25 2008 +0100
@@ -58,7 +58,7 @@
         if self.parents(node)[0] != nullid:
             return False
         m = self._readmeta(node)
-        if m and m.has_key("copy"):
+        if m and "copy" in m:
             return (m["copy"], bin(m["copyrev"]))
         return False
 
--- a/mercurial/hgweb/hgweb_mod.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/hgweb/hgweb_mod.py	Sun Jan 20 14:39:25 2008 +0100
@@ -153,7 +153,7 @@
         req.url = req.env['SCRIPT_NAME']
         if not req.url.endswith('/'):
             req.url += '/'
-        if req.env.has_key('REPO_NAME'):
+        if 'REPO_NAME' in req.env:
             req.url += req.env['REPO_NAME'] + '/'
 
         if req.env.get('PATH_INFO'):
@@ -267,7 +267,7 @@
 
         def sessionvars(**map):
             fields = []
-            if req.form.has_key('style'):
+            if 'style' in req.form:
                 style = req.form['style'][0]
                 if style != self.config('web', 'style', ''):
                     fields.append(('style', style))
@@ -280,7 +280,7 @@
         # figure out which style to use
 
         style = self.config("web", "style", "")
-        if req.form.has_key('style'):
+        if 'style' in req.form:
             style = req.form['style'][0]
         mapfile = style_map(self.templatepath, style)
 
@@ -863,9 +863,9 @@
         return util.canonpath(self.repo.root, '', path)
 
     def changectx(self, req):
-        if req.form.has_key('node'):
+        if 'node' in req.form:
             changeid = req.form['node'][0]
-        elif req.form.has_key('manifest'):
+        elif 'manifest' in req.form:
             changeid = req.form['manifest'][0]
         else:
             changeid = self.repo.changelog.count() - 1
@@ -881,7 +881,7 @@
 
     def filectx(self, req):
         path = self.cleanpath(req.form['file'][0])
-        if req.form.has_key('node'):
+        if 'node' in req.form:
             changeid = req.form['node'][0]
         else:
             changeid = req.form['filenode'][0]
--- a/mercurial/hgweb/hgwebdir_mod.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/hgweb/hgwebdir_mod.py	Sun Jan 20 14:39:25 2008 +0100
@@ -143,7 +143,7 @@
         def entries(sortcolumn="", descending=False, subdir="", **map):
             def sessionvars(**map):
                 fields = []
-                if req.form.has_key('style'):
+                if 'style' in req.form:
                     style = req.form['style'][0]
                     if style != get('web', 'style', ''):
                         fields.append(('style', style))
@@ -214,7 +214,7 @@
 
         sortable = ["name", "description", "contact", "lastchange"]
         sortcolumn, descending = self.repos_sorted
-        if req.form.has_key('sort'):
+        if 'sort' in req.form:
             sortcolumn = req.form['sort'][0]
             descending = sortcolumn.startswith('-')
             if descending:
@@ -262,7 +262,7 @@
         style = self.style
         if style is None:
             style = config('web', 'style', '')
-        if req.form.has_key('style'):
+        if 'style' in req.form:
             style = req.form['style'][0]
         if self.stripecount is None:
             self.stripecount = int(config('web', 'stripes', 1))
--- a/mercurial/hgweb/protocol.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/hgweb/protocol.py	Sun Jan 20 14:39:25 2008 +0100
@@ -28,7 +28,7 @@
 
 def branches(web, req):
     nodes = []
-    if req.form.has_key('nodes'):
+    if 'nodes' in req.form:
         nodes = map(bin, req.form['nodes'][0].split(" "))
     resp = cStringIO.StringIO()
     for b in web.repo.branches(nodes):
@@ -38,7 +38,7 @@
     req.write(resp)
 
 def between(web, req):
-    if req.form.has_key('pairs'):
+    if 'pairs' in req.form:
         pairs = [map(bin, p.split("-"))
                  for p in req.form['pairs'][0].split(" ")]
     resp = cStringIO.StringIO()
@@ -54,7 +54,7 @@
     if not web.allowpull:
         return
 
-    if req.form.has_key('roots'):
+    if 'roots' in req.form:
         nodes = map(bin, req.form['roots'][0].split(" "))
 
     z = zlib.compressobj()
@@ -74,9 +74,9 @@
     if not web.allowpull:
         return
 
-    if req.form.has_key('bases'):
+    if 'bases' in req.form:
         bases = [bin(x) for x in req.form['bases'][0].split(' ')]
-    if req.form.has_key('heads'):
+    if 'heads' in req.form:
         heads = [bin(x) for x in req.form['heads'][0].split(' ')]
 
     z = zlib.compressobj()
--- a/mercurial/hgweb/webcommands.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/hgweb/webcommands.py	Sun Jan 20 14:39:25 2008 +0100
@@ -10,7 +10,7 @@
 from common import staticfile
 
 def log(web, req, tmpl):
-    if req.form.has_key('file') and req.form['file'][0]:
+    if 'file' in req.form and req.form['file'][0]:
         filelog(web, req, tmpl)
     else:
         changelog(web, req, tmpl)
@@ -48,10 +48,10 @@
     req.write(web.manifest(tmpl, web.changectx(req), path))
 
 def changelog(web, req, tmpl, shortlog = False):
-    if req.form.has_key('node'):
+    if 'node' in req.form:
         ctx = web.changectx(req)
     else:
-        if req.form.has_key('rev'):
+        if 'rev' in req.form:
             hi = req.form['rev'][0]
         else:
             hi = web.repo.changelog.count() - 1
--- a/mercurial/httprepo.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/httprepo.py	Sun Jan 20 14:39:25 2008 +0100
@@ -247,7 +247,7 @@
         # will take precedence if found, so drop them
         for env in ["HTTP_PROXY", "http_proxy", "no_proxy"]:
             try:
-                if os.environ.has_key(env):
+                if env in os.environ:
                     del os.environ[env]
             except OSError:
                 pass
--- a/mercurial/keepalive.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/keepalive.py	Sun Jan 20 14:39:25 2008 +0100
@@ -129,7 +129,7 @@
     def add(self, host, connection, ready):
         self._lock.acquire()
         try:
-            if not self._hostmap.has_key(host): self._hostmap[host] = []
+            if not host in self._hostmap: self._hostmap[host] = []
             self._hostmap[host].append(connection)
             self._connmap[connection] = host
             self._readymap[connection] = ready
@@ -159,7 +159,7 @@
         conn = None
         self._lock.acquire()
         try:
-            if self._hostmap.has_key(host):
+            if host in self._hostmap:
                 for c in self._hostmap[host]:
                     if self._readymap[c]:
                         self._readymap[c] = 0
--- a/mercurial/localrepo.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/localrepo.py	Sun Jan 20 14:39:25 2008 +0100
@@ -998,7 +998,7 @@
             mf2keys.sort()
             getnode = lambda fn: mf1.get(fn, nullid)
             for fn in mf2keys:
-                if mf1.has_key(fn):
+                if fn in mf1:
                     if (mf1.flags(fn) != mf2.flags(fn) or
                         (mf1[fn] != mf2[fn] and
                          (mf2[fn] != "" or fcmp(fn, getnode)))):
@@ -1779,7 +1779,7 @@
                     raise util.Abort(_("empty or missing revlog for %s") % fname)
                 # Toss out the filenodes that the recipient isn't really
                 # missing.
-                if msng_filenode_set.has_key(fname):
+                if fname in msng_filenode_set:
                     prune_filenodes(fname, filerevlog)
                     msng_filenode_lst = msng_filenode_set[fname].keys()
                 else:
@@ -1798,7 +1798,7 @@
                                              lookup_filenode_link_func(fname))
                     for chnk in group:
                         yield chnk
-                if msng_filenode_set.has_key(fname):
+                if fname in msng_filenode_set:
                     # Don't need this anymore, toss it to free memory.
                     del msng_filenode_set[fname]
             # Signal that no more groups are left.
--- a/mercurial/templater.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/mercurial/templater.py	Sun Jan 20 14:39:25 2008 +0100
@@ -82,7 +82,7 @@
         '''perform expansion.
         t is name of map element to expand.
         map is added elements to use during expansion.'''
-        if not self.cache.has_key(t):
+        if not t in self.cache:
             try:
                 self.cache[t] = file(self.map[t]).read()
             except IOError, inst:
--- a/tests/coverage.py	Mon Jan 21 13:37:27 2008 -0200
+++ b/tests/coverage.py	Sun Jan 20 14:39:25 2008 +0100
@@ -186,9 +186,9 @@
                 return 0
             # If this line is excluded, or suite_spots maps this line to
             # another line that is exlcuded, then we're excluded.
-            elif self.excluded.has_key(lineno) or \
-                 self.suite_spots.has_key(lineno) and \
-                 self.excluded.has_key(self.suite_spots[lineno][1]):
+            elif lineno in self.excluded or \
+                 lineno in self.suite_spots and \
+                 self.suite_spots[lineno][1] in self.excluded:
                 return 0
             # Otherwise, this is an executable line.
             else:
@@ -217,8 +217,8 @@
         lastprev = self.getLastLine(prevsuite)
         firstelse = self.getFirstLine(suite)
         for l in range(lastprev+1, firstelse):
-            if self.suite_spots.has_key(l):
-                self.doSuite(None, suite, exclude=self.excluded.has_key(l))
+            if l in self.suite_spots:
+                self.doSuite(None, suite, l in exclude=self.excluded)
                 break
         else:
             self.doSuite(None, suite)
@@ -353,9 +353,9 @@
         long_opts = optmap.values()
         options, args = getopt.getopt(argv, short_opts, long_opts)
         for o, a in options:
-            if optmap.has_key(o):
+            if o in optmap:
                 settings[optmap[o]] = 1
-            elif optmap.has_key(o + ':'):
+            elif o + ':' in optmap:
                 settings[optmap[o + ':']] = a
             elif o[2:] in long_opts:
                 settings[o[2:]] = 1
@@ -512,14 +512,14 @@
 
     def merge_data(self, new_data):
         for file_name, file_data in new_data.items():
-            if self.cexecuted.has_key(file_name):
+            if file_name in self.cexecuted:
                 self.merge_file_data(self.cexecuted[file_name], file_data)
             else:
                 self.cexecuted[file_name] = file_data
 
     def merge_file_data(self, cache_data, new_data):
         for line_number in new_data.keys():
-            if not cache_data.has_key(line_number):
+            if not line_number in cache_data:
                 cache_data[line_number] = new_data[line_number]
 
     # canonical_filename(filename).  Return a canonical filename for the
@@ -527,7 +527,7 @@
     # normalized case).  See [GDR 2001-12-04b, 3.3].
 
     def canonical_filename(self, filename):
-        if not self.canonical_filename_cache.has_key(filename):
+        if not filename in self.canonical_filename_cache:
             f = filename
             if os.path.isabs(f) and not os.path.exists(f):
                 f = os.path.basename(f)
@@ -550,7 +550,7 @@
                 # Can't do anything useful with exec'd strings, so skip them.
                 continue
             f = self.canonical_filename(filename)
-            if not self.cexecuted.has_key(f):
+            if not f in self.cexecuted:
                 self.cexecuted[f] = {}
             self.cexecuted[f][lineno] = 1
         self.c = {}
@@ -575,7 +575,7 @@
     # statements that cross lines.
 
     def analyze_morf(self, morf):
-        if self.analysis_cache.has_key(morf):
+        if morf in self.analysis_cache:
             return self.analysis_cache[morf]
         filename = self.morf_filename(morf)
         ext = os.path.splitext(filename)[1]
@@ -752,13 +752,13 @@
     def analysis2(self, morf):
         filename, statements, excluded, line_map = self.analyze_morf(morf)
         self.canonicalize_filenames()
-        if not self.cexecuted.has_key(filename):
+        if not filename in self.cexecuted:
             self.cexecuted[filename] = {}
         missing = []
         for line in statements:
             lines = line_map.get(line, [line, line])
             for l in range(lines[0], lines[1]+1):
-                if self.cexecuted[filename].has_key(l):
+                if l in self.cexecuted[filename]:
                     break
             else:
                 missing.append(line)