Author: rhs
Date: Fri Jan 18 09:32:55 2008
New Revision: 613211

URL: http://svn.apache.org/viewvc?rev=613211&view=rev
Log:
fixed python dependence on the content-length attribute (bz 419371)

Modified:
    incubator/qpid/trunk/qpid/python/qpid/connection.py
    incubator/qpid/trunk/qpid/python/qpid/peer.py
    incubator/qpid/trunk/qpid/python/tests_0-10/message.py

Modified: incubator/qpid/trunk/qpid/python/qpid/connection.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/connection.py?rev=613211&r1=613210&r2=613211&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/connection.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/connection.py Fri Jan 18 09:32:55 2008
@@ -360,7 +360,8 @@
 
     # message properties store the content-length now, and weight is
     # deprecated
-    structs[1].content_length = self.size
+    if self.size != None:
+      structs[1].content_length = self.size
 
     for s in structs:
       c.encode_long_struct(s)
@@ -412,9 +413,10 @@
     length = None
     for s in structs:
       for f in s.type.fields:
-        props[f.name] = s.get(f.name)
-        if f.name == "content_length":
-          length = s.get(f.name)
+        if s.has(f.name):
+          props[f.name] = s.get(f.name)
+          if f.name == "content_length":
+            length = s.get(f.name)
     return Header(None, 0, length, props)
 
   @staticmethod

Modified: incubator/qpid/trunk/qpid/python/qpid/peer.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/peer.py?rev=613211&r1=613210&r2=613211&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/peer.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/peer.py Fri Jan 18 09:32:55 2008
@@ -226,13 +226,12 @@
       self.write_content(frame.method_type.klass, content)
 
   def write_content(self, klass, content):
-    size = content.size()
-    header = Header(klass, content.weight(), size, content.properties)
+    header = Header(klass, content.weight(), content.size(), 
content.properties)
     self.write(header)
     for child in content.children:
       self.write_content(klass, child)
     # should split up if content.body exceeds max frame size
-    if size > 0:
+    if content.body:
       self.write(Body(content.body))
 
   def receive(self, frame, work):
@@ -360,14 +359,13 @@
   children = []
   for i in range(header.weight):
     children.append(read_content(queue))
-  size = header.size
-  read = 0
   buf = StringIO()
-  while read < size:
+  eof = header.eof
+  while not eof:
     body = queue.get()
+    eof = body.eof
     content = body.content
     buf.write(content)
-    read += len(content)
   return Content(buf.getvalue(), children, header.properties.copy())
 
 class Future:

Modified: incubator/qpid/trunk/qpid/python/tests_0-10/message.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/tests_0-10/message.py?rev=613211&r1=613210&r2=613211&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/tests_0-10/message.py (original)
+++ incubator/qpid/trunk/qpid/python/tests_0-10/message.py Fri Jan 18 09:32:55 
2008
@@ -720,6 +720,20 @@
         #check all 'browsed' messages are still on the queue
         self.assertEqual(5, channel.queue_query(queue="q").message_count)
 
+    def test_no_size(self):
+        self.queue_declare(queue = "q", exclusive=True, auto_delete=True)
+
+        ch = self.channel
+        ch.message_transfer(content=SizelessContent(properties={'routing_key' 
: "q"}, body="message-body"))
+
+        ch.message_subscribe(queue = "q", destination="d", confirm_mode = 0)
+        ch.message_flow(unit = 0, value = 0xFFFFFFFF, destination = "d")
+        ch.message_flow(unit = 1, value = 0xFFFFFFFF, destination = "d")
+
+        queue = self.client.queue("d")
+        msg = queue.get(timeout = 3)
+        self.assertEquals("message-body", msg.content.body)
+
     def assertDataEquals(self, channel, msg, expected):
         self.assertEquals(expected, msg.content.body)
 
@@ -728,3 +742,8 @@
             extra = queue.get(timeout=1)
             self.fail("Queue not empty, contains: " + extra.content.body)
         except Empty: None
+
+class SizelessContent(Content):
+
+    def size(self):
+        return None


Reply via email to