Files
deb-python-eventlet/eventlet/twistedutil/protocols/basic.py
Denis Bilenko 597a2c0914 renamed twistedutil/basic.py to twistedutil/protocol.py;
removed listenXXX shortcuts: use reactor.listenXXX+SpawnFactory;
added buffer_class class attribute to SpawnFactory;
twistedutil: converted class names to CamelCase;
moved LineOnlyReceiverBuffer to twistedutil.protocols.basic;
fixed the examples.
2008-11-04 23:31:54 +06:00

35 lines
799 B
Python

from twisted.protocols import basic
from twisted.internet.error import ConnectionDone
from eventlet.api import spawn
from eventlet.twistedutil.protocol import BaseBuffer
class LineOnlyReceiver(basic.LineOnlyReceiver):
def lineReceived(self, line):
spawn(self.channel.send, line)
def connectionLost(self, reason):
self.channel.send_exception(reason.value)
class LineOnlyReceiverBuffer(BaseBuffer):
protocol_class = LineOnlyReceiver
def readline(self):
return self.channel.receive()
def sendline(self, line):
self.protocol.sendLine(line)
# iterator protocol:
def __iter__(self):
return self
def next(self):
try:
return self.readline()
except ConnectionDone:
raise StopIteration