Created
April 8, 2014 01:33
-
-
Save aurynn/10081067 to your computer and use it in GitHub Desktop.
stdio protocol
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
class StdioProtocol(LineReceiver): | |
from os import linesep as delimiter | |
def connectionMade(self): | |
self.connected = True | |
def __init__(self, wire): | |
self.chat = wire | |
wire.output = self | |
def lineReceived(self, line): | |
try: | |
self.chat.sendMessage(line) | |
except NotConnectedError as e: | |
self.metaMessage(e) | |
def sendMessage(self, line): | |
if not self.connected: | |
raise NotConnectedError("Not connected") | |
self.sendLine(str("<{from}> {message}".format(**line) )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment