MQOpts unpack in pymqi.py doesn't unflatten arrays
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
PyMQI |
Invalid
|
Wishlist
|
Unassigned |
Bug Description
The pack() in class MQOpts flattens attributes that are arrays. However, the unpack does not unflatten them on the way back.
unpack should be changed to something like this to work:
def unpack(self, buff):
Unpack a 'C' structure 'buff' into self."""
# Unpack returns a tuple of the unpacked data, in the same
# order (I hope!) as in the ctor's list arg.
r = struct.
x = 0
for i in self.__list:
v = getattr(self, i[0])
if type(v) is types.ListType:
for jj in range(len(v)):
x += 1
else:
x += 1
I found this because I thought I was having a problem with the message id that was coming back after getting a message. I thought the pack/unpack was truncating the message id on the first null character. So, I change class md to use 24B instead of 24s for MsgId and defaulted it to [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] instead of ''. This worked fine except for on the way back, unpack didn't unpack the array. When I put the unpack code above in, it worked. It turns out pymqi wasn't causing the truncation of the message id, it was my pygtk code. So, leaving MsgId as 24s is fine. The current unpack code is wrong though and should be fixed. I'm not sure anything that is packed ever has an array but for some reason the pack function handles it so the unpack should also. Later versions of MQ may have a parameter that needs it someday.
Hey,
as a quick hint, without trying your code yet, does the explanation from http:// packages. python. org/pymqi/ #caveats do the trick for you?