You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by jd...@apache.org on 2023/04/10 20:35:44 UTC

[qpid-python] branch main updated: QPID-8631: remove use of `iteritems` and `xrange` (#12)

This is an automated email from the ASF dual-hosted git repository.

jdanek pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-python.git


The following commit(s) were added to refs/heads/main by this push:
     new f22f5ad  QPID-8631: remove use of `iteritems` and `xrange` (#12)
f22f5ad is described below

commit f22f5adb21a0b65f88512399845ffb0e42c688bd
Author: Jiri Daněk <jd...@redhat.com>
AuthorDate: Mon Apr 10 22:35:37 2023 +0200

    QPID-8631: remove use of `iteritems` and `xrange` (#12)
    
    These are somewhat helpful in Python 2, but they are not available in Python 3.
---
 qpid/client.py                    | 2 +-
 qpid/connection.py                | 2 +-
 qpid/datatypes.py                 | 2 +-
 qpid/messaging/driver.py          | 2 +-
 qpid/messaging/endpoints.py       | 2 +-
 qpid/peer.py                      | 2 +-
 qpid/tests/codec.py               | 2 +-
 qpid/tests/datatypes.py           | 2 +-
 qpid/tests/messaging/endpoints.py | 4 ++--
 qpid_tests/broker_0_10/lvq.py     | 2 +-
 qpid_tests/broker_0_9/queue.py    | 2 +-
 11 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/qpid/client.py b/qpid/client.py
index 39b7c58..b147062 100644
--- a/qpid/client.py
+++ b/qpid/client.py
@@ -121,7 +121,7 @@ class Client:
     self.lock.acquire()
     try:
       id = None
-      for i in xrange(1, 64*1024):
+      for i in range(1, 64*1024):
         if not self.sessions.has_key(i):
           id = i
           break
diff --git a/qpid/connection.py b/qpid/connection.py
index 4bc9d9d..8d5f037 100644
--- a/qpid/connection.py
+++ b/qpid/connection.py
@@ -111,7 +111,7 @@ class Connection(Framer):
       self.lock.release()
 
   def __channel(self):
-    for i in xrange(1, self.channel_max):
+    for i in range(1, self.channel_max):
       if not self.attached.has_key(i):
         return i
     else:
diff --git a/qpid/datatypes.py b/qpid/datatypes.py
index 985fc3a..06528a5 100644
--- a/qpid/datatypes.py
+++ b/qpid/datatypes.py
@@ -319,7 +319,7 @@ except ImportError:
   rand = random.Random()
   rand.seed((os.getpid(), time.time(), socket.gethostname()))
   def random_uuid():
-    bytes = [rand.randint(0, 255) for i in xrange(16)]
+    bytes = [rand.randint(0, 255) for i in range(16)]
 
     # From RFC4122, the version bits are set to 0100
     bytes[7] &= 0x0F
diff --git a/qpid/messaging/driver.py b/qpid/messaging/driver.py
index 7f72e0d..2ca20b3 100644
--- a/qpid/messaging/driver.py
+++ b/qpid/messaging/driver.py
@@ -894,7 +894,7 @@ class Engine:
     if ssn.closed: return
     sst = self._attachments.get(ssn)
     if sst is None:
-      for i in xrange(0, self.channel_max):
+      for i in range(0, self.channel_max):
         if not self._sessions.has_key(i):
           ch = i
           break
diff --git a/qpid/messaging/endpoints.py b/qpid/messaging/endpoints.py
index a03749d..d2a19d9 100644
--- a/qpid/messaging/endpoints.py
+++ b/qpid/messaging/endpoints.py
@@ -180,7 +180,7 @@ class Connection(Endpoint):
     for key in opt_keys:
         setattr(self, key, None)
     # Get values from options, check for invalid options
-    for (key, value) in options.iteritems():
+    for (key, value) in options.items():
         if key in opt_keys:
             setattr(self, key, value)
         else:
diff --git a/qpid/peer.py b/qpid/peer.py
index 545d8aa..fddddfd 100644
--- a/qpid/peer.py
+++ b/qpid/peer.py
@@ -271,7 +271,7 @@ class Channel:
         # if other type
         raise ContentError("Content body must be string or buffer, not a %s" % type(content.body))
       frame_max = self.client.tune_params['frame_max'] - self.client.conn.AMQP_HEADER_SIZE
-      for chunk in (content.body[i:i + frame_max] for i in xrange(0, len(content.body), frame_max)):
+      for chunk in (content.body[i:i + frame_max] for i in range(0, len(content.body), frame_max)):
         self.write(Body(chunk))
 
   def receive(self, frame, work):
diff --git a/qpid/tests/codec.py b/qpid/tests/codec.py
index 162b076..1c68cfe 100644
--- a/qpid/tests/codec.py
+++ b/qpid/tests/codec.py
@@ -637,7 +637,7 @@ def test(type, value):
     enc = stream.getvalue()
     stream.reset()
     dup = []
-    for i in xrange(len(values)):
+    for i in range(len(values)):
       dup.append(codec.decode(type))
     if values != dup:
       raise AssertionError("%r --> %r --> %r" % (values, enc, dup))
diff --git a/qpid/tests/datatypes.py b/qpid/tests/datatypes.py
index 214e580..e28a380 100644
--- a/qpid/tests/datatypes.py
+++ b/qpid/tests/datatypes.py
@@ -210,7 +210,7 @@ class UUIDTest(TestCase):
     # this test is kind of lame, but it does excercise the basic
     # functionality of the class
     u = uuid4()
-    for i in xrange(1024):
+    for i in range(1024):
       assert u != uuid4()
 
 class MessageTest(TestCase):
diff --git a/qpid/tests/messaging/endpoints.py b/qpid/tests/messaging/endpoints.py
index 3c7df7c..64b0a08 100644
--- a/qpid/tests/messaging/endpoints.py
+++ b/qpid/tests/messaging/endpoints.py
@@ -82,7 +82,7 @@ class SetupTests(Base):
     try:
       for i in range(32):
         if fds: os.close(fds.pop())
-      for i in xrange(64):
+      for i in range(64):
         conn = Connection.establish(self.broker, **self.connection_options())
         conn.close()
     finally:
@@ -94,7 +94,7 @@ class SetupTests(Base):
     try:
       for i in range(32):
         if fds: os.close(fds.pop())
-      for i in xrange(64):
+      for i in range(64):
         conn = Connection("localhost:0", **self.connection_options())
         # XXX: we need to force a waiter to be created for this test
         # to work
diff --git a/qpid_tests/broker_0_10/lvq.py b/qpid_tests/broker_0_10/lvq.py
index 40b9835..f5edc90 100644
--- a/qpid_tests/broker_0_10/lvq.py
+++ b/qpid_tests/broker_0_10/lvq.py
@@ -73,7 +73,7 @@ class LVQTests (Base):
             counters[k] += 1
             messages.append(create_message(k, "%s-%i" % (k, counters[k])))
         # make sure we have sent at least one message for every key
-        for k, v in counters.iteritems():
+        for k, v in counters.items():
             if v == 0:
                 counters[k] += 1
                 messages.append(create_message(k, "%s-%i" % (k, counters[k])))
diff --git a/qpid_tests/broker_0_9/queue.py b/qpid_tests/broker_0_9/queue.py
index 8d6ae1c..6ce8323 100644
--- a/qpid_tests/broker_0_9/queue.py
+++ b/qpid_tests/broker_0_9/queue.py
@@ -121,7 +121,7 @@ class QueueTests(TestBase):
         channel.queue_declare(queue=queue_name, arguments={"x-qpid-capacity" : 25, "x-qpid-flow-resume-capacity" : 15})
 
         try:
-            for i in xrange(100):
+            for i in range(100):
                 channel.basic_publish(exchange="", routing_key=queue_name,
                                       content=Content("This is a message with more than 25 bytes. This should trigger flow control."))
                 time.sleep(.1)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org