コード例 #1
0
      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()
コード例 #2
0
ファイル: server.py プロジェクト: chadselph/Autobahn
      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()
コード例 #3
0
ファイル: keyvalue_server.py プロジェクト: chadselph/Autobahn
   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")