summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpython/hello-010-world4
-rw-r--r--python/qpid/assembler.py6
-rw-r--r--python/qpid/codec.py6
-rw-r--r--python/qpid/datatypes.py12
-rw-r--r--python/qpid/framer.py16
5 files changed, 35 insertions, 9 deletions
diff --git a/python/hello-010-world b/python/hello-010-world
index 7685af8fd3..91ebc242c6 100755
--- a/python/hello-010-world
+++ b/python/hello-010-world
@@ -1,10 +1,14 @@
#!/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)
conn.start(timeout=10)
diff --git a/python/qpid/assembler.py b/python/qpid/assembler.py
index e0e5d3fb72..aac8b80cb4 100644
--- a/python/qpid/assembler.py
+++ b/python/qpid/assembler.py
@@ -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 @@ class Assembler(Framer):
if frame.isLastFrame():
self.fragments.pop(key)
+ log.debug("RECV: %s", seg)
return seg
def write_segment(self, segment):
@@ -108,3 +112,5 @@ class Assembler(Framer):
frame = Frame(flags, segment.type, segment.track, segment.channel,
payload)
self.write_frame(frame)
+
+ log.debug("SENT: %s", segment)
diff --git a/python/qpid/codec.py b/python/qpid/codec.py
index 1a9372455d..dfa74b6a2f 100644
--- a/python/qpid/codec.py
+++ b/python/qpid/codec.py
@@ -198,7 +198,7 @@ class Codec:
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 @@ class Codec:
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 @@ class Codec:
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):
"""
diff --git a/python/qpid/datatypes.py b/python/qpid/datatypes.py
index 9e3177154e..649c8f4d76 100644
--- a/python/qpid/datatypes.py
+++ b/python/qpid/datatypes.py
@@ -33,9 +33,15 @@ class Struct:
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:
diff --git a/python/qpid/framer.py b/python/qpid/framer.py
index adc52cc3bd..f4ec53dc07 100644
--- a/python/qpid/framer.py
+++ b/python/qpid/framer.py
@@ -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 Frame:
class Closed(Exception): pass
+class FramingError(Exception): pass
+
class Framer(Packer):
HEADER="!4s4B"
@@ -74,7 +80,6 @@ class Framer(Packer):
return False
def write(self, buf):
-# print "OUT: %r" % buf
while buf:
try:
n = self.sock.send(buf)
@@ -83,6 +88,7 @@ class Framer(Packer):
raise Closed()
else:
continue
+ raw.debug("SENT: %r", buf[:n])
buf = buf[n:]
def read(self, n):
@@ -102,8 +108,8 @@ class Framer(Packer):
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 @@ class Framer(Packer):
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