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 2019/08/24 07:47:30 UTC

[qpid-proton] branch master updated: PROTON-2091: fix `len(queue)` in python/examples and reformat for PEP8

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 858aabf  PROTON-2091: fix `len(queue)` in python/examples and reformat for PEP8
858aabf is described below

commit 858aabfcc4716c878c29bc8a4ffbcb476dfe2d3a
Author: Jiri Danek <jd...@redhat.com>
AuthorDate: Fri Aug 23 23:29:02 2019 +0200

    PROTON-2091: fix `len(queue)` in python/examples and reformat for PEP8
---
 python/examples/broker.py | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/python/examples/broker.py b/python/examples/broker.py
index 67eb216..b47c636 100755
--- a/python/examples/broker.py
+++ b/python/examples/broker.py
@@ -18,11 +18,17 @@
 # under the License.
 #
 
-import collections, optparse, uuid
+import collections
+import optparse
+import uuid
+
+import unittest
+
 from proton import Endpoint
 from proton.handlers import MessagingHandler
 from proton.reactor import Container
 
+
 class Queue(object):
     def __init__(self, dynamic=False):
         self.dynamic = dynamic
@@ -33,9 +39,12 @@ class Queue(object):
         self.consumers.append(consumer)
 
     def unsubscribe(self, consumer):
+        """
+        :return: True if the queue is to be deleted
+        """
         if consumer in self.consumers:
             self.consumers.remove(consumer)
-        return len(self.consumers) == 0 and (self.dynamic or self.queue.count == 0)
+        return len(self.consumers) == 0 and (self.dynamic or len(self.queue) == 0)
 
     def publish(self, message):
         self.queue.append(message)
@@ -46,7 +55,8 @@ class Queue(object):
             c = [consumer]
         else:
             c = self.consumers
-        while self._deliver_to(c): pass
+        while self._deliver_to(c):
+            pass
 
     def _deliver_to(self, consumers):
         try:
@@ -56,9 +66,10 @@ class Queue(object):
                     c.send(self.queue.popleft())
                     result = True
             return result
-        except IndexError: # no more messages
+        except IndexError:  # no more messages
             return False
 
+
 class Broker(MessagingHandler):
     def __init__(self, url):
         super(Broker, self).__init__()
@@ -117,11 +128,18 @@ class Broker(MessagingHandler):
             address = event.message.address
         self._queue(address).publish(event.message)
 
-parser = optparse.OptionParser(usage="usage: %prog [options]")
-parser.add_option("-a", "--address", default="localhost:5672",
-                  help="address router listens on (default %default)")
-opts, args = parser.parse_args()
 
-try:
-    Container(Broker(opts.address)).run()
-except KeyboardInterrupt: pass
+def main():
+    parser = optparse.OptionParser(usage="usage: %prog [options]")
+    parser.add_option("-a", "--address", default="localhost:5672",
+                      help="address router listens on (default %default)")
+    opts, args = parser.parse_args()
+
+    try:
+        Container(Broker(opts.address)).run()
+    except KeyboardInterrupt:
+        pass
+
+
+if __name__ == '__main__':
+    main()


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