Skip to content

Instantly share code, notes, and snippets.

@aurynn
Created April 7, 2014 23:52
Show Gist options
  • Save aurynn/10074760 to your computer and use it in GitHub Desktop.
Save aurynn/10074760 to your computer and use it in GitHub Desktop.
Echo client lineReceived()
def lineReceived(self, msg):
try:
msg = json.loads(msg)
except json.JSONDecoderError:
print "Received a non-JSON message: %s" % msg
if "message" in msg:
print "<{from}> {message}".format(**msg)
elif "acknowledge" in msg:
if not msg["acknowledge"] in self.msgs:
print "We got a bad ack: {id}".format(msg["acknowledge"])
return
id_ = msg["acknowledge"]
print id_
self.msgs[id_]["deferred"].callback(self.msgs[id_]["msg"])
del self.msgs[id_]
else:
print json.dumps(msg,indent=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment