Commit d9b88d8b authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove packet argument from PacketMalformedError exception to move decode methods

from Packet class to protocol module in next commit as it was done for encoding.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@499 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 79c6f0c0
...@@ -207,9 +207,10 @@ class Connection(BaseConnection): ...@@ -207,9 +207,10 @@ class Connection(BaseConnection):
def analyse(self): def analyse(self):
"""Analyse received data.""" """Analyse received data."""
while 1: while 1:
packet = None
try: try:
packet = Packet.parse(self.read_buf) packet = Packet.parse(self.read_buf)
except PacketMalformedError, (packet, msg): except PacketMalformedError, msg:
self.handler.packetMalformed(self, packet, msg) self.handler.packetMalformed(self, packet, msg)
return return
......
...@@ -80,9 +80,12 @@ class EventHandler(object): ...@@ -80,9 +80,12 @@ class EventHandler(object):
def packetMalformed(self, conn, packet, error_message): def packetMalformed(self, conn, packet, error_message):
"""Called when a packet is malformed.""" """Called when a packet is malformed."""
logging.info('malformed packet %x from %s:%d: %s', args = (conn.getAddress()[0], conn.getAddress()[1], error_message)
packet.getType(), conn.getAddress()[0], if packet is None:
conn.getAddress()[1], error_message) # if decoding fail, there's no packet instance
logging.info('malformed packet from %s:%d: %s', *args)
else:
logging.info('malformed packet %s from %s:%d: %s', packet.getType(), *args)
conn.notify(protocol.protocolError(error_message)) conn.notify(protocol.protocolError(error_message))
conn.abort() conn.abort()
self.peerBroken(conn) self.peerBroken(conn)
...@@ -100,8 +103,8 @@ class EventHandler(object): ...@@ -100,8 +103,8 @@ class EventHandler(object):
method(conn, packet, *args) method(conn, packet, *args)
except (KeyError, ValueError): except (KeyError, ValueError):
self.handleUnexpectedPacket(conn, packet) self.handleUnexpectedPacket(conn, packet)
except PacketMalformedError, m: except PacketMalformedError, msg:
self.packetMalformed(conn, packet, m[1]) self.packetMalformed(conn, packet, msg)
def handleUnexpectedPacket(self, conn, packet, message = None): def handleUnexpectedPacket(self, conn, packet, message = None):
"""Handle an unexpected packet.""" """Handle an unexpected packet."""
......
...@@ -337,13 +337,11 @@ class Packet(object): ...@@ -337,13 +337,11 @@ class Packet(object):
try: try:
msg_type = packet_types[msg_type] msg_type = packet_types[msg_type]
except KeyError: except KeyError:
raise PacketMalformedError(cls(msg_id, msg_type), 'Unknown packet type') raise PacketMalformedError('Unknown packet type')
if msg_len > MAX_PACKET_SIZE: if msg_len > MAX_PACKET_SIZE:
raise PacketMalformedError(cls(msg_id, msg_type), raise PacketMalformedError('message too big (%d)' % msg_len)
'message too big (%d)' % msg_len)
if msg_len < MIN_PACKET_SIZE: if msg_len < MIN_PACKET_SIZE:
raise PacketMalformedError(cls(msg_id, msg_type), raise PacketMalformedError('message too small (%d)' % msg_len)
'message too small (%d)' % msg_len)
if len(msg) < msg_len: if len(msg) < msg_len:
# Not enough. # Not enough.
return None return None
...@@ -375,7 +373,7 @@ class Packet(object): ...@@ -375,7 +373,7 @@ class Packet(object):
def encode(self): def encode(self):
msg = pack('!LHL', self._id, self._type, PACKET_HEADER_SIZE + len(self._body)) + self._body msg = pack('!LHL', self._id, self._type, PACKET_HEADER_SIZE + len(self._body)) + self._body
if len(msg) > MAX_PACKET_SIZE: if len(msg) > MAX_PACKET_SIZE:
raise PacketMalformedError(self, 'message too big (%d)' % len(msg)) raise PacketMalformedError('message too big (%d)' % len(msg))
return msg return msg
__str__ = encode __str__ = encode
...@@ -385,7 +383,7 @@ class Packet(object): ...@@ -385,7 +383,7 @@ class Packet(object):
try: try:
method = self.decode_table[self._type] method = self.decode_table[self._type]
except KeyError: except KeyError:
raise PacketMalformedError(self, 'unknown message type 0x%x' % self._type) raise PacketMalformedError('unknown message type 0x%x' % self._type)
return method(self) return method(self)
decode_table = {} decode_table = {}
...@@ -396,9 +394,9 @@ class Packet(object): ...@@ -396,9 +394,9 @@ class Packet(object):
code, size = unpack('!HL', body[:6]) code, size = unpack('!HL', body[:6])
message = body[6:] message = body[6:]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid error message') raise PacketMalformedError('invalid error message')
if len(message) != size: if len(message) != size:
raise PacketMalformedError(self, 'invalid error message size') raise PacketMalformedError('invalid error message size')
return code, message return code, message
decode_table[ERROR] = _decodeError decode_table[ERROR] = _decodeError
...@@ -418,13 +416,13 @@ class Packet(object): ...@@ -418,13 +416,13 @@ class Packet(object):
ip_address = inet_ntoa(ip_address) ip_address = inet_ntoa(ip_address)
name = body[36:] name = body[36:]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid request node identification') raise PacketMalformedError('invalid request node identification')
if size != len(name): if size != len(name):
raise PacketMalformedError(self, 'invalid name size') raise PacketMalformedError('invalid name size')
if node_type not in VALID_NODE_TYPE_LIST: if node_type not in VALID_NODE_TYPE_LIST:
raise PacketMalformedError(self, 'invalid node type %d' % node_type) raise PacketMalformedError('invalid node type %d' % node_type)
if (major, minor) != PROTOCOL_VERSION: if (major, minor) != PROTOCOL_VERSION:
raise PacketMalformedError(self, 'protocol version mismatch') raise PacketMalformedError('protocol version mismatch')
return node_type, uuid, ip_address, port, name return node_type, uuid, ip_address, port, name
decode_table[REQUEST_NODE_IDENTIFICATION] = _decodeRequestNodeIdentification decode_table[REQUEST_NODE_IDENTIFICATION] = _decodeRequestNodeIdentification
...@@ -434,9 +432,9 @@ class Packet(object): ...@@ -434,9 +432,9 @@ class Packet(object):
= unpack('!H16s4sHLL16s', self._body) = unpack('!H16s4sHLL16s', self._body)
ip_address = inet_ntoa(ip_address) ip_address = inet_ntoa(ip_address)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid accept node identification') raise PacketMalformedError('invalid accept node identification')
if node_type not in VALID_NODE_TYPE_LIST: if node_type not in VALID_NODE_TYPE_LIST:
raise PacketMalformedError(self, 'invalid node type %d' % node_type) raise PacketMalformedError('invalid node type %d' % node_type)
return node_type, uuid, ip_address, port, num_partitions, num_replicas, your_uuid return node_type, uuid, ip_address, port, num_partitions, num_replicas, your_uuid
decode_table[ACCEPT_NODE_IDENTIFICATION] = _decodeAcceptNodeIdentification decode_table[ACCEPT_NODE_IDENTIFICATION] = _decodeAcceptNodeIdentification
...@@ -453,7 +451,7 @@ class Packet(object): ...@@ -453,7 +451,7 @@ class Packet(object):
ip_address = inet_ntoa(ip_address) ip_address = inet_ntoa(ip_address)
known_master_list.append((ip_address, port, uuid)) known_master_list.append((ip_address, port, uuid))
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer primary master') raise PacketMalformedError('invalid answer primary master')
return primary_uuid, known_master_list return primary_uuid, known_master_list
decode_table[ANSWER_PRIMARY_MASTER] = _decodeAnswerPrimaryMaster decode_table[ANSWER_PRIMARY_MASTER] = _decodeAnswerPrimaryMaster
...@@ -474,15 +472,15 @@ class Packet(object): ...@@ -474,15 +472,15 @@ class Packet(object):
node_type, ip_address, port, uuid, state = r node_type, ip_address, port, uuid, state = r
ip_address = inet_ntoa(ip_address) ip_address = inet_ntoa(ip_address)
if node_type not in VALID_NODE_TYPE_LIST: if node_type not in VALID_NODE_TYPE_LIST:
raise PacketMalformedError(self, 'invalid node type %d' % node_type) raise PacketMalformedError('invalid node type %d' % node_type)
state = node_states.get(state) state = node_states.get(state)
if state not in VALID_NODE_STATE_LIST: if state not in VALID_NODE_STATE_LIST:
raise PacketMalformedError(self, 'invalid node state %d' % state) raise PacketMalformedError('invalid node state %d' % state)
node_list.append((node_type, ip_address, port, uuid, state)) node_list.append((node_type, ip_address, port, uuid, state))
except PacketMalformedError: except PacketMalformedError:
raise raise
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer node information') raise PacketMalformedError('invalid answer node information')
return (node_list,) return (node_list,)
decode_table[NOTIFY_NODE_INFORMATION] = _decodeNotifyNodeInformation decode_table[NOTIFY_NODE_INFORMATION] = _decodeNotifyNodeInformation
...@@ -494,7 +492,7 @@ class Packet(object): ...@@ -494,7 +492,7 @@ class Packet(object):
try: try:
loid, ltid, lptid = unpack('!8s8s8s', self._body) loid, ltid, lptid = unpack('!8s8s8s', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer last ids') raise PacketMalformedError('invalid answer last ids')
return loid, ltid, lptid return loid, ltid, lptid
decode_table[ANSWER_LAST_IDS] = _decodeAnswerLastIDs decode_table[ANSWER_LAST_IDS] = _decodeAnswerLastIDs
...@@ -506,7 +504,7 @@ class Packet(object): ...@@ -506,7 +504,7 @@ class Packet(object):
offset = unpack('!L', self._body[4+i*4:8+i*4])[0] offset = unpack('!L', self._body[4+i*4:8+i*4])[0]
offset_list.append(offset) offset_list.append(offset)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask partition table') raise PacketMalformedError('invalid ask partition table')
return (offset_list,) return (offset_list,)
decode_table[ASK_PARTITION_TABLE] = _decodeAskPartitionTable decode_table[ASK_PARTITION_TABLE] = _decodeAskPartitionTable
...@@ -527,7 +525,7 @@ class Packet(object): ...@@ -527,7 +525,7 @@ class Packet(object):
row_list.append((offset, tuple(cell_list))) row_list.append((offset, tuple(cell_list)))
del cell_list[:] del cell_list[:]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer partition table') raise PacketMalformedError('invalid answer partition table')
return ptid, row_list return ptid, row_list
decode_table[ANSWER_PARTITION_TABLE] = _decodeAnswerPartitionTable decode_table[ANSWER_PARTITION_TABLE] = _decodeAnswerPartitionTable
...@@ -548,7 +546,7 @@ class Packet(object): ...@@ -548,7 +546,7 @@ class Packet(object):
row_list.append((offset, tuple(cell_list))) row_list.append((offset, tuple(cell_list)))
del cell_list[:] del cell_list[:]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid send partition table') raise PacketMalformedError('invalid send partition table')
return ptid, row_list return ptid, row_list
decode_table[SEND_PARTITION_TABLE] = _decodeSendPartitionTable decode_table[SEND_PARTITION_TABLE] = _decodeSendPartitionTable
...@@ -561,7 +559,7 @@ class Packet(object): ...@@ -561,7 +559,7 @@ class Packet(object):
state = partition_cell_states.get(state) state = partition_cell_states.get(state)
cell_list.append((offset, uuid, state)) cell_list.append((offset, uuid, state))
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid notify partition changes') raise PacketMalformedError('invalid notify partition changes')
return ptid, cell_list return ptid, cell_list
decode_table[NOTIFY_PARTITION_CHANGES] = _decodeNotifyPartitionChanges decode_table[NOTIFY_PARTITION_CHANGES] = _decodeNotifyPartitionChanges
...@@ -585,7 +583,7 @@ class Packet(object): ...@@ -585,7 +583,7 @@ class Packet(object):
tid = unpack('8s', self._body[4+i*8:12+i*8])[0] tid = unpack('8s', self._body[4+i*8:12+i*8])[0]
tid_list.append(tid) tid_list.append(tid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer unfinished transactions') raise PacketMalformedError('invalid answer unfinished transactions')
return (tid_list,) return (tid_list,)
decode_table[ANSWER_UNFINISHED_TRANSACTIONS] = _decodeAnswerUnfinishedTransactions decode_table[ANSWER_UNFINISHED_TRANSACTIONS] = _decodeAnswerUnfinishedTransactions
...@@ -593,7 +591,7 @@ class Packet(object): ...@@ -593,7 +591,7 @@ class Packet(object):
try: try:
oid, tid = unpack('8s8s', self._body) oid, tid = unpack('8s8s', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask object present') raise PacketMalformedError('invalid ask object present')
return oid, tid return oid, tid
decode_table[ASK_OBJECT_PRESENT] = _decodeAskObjectPresent decode_table[ASK_OBJECT_PRESENT] = _decodeAskObjectPresent
...@@ -601,7 +599,7 @@ class Packet(object): ...@@ -601,7 +599,7 @@ class Packet(object):
try: try:
oid, tid = unpack('8s8s', self._body) oid, tid = unpack('8s8s', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer object present') raise PacketMalformedError('invalid answer object present')
return oid, tid return oid, tid
decode_table[ANSWER_OBJECT_PRESENT] = _decodeAnswerObjectPresent decode_table[ANSWER_OBJECT_PRESENT] = _decodeAnswerObjectPresent
...@@ -609,7 +607,7 @@ class Packet(object): ...@@ -609,7 +607,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid delete transaction') raise PacketMalformedError('invalid delete transaction')
return (tid,) return (tid,)
decode_table[DELETE_TRANSACTION] = _decodeDeleteTransaction decode_table[DELETE_TRANSACTION] = _decodeDeleteTransaction
...@@ -617,7 +615,7 @@ class Packet(object): ...@@ -617,7 +615,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid commit transaction') raise PacketMalformedError('invalid commit transaction')
return (tid,) return (tid,)
decode_table[COMMIT_TRANSACTION] = _decodeCommitTransaction decode_table[COMMIT_TRANSACTION] = _decodeCommitTransaction
...@@ -629,7 +627,7 @@ class Packet(object): ...@@ -629,7 +627,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer new tid') raise PacketMalformedError('invalid answer new tid')
return (tid,) return (tid,)
decode_table[ANSWER_NEW_TID] = _decodeAnswerNewTID decode_table[ANSWER_NEW_TID] = _decodeAnswerNewTID
...@@ -637,7 +635,7 @@ class Packet(object): ...@@ -637,7 +635,7 @@ class Packet(object):
try: try:
num_oids = unpack('!H', self._body)[0] num_oids = unpack('!H', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask new oids') raise PacketMalformedError('invalid ask new oids')
return (num_oids,) return (num_oids,)
decode_table[ASK_NEW_OIDS] = _decodeAskNewOIDs decode_table[ASK_NEW_OIDS] = _decodeAskNewOIDs
...@@ -649,7 +647,7 @@ class Packet(object): ...@@ -649,7 +647,7 @@ class Packet(object):
oid = unpack('8s', self._body[2+i*8:10+i*8])[0] oid = unpack('8s', self._body[2+i*8:10+i*8])[0]
oid_list.append(oid) oid_list.append(oid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer new oids') raise PacketMalformedError('invalid answer new oids')
return (oid_list,) return (oid_list,)
decode_table[ANSWER_NEW_OIDS] = _decodeAnswerNewOIDs decode_table[ANSWER_NEW_OIDS] = _decodeAnswerNewOIDs
...@@ -661,7 +659,7 @@ class Packet(object): ...@@ -661,7 +659,7 @@ class Packet(object):
oid = unpack('8s', self._body[12+i*8:20+i*8])[0] oid = unpack('8s', self._body[12+i*8:20+i*8])[0]
oid_list.append(oid) oid_list.append(oid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid finish transaction') raise PacketMalformedError('invalid finish transaction')
return oid_list, tid return oid_list, tid
decode_table[FINISH_TRANSACTION] = _decodeFinishTransaction decode_table[FINISH_TRANSACTION] = _decodeFinishTransaction
...@@ -669,7 +667,7 @@ class Packet(object): ...@@ -669,7 +667,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid notify transactin finished') raise PacketMalformedError('invalid notify transactin finished')
return (tid,) return (tid,)
decode_table[NOTIFY_TRANSACTION_FINISHED] = _decodeNotifyTransactionFinished decode_table[NOTIFY_TRANSACTION_FINISHED] = _decodeNotifyTransactionFinished
...@@ -677,7 +675,7 @@ class Packet(object): ...@@ -677,7 +675,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid lock information') raise PacketMalformedError('invalid lock information')
return (tid,) return (tid,)
decode_table[LOCK_INFORMATION] = _decodeLockInformation decode_table[LOCK_INFORMATION] = _decodeLockInformation
...@@ -685,7 +683,7 @@ class Packet(object): ...@@ -685,7 +683,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid notify information locked') raise PacketMalformedError('invalid notify information locked')
return (tid,) return (tid,)
decode_table[NOTIFY_INFORMATION_LOCKED] = _decodeNotifyInformationLocked decode_table[NOTIFY_INFORMATION_LOCKED] = _decodeNotifyInformationLocked
...@@ -697,7 +695,7 @@ class Packet(object): ...@@ -697,7 +695,7 @@ class Packet(object):
oid = unpack('8s', self._body[i:i+8])[0] oid = unpack('8s', self._body[i:i+8])[0]
oid_list.append(oid) oid_list.append(oid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid finish transaction') raise PacketMalformedError('invalid finish transaction')
return oid_list, tid return oid_list, tid
decode_table[INVALIDATE_OBJECTS] = _decodeInvalidateObjects decode_table[INVALIDATE_OBJECTS] = _decodeInvalidateObjects
...@@ -705,7 +703,7 @@ class Packet(object): ...@@ -705,7 +703,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid unlock information') raise PacketMalformedError('invalid unlock information')
return (tid,) return (tid,)
decode_table[UNLOCK_INFORMATION] = _decodeUnlockInformation decode_table[UNLOCK_INFORMATION] = _decodeUnlockInformation
...@@ -713,7 +711,7 @@ class Packet(object): ...@@ -713,7 +711,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid abort transaction') raise PacketMalformedError('invalid abort transaction')
return (tid,) return (tid,)
decode_table[ABORT_TRANSACTION] = _decodeAbortTransaction decode_table[ABORT_TRANSACTION] = _decodeAbortTransaction
...@@ -723,9 +721,9 @@ class Packet(object): ...@@ -723,9 +721,9 @@ class Packet(object):
= unpack('!8s8s8sBLL', self._body[:33]) = unpack('!8s8s8sBLL', self._body[:33])
data = self._body[33:] data = self._body[33:]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask store object') raise PacketMalformedError('invalid ask store object')
if data_len != len(data): if data_len != len(data):
raise PacketMalformedError(self, 'invalid data size') raise PacketMalformedError('invalid data size')
return oid, serial, compression, checksum, data, tid return oid, serial, compression, checksum, data, tid
decode_table[ASK_STORE_OBJECT] = _decodeAskStoreObject decode_table[ASK_STORE_OBJECT] = _decodeAskStoreObject
...@@ -733,7 +731,7 @@ class Packet(object): ...@@ -733,7 +731,7 @@ class Packet(object):
try: try:
conflicting, oid, serial = unpack('!B8s8s', self._body) conflicting, oid, serial = unpack('!B8s8s', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer store object') raise PacketMalformedError('invalid answer store object')
return conflicting, oid, serial return conflicting, oid, serial
decode_table[ANSWER_STORE_OBJECT] = _decodeAnswerStoreObject decode_table[ANSWER_STORE_OBJECT] = _decodeAnswerStoreObject
...@@ -754,7 +752,7 @@ class Packet(object): ...@@ -754,7 +752,7 @@ class Packet(object):
offset += 8 offset += 8
oid_list.append(oid) oid_list.append(oid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask store transaction') raise PacketMalformedError('invalid ask store transaction')
return tid, user, desc, ext, oid_list return tid, user, desc, ext, oid_list
decode_table[ASK_STORE_TRANSACTION] = _decodeAskStoreTransaction decode_table[ASK_STORE_TRANSACTION] = _decodeAskStoreTransaction
...@@ -762,7 +760,7 @@ class Packet(object): ...@@ -762,7 +760,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer store transaction') raise PacketMalformedError('invalid answer store transaction')
return (tid,) return (tid,)
decode_table[ANSWER_STORE_TRANSACTION] = _decodeAnswerStoreTransaction decode_table[ANSWER_STORE_TRANSACTION] = _decodeAnswerStoreTransaction
...@@ -770,7 +768,7 @@ class Packet(object): ...@@ -770,7 +768,7 @@ class Packet(object):
try: try:
oid, serial, tid = unpack('8s8s8s', self._body) oid, serial, tid = unpack('8s8s8s', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask object') raise PacketMalformedError('invalid ask object')
return oid, serial, tid return oid, serial, tid
decode_table[ASK_OBJECT] = _decodeAskObject decode_table[ASK_OBJECT] = _decodeAskObject
...@@ -780,9 +778,9 @@ class Packet(object): ...@@ -780,9 +778,9 @@ class Packet(object):
= unpack('!8s8s8sBLL', self._body[:33]) = unpack('!8s8s8sBLL', self._body[:33])
data = self._body[33:] data = self._body[33:]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer object') raise PacketMalformedError('invalid answer object')
if len(data) != data_len: if len(data) != data_len:
raise PacketMalformedError(self, 'invalid data size') raise PacketMalformedError('invalid data size')
return oid, serial_start, serial_end, compression, checksum, data return oid, serial_start, serial_end, compression, checksum, data
decode_table[ANSWER_OBJECT] = _decodeAnswerObject decode_table[ANSWER_OBJECT] = _decodeAnswerObject
...@@ -790,7 +788,7 @@ class Packet(object): ...@@ -790,7 +788,7 @@ class Packet(object):
try: try:
first, last, partition = unpack('!QQL', self._body) first, last, partition = unpack('!QQL', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask tids') raise PacketMalformedError('invalid ask tids')
return first, last, partition return first, last, partition
decode_table[ASK_TIDS] = _decodeAskTIDs decode_table[ASK_TIDS] = _decodeAskTIDs
...@@ -802,7 +800,7 @@ class Packet(object): ...@@ -802,7 +800,7 @@ class Packet(object):
tid = unpack('8s', self._body[4+i*8:12+i*8])[0] tid = unpack('8s', self._body[4+i*8:12+i*8])[0]
tid_list.append(tid) tid_list.append(tid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer tids') raise PacketMalformedError('invalid answer tids')
return (tid_list,) return (tid_list,)
decode_table[ANSWER_TIDS] = _decodeAnswerTIDs decode_table[ANSWER_TIDS] = _decodeAnswerTIDs
...@@ -810,7 +808,7 @@ class Packet(object): ...@@ -810,7 +808,7 @@ class Packet(object):
try: try:
tid = unpack('8s', self._body)[0] tid = unpack('8s', self._body)[0]
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask transaction information') raise PacketMalformedError('invalid ask transaction information')
return (tid,) return (tid,)
decode_table[ASK_TRANSACTION_INFORMATION] = _decodeAskTransactionInformation decode_table[ASK_TRANSACTION_INFORMATION] = _decodeAskTransactionInformation
...@@ -830,7 +828,7 @@ class Packet(object): ...@@ -830,7 +828,7 @@ class Packet(object):
oid = unpack('8s', self._body[offset+i*8:offset+8+i*8])[0] oid = unpack('8s', self._body[offset+i*8:offset+8+i*8])[0]
oid_list.append(oid) oid_list.append(oid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer transaction information') raise PacketMalformedError('invalid answer transaction information')
return tid, user, desc, ext, oid_list return tid, user, desc, ext, oid_list
decode_table[ANSWER_TRANSACTION_INFORMATION] = _decodeAnswerTransactionInformation decode_table[ANSWER_TRANSACTION_INFORMATION] = _decodeAnswerTransactionInformation
...@@ -838,7 +836,7 @@ class Packet(object): ...@@ -838,7 +836,7 @@ class Packet(object):
try: try:
oid, first, last = unpack('!8sQQ', self._body) oid, first, last = unpack('!8sQQ', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask object history') raise PacketMalformedError('invalid ask object history')
return oid, first, last return oid, first, last
decode_table[ASK_OBJECT_HISTORY] = _decodeAskObjectHistory decode_table[ASK_OBJECT_HISTORY] = _decodeAskObjectHistory
...@@ -850,7 +848,7 @@ class Packet(object): ...@@ -850,7 +848,7 @@ class Packet(object):
serial, size = unpack('!8sL', self._body[i:i+12]) serial, size = unpack('!8sL', self._body[i:i+12])
history_list.append((serial, size)) history_list.append((serial, size))
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer object history') raise PacketMalformedError('invalid answer object history')
return oid, history_list return oid, history_list
decode_table[ANSWER_OBJECT_HISTORY] = _decodeAnswerObjectHistory decode_table[ANSWER_OBJECT_HISTORY] = _decodeAnswerObjectHistory
...@@ -858,7 +856,7 @@ class Packet(object): ...@@ -858,7 +856,7 @@ class Packet(object):
try: try:
first, last, partition = unpack('!QQL', self._body) first, last, partition = unpack('!QQL', self._body)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid ask oids') raise PacketMalformedError('invalid ask oids')
return first, last, partition return first, last, partition
decode_table[ASK_OIDS] = _decodeAskOIDs decode_table[ASK_OIDS] = _decodeAskOIDs
...@@ -870,7 +868,7 @@ class Packet(object): ...@@ -870,7 +868,7 @@ class Packet(object):
oid = unpack('8s', self._body[4+i*8:12+i*8])[0] oid = unpack('8s', self._body[4+i*8:12+i*8])[0]
oid_list.append(oid) oid_list.append(oid)
except struct.error, msg: except struct.error, msg:
raise PacketMalformedError(self, 'invalid answer oids') raise PacketMalformedError('invalid answer oids')
return (oid_list,) return (oid_list,)
decode_table[ANSWER_OIDS] = _decodeAnswerOIDs decode_table[ANSWER_OIDS] = _decodeAnswerOIDs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment