Author: rhs
Date: Wed Mar  5 03:12:39 2008
New Revision: 633815

URL: http://svn.apache.org/viewvc?rev=633815&view=rev
Log:
added logging; fixed deprecation warnings in old codec; filled in 
datatypes.Message

Modified:
    incubator/qpid/trunk/qpid/python/hello-010-world
    incubator/qpid/trunk/qpid/python/qpid/assembler.py
    incubator/qpid/trunk/qpid/python/qpid/codec.py
    incubator/qpid/trunk/qpid/python/qpid/datatypes.py
    incubator/qpid/trunk/qpid/python/qpid/framer.py

Modified: incubator/qpid/trunk/qpid/python/hello-010-world
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/hello-010-world?rev=633815&r1=633814&r2=633815&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/hello-010-world (original)
+++ incubator/qpid/trunk/qpid/python/hello-010-world Wed Mar  5 03:12:39 2008
@@ -1,9 +1,13 @@
 #!/usr/bin/env python
 
+import logging
 from qpid.connection010 import Connection
 from qpid.spec010 import load
 from qpid.util import connect
 from qpid.datatypes import Message
+
+format = "%(asctime)s %(name)-12s %(levelname)-8s %(message)s"
+logging.basicConfig(level=logging.DEBUG, format=format, datefmt='%H:%M:%S')
 
 spec = load("../specs/amqp.0-10.xml")
 conn = Connection(connect("0.0.0.0", spec.port), spec)

Modified: incubator/qpid/trunk/qpid/python/qpid/assembler.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/assembler.py?rev=633815&r1=633814&r2=633815&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/assembler.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/assembler.py Wed Mar  5 03:12:39 2008
@@ -19,6 +19,9 @@
 
 from codec010 import StringCodec
 from framer import *
+from logging import getLogger
+
+log = getLogger("qpid.io.seg")
 
 class Segment:
 
@@ -84,6 +87,7 @@
 
       if frame.isLastFrame():
         self.fragments.pop(key)
+        log.debug("RECV: %s", seg)
         return seg
 
   def write_segment(self, segment):
@@ -108,3 +112,5 @@
       frame = Frame(flags, segment.type, segment.track, segment.channel,
                     payload)
       self.write_frame(frame)
+
+    log.debug("SENT: %s", segment)

Modified: incubator/qpid/trunk/qpid/python/qpid/codec.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/codec.py?rev=633815&r1=633814&r2=633815&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/codec.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/codec.py Wed Mar  5 03:12:39 2008
@@ -198,7 +198,7 @@
     if (o < 0 or o > 255):
         raise ValueError('Valid range of octet is [0,255]')
 
-    self.pack("!B", o)
+    self.pack("!B", int(o))
 
   def decode_octet(self):
     """
@@ -215,7 +215,7 @@
     if (o < 0 or o > 65535):
         raise ValueError('Valid range of short int is [0,65535]: %s' % o)
 
-    self.pack("!H", o)
+    self.pack("!H", int(o))
 
   def decode_short(self):
     """
@@ -233,7 +233,7 @@
     if (o < 0 or o > 4294967295):
       raise ValueError('Valid range of long int is [0,4294967295]')
 
-    self.pack("!L", o)
+    self.pack("!L", int(o))
 
   def decode_long(self):
     """

Modified: incubator/qpid/trunk/qpid/python/qpid/datatypes.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/datatypes.py?rev=633815&r1=633814&r2=633815&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/datatypes.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/datatypes.py Wed Mar  5 03:12:39 2008
@@ -33,9 +33,15 @@
 
 class Message:
 
-  def __init__(self, body):
-    self.headers = None
-    self.body = body
+  def __init__(self, *args):
+    if args:
+      self.body = args[-1]
+    else:
+      self.body = None
+    if len(args) > 1:
+      self.headers = args[:-1]
+    else:
+      self.headers = None
 
 class Range:
 

Modified: incubator/qpid/trunk/qpid/python/qpid/framer.py
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/python/qpid/framer.py?rev=633815&r1=633814&r2=633815&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/python/qpid/framer.py (original)
+++ incubator/qpid/trunk/qpid/python/qpid/framer.py Wed Mar  5 03:12:39 2008
@@ -19,6 +19,10 @@
 
 import struct, socket
 from packer import Packer
+from logging import getLogger
+
+raw = getLogger("qpid.io.raw")
+frm = getLogger("qpid.io.frm")
 
 FIRST_SEG = 0x08
 LAST_SEG = 0x04
@@ -63,6 +67,8 @@
 
 class Closed(Exception): pass
 
+class FramingError(Exception): pass
+
 class Framer(Packer):
 
   HEADER="!4s4B"
@@ -74,7 +80,6 @@
     return False
 
   def write(self, buf):
-#    print "OUT: %r" % buf
     while buf:
       try:
         n = self.sock.send(buf)
@@ -83,6 +88,7 @@
           raise Closed()
         else:
           continue
+      raw.debug("SENT: %r", buf[:n])
       buf = buf[n:]
 
   def read(self, n):
@@ -102,8 +108,8 @@
           raise Closed()
       if len(s) == 0:
         raise Closed()
-#      print "IN: %r" % s
       data += s
+      raw.debug("RECV: %r", s)
     return data
 
   def read_header(self):
@@ -117,8 +123,12 @@
     track = frame.track & 0x0F
     self.pack(Frame.HEADER, frame.flags, frame.type, size, track, 
frame.channel)
     self.write(frame.payload)
+    frm.debug("SENT: %s", frame)
 
   def read_frame(self):
     flags, type, size, track, channel = self.unpack(Frame.HEADER)
+    if flags & 0xF0: raise FramingError()
     payload = self.read(size - struct.calcsize(Frame.HEADER))
-    return Frame(flags, type, track, channel, payload)
+    frame = Frame(flags, type, track, channel, payload)
+    frm.debug("RECV: %s", frame)
+    return frame


Reply via email to