Created
December 23, 2018 22:24
-
-
Save ryancdotorg/38ec1f755eddfd3dd2dec05f32e44766 to your computer and use it in GitHub Desktop.
Twisted protocol for Exim's `readsocket` function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from zope.interface import implementer | |
from twisted.internet.interfaces import IHalfCloseableProtocol | |
from twisted.internet.protocol import Protocol | |
@implementer(IHalfCloseableProtocol) | |
class EximSocketProtocol(Protocol): | |
# buffer received data | |
def dataReceived(self, data): | |
if not hasattr(self, 'buf'): | |
self.buf = '' | |
self.buf += data | |
# write response and close socket | |
def sendResponse(self, response): | |
self.transport.write(response) | |
self.transport.loseConnection() | |
# needs to call sendResponse | |
def queryReceived(self, query): | |
raise NotImplementedError | |
# exim signals end of query by half-closing the connection | |
def readConnectionLost(self): | |
self.queryReceived(self.buf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment