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."""
......
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