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):
def analyse(self):
"""Analyse received data."""
while 1:
packet = None
try:
packet = Packet.parse(self.read_buf)
except PacketMalformedError, (packet, msg):
except PacketMalformedError, msg:
self.handler.packetMalformed(self, packet, msg)
return
......
......@@ -80,9 +80,12 @@ class EventHandler(object):
def packetMalformed(self, conn, packet, error_message):
"""Called when a packet is malformed."""
logging.info('malformed packet %x from %s:%d: %s',
packet.getType(), conn.getAddress()[0],
conn.getAddress()[1], error_message)
args = (conn.getAddress()[0], conn.getAddress()[1], error_message)
if packet is None:
# 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.abort()
self.peerBroken(conn)
......@@ -100,8 +103,8 @@ class EventHandler(object):
method(conn, packet, *args)
except (KeyError, ValueError):
self.handleUnexpectedPacket(conn, packet)
except PacketMalformedError, m:
self.packetMalformed(conn, packet, m[1])
except PacketMalformedError, msg:
self.packetMalformed(conn, packet, msg)
def handleUnexpectedPacket(self, conn, packet, message = None):
"""Handle an unexpected packet."""
......
This diff is collapsed.
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