2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-21 14:49:41 +00:00

python: Stop using xrange().

Python 2 had range() and xrange().  xrange() is more efficient, but
behaves differently so range() was retained for compatibility.  Python 3
only has range() and it behaves like Python 2's xrange().

Remove explicit use of xrange() and use six.moves.range() to
make sure we're using xrange() from Python 2 or range() from Python 3.

Signed-off-by: Russell Bryant <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
Russell Bryant
2015-12-14 14:33:52 -05:00
parent 73eb682edb
commit b3ac29477d
9 changed files with 16 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ import ovs.db.idl
import ovs.unixctl
import ovs.unixctl.server
import ovs.vlog
from six.moves import range
vlog = ovs.vlog.Vlog("ovs-monitor-ipsec")
root_prefix = '' # Prefix for absolute file names, for testing.

View File

@@ -16,6 +16,8 @@ import re
import StringIO
import sys
from six.moves import range
__pychecker__ = 'no-stringiter'
escapes = {ord('"'): u"\\\"",

View File

@@ -15,6 +15,8 @@
import re
import uuid
from six.moves import range
from ovs.db import error
import ovs.db.parser

View File

@@ -19,6 +19,8 @@ import random
import socket
import sys
from six.moves import range
import ovs.fatal_signal
import ovs.poller
import ovs.vlog
@@ -32,7 +34,7 @@ def make_short_name(long_name):
long_name = os.path.abspath(long_name)
long_dirname = os.path.dirname(long_name)
tmpdir = os.getenv('TMPDIR', '/tmp')
for x in xrange(0, 1000):
for x in range(0, 1000):
link_name = \
'%s/ovs-un-py-%d-%d' % (tmpdir, random.randint(0, 10000), x)
try:

View File

@@ -17,6 +17,8 @@ import errno
import os
import types
from six.moves import range
import ovs.dirs
import ovs.jsonrpc
import ovs.stream

View File

@@ -22,6 +22,8 @@ import socket
import sys
import threading
from six.moves import range
import ovs.dirs
import ovs.unixctl
import ovs.util

View File

@@ -26,6 +26,7 @@ import signal
import subprocess
import re
from six.moves import range
import six.moves.xmlrpc_client

View File

@@ -15,10 +15,11 @@
import argparse
import ovs.vlog
from six.moves import range
def main():
modules = [ovs.vlog.Vlog("module_%d" % i) for i in xrange(3)]
modules = [ovs.vlog.Vlog("module_%d" % i) for i in range(3)]
parser = argparse.ArgumentParser(description="Vlog Module Tester")
ovs.vlog.add_args(parser)

View File

@@ -29,6 +29,7 @@ import ovs.util
import ovs.daemon
import ovs.unixctl.server
import ovs.vlog
from six.moves import range
VERSION = "0.99"