Skip to content

Commit

Permalink
python: futurize -f lib2to3.fixes.fix_has_key
Browse files Browse the repository at this point in the history
Change "dict.has_key(key)" to "key in dict"

This is necessary for Python 3 compatibility.

Done using:

  $ py=$( (g grep -l -E '^#!.*python';find -name '*.py' -printf '%P\n';) | \
    sort -u | grep -v README.sh4)
  $ futurize -w -f lib2to3.fixes.fix_has_key $py

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20180608122952.2009-5-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
  • Loading branch information
ehabkost committed Jun 8, 2018
1 parent d24d523 commit d7a4228
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions scripts/qmp/qmp
Expand Up @@ -36,7 +36,7 @@ def main(args):
path = None

# Use QMP_PATH if it's set
if os.environ.has_key('QMP_PATH'):
if 'QMP_PATH' in os.environ:
path = os.environ['QMP_PATH']

while len(args):
Expand Down Expand Up @@ -80,7 +80,7 @@ def main(args):

def do_command(srv, cmd, **kwds):
rsp = srv.cmd(cmd, kwds)
if rsp.has_key('error'):
if 'error' in rsp:
raise Exception(rsp['error']['desc'])
return rsp['return']

Expand Down
2 changes: 1 addition & 1 deletion scripts/qmp/qmp-shell
Expand Up @@ -134,7 +134,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):

def _fill_completion(self):
cmds = self.cmd('query-commands')
if cmds.has_key('error'):
if 'error' in cmds:
return
for cmd in cmds['return']:
self._completer.append(cmd['name'])
Expand Down
2 changes: 1 addition & 1 deletion scripts/qmp/qom-fuse
Expand Up @@ -29,7 +29,7 @@ class QOMFS(Fuse):
self.ino_count = 1

def get_ino(self, path):
if self.ino_map.has_key(path):
if path in self.ino_map:
return self.ino_map[path]
self.ino_map[path] = self.ino_count
self.ino_count += 1
Expand Down
2 changes: 1 addition & 1 deletion scripts/qmp/qom-get
Expand Up @@ -45,7 +45,7 @@ if len(args) > 0:
args = args[2:]

if not socket_path:
if os.environ.has_key('QMP_SOCKET'):
if 'QMP_SOCKET' in os.environ:
socket_path = os.environ['QMP_SOCKET']
else:
usage_error("no QMP socket path or address given");
Expand Down
2 changes: 1 addition & 1 deletion scripts/qmp/qom-list
Expand Up @@ -45,7 +45,7 @@ if len(args) > 0:
args = args[2:]

if not socket_path:
if os.environ.has_key('QMP_SOCKET'):
if 'QMP_SOCKET' in os.environ:
socket_path = os.environ['QMP_SOCKET']
else:
usage_error("no QMP socket path or address given");
Expand Down
2 changes: 1 addition & 1 deletion scripts/qmp/qom-set
Expand Up @@ -46,7 +46,7 @@ if len(args) > 0:
args = args[2:]

if not socket_path:
if os.environ.has_key('QMP_SOCKET'):
if 'QMP_SOCKET' in os.environ:
socket_path = os.environ['QMP_SOCKET']
else:
usage_error("no QMP socket path or address given");
Expand Down
2 changes: 1 addition & 1 deletion scripts/qmp/qom-tree
Expand Up @@ -47,7 +47,7 @@ if len(args) > 0:
args = args[2:]

if not socket_path:
if os.environ.has_key('QMP_SOCKET'):
if 'QMP_SOCKET' in os.environ:
socket_path = os.environ['QMP_SOCKET']
else:
usage_error("no QMP socket path or address given");
Expand Down
2 changes: 1 addition & 1 deletion tests/qemu-iotests/093
Expand Up @@ -237,7 +237,7 @@ class ThrottleTestGroupNames(iotests.QMPTestCase):
if name:
self.assertEqual(info["group"], name)
else:
self.assertFalse(info.has_key('group'))
self.assertFalse('group' in info)
return

raise Exception("No group information found for '%s'" % device)
Expand Down
4 changes: 2 additions & 2 deletions tests/qemu-iotests/096
Expand Up @@ -53,9 +53,9 @@ class TestLiveSnapshot(iotests.QMPTestCase):
self.assertEqual(r['iops'], self.iops)
self.assertEqual(r['iops_size'], self.iops_size)
else:
self.assertFalse(r.has_key('group'))
self.assertFalse('group' in r)
self.assertEqual(r['iops'], 0)
self.assertFalse(r.has_key('iops_size'))
self.assertFalse('iops_size' in r)

def testSnapshot(self):
self.checkConfig('base')
Expand Down
2 changes: 1 addition & 1 deletion tests/qemu-iotests/136
Expand Up @@ -203,7 +203,7 @@ sector = "%d"
if (self.accounted_ops(read = True, write = True, flush = True) != 0):
self.assertLess(0, stats['idle_time_ns'])
else:
self.assertFalse(stats.has_key('idle_time_ns'))
self.assertFalse('idle_time_ns' in stats)

# This test does not alter these, so they must be all 0
self.assertEqual(0, stats['rd_merged'])
Expand Down

0 comments on commit d7a4228

Please sign in to comment.