num = decimal.Decimal(arg["num"]) if self.op: if self.op == "+": self.current += num elif self.op == "-": self.current -= num elif self.op == "*": self.current *= num elif self.op == "/": self.current /= num self.op = op else: self.op = op self.current = num res = str(self.current) if op == "=": self.clear() return res if __name__ == '__main__': log.startLogging(sys.stdout) decimal.getcontext().prec = 20 factory = AutobahnServerFactory(debug = False) factory.protocol = CalculatorServerProtocol reactor.listenTCP(9000, factory) reactor.run()
except: print "illegal topic - skipped publication of event" return None class SimpleServerProtocol(AutobahnServerProtocol): def onConnect(self, connectionRequest): ## register a single, fixed URI as PubSub topic self.registerForPubSub("http://example.com/event/simple") ## register a URI and all URIs having the string as prefix as PubSub topic #self.registerForPubSub("http://example.com/event/simple", True) ## register any URI (string) as topic #self.registerForPubSub("", True) ## register a topic handler to control topic subscriptions/publications self.topicservice = TopicService([1, 3, 7]) self.registerHandlerForPubSub(self.topicservice, "http://example.com/event/") if __name__ == '__main__': log.startLogging(sys.stdout) factory = AutobahnServerFactory(debug_autobahn = True) factory.protocol = SimpleServerProtocol reactor.listenTCP(9000, factory) reactor.run()
def __init__(self, debug = False): AutobahnServerFactory.__init__(self, debug) ## the key-value store resides on the factory object, since it is to ## be shared among all client connections self.keyvalue = KeyValue("keyvalue.dat")