Commit 79c6f0c0 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Add PacketMalformedError exception that inherit from ProtocolError to replace

the last one with decoding errors. New protocol exceptions will follows in next
commits.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@498 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 746fed5b
...@@ -21,7 +21,7 @@ import sys ...@@ -21,7 +21,7 @@ import sys
import traceback import traceback
from neo import protocol from neo import protocol
from neo.protocol import Packet, ProtocolError from neo.protocol import Packet, PacketMalformedError
from neo.event import IdleEvent from neo.event import IdleEvent
from neo.connector import ConnectorException, ConnectorTryAgainException, \ from neo.connector import ConnectorException, ConnectorTryAgainException, \
ConnectorInProgressException, ConnectorConnectionRefusedException ConnectorInProgressException, ConnectorConnectionRefusedException
...@@ -209,8 +209,8 @@ class Connection(BaseConnection): ...@@ -209,8 +209,8 @@ class Connection(BaseConnection):
while 1: while 1:
try: try:
packet = Packet.parse(self.read_buf) packet = Packet.parse(self.read_buf)
except ProtocolError, m: except PacketMalformedError, (packet, msg):
self.handler.packetMalformed(self, *m) self.handler.packetMalformed(self, packet, msg)
return return
if packet is None: if packet is None:
...@@ -286,9 +286,11 @@ class Connection(BaseConnection): ...@@ -286,9 +286,11 @@ class Connection(BaseConnection):
packet.getType(), dump(self.uuid), *self.getAddress()) packet.getType(), dump(self.uuid), *self.getAddress())
try: try:
self.write_buf += packet.encode() self.write_buf += packet.encode()
except ProtocolError, m: except PacketMalformedError, m:
logging.critical('trying to send a too big message') logging.critical('trying to send a too big message')
return self.addPacket(protocol.internalError(m[0])) # XXX: we should assert that the internalError packet has a size
# lower than MAX_PACKET_SIZE
return self.notify(protocol.internalError(m))
# If this is the first time, enable polling for writing. # If this is the first time, enable polling for writing.
if self.write_buf: if self.write_buf:
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import logging import logging
from neo import protocol from neo import protocol
from neo.protocol import Packet, ProtocolError from neo.protocol import Packet, PacketMalformedError
from neo.connection import ServerConnection from neo.connection import ServerConnection
from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICATION, \
...@@ -100,7 +100,7 @@ class EventHandler(object): ...@@ -100,7 +100,7 @@ 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 ProtocolError, m: except PacketMalformedError, m:
self.packetMalformed(conn, packet, m[1]) self.packetMalformed(conn, packet, m[1])
def handleUnexpectedPacket(self, conn, packet, message = None): def handleUnexpectedPacket(self, conn, packet, message = None):
......
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