Exemplo n.º 1
0
 def broadcast(self, name, message):
     targets = []
     message = ",".join(["msg", name, message])
     for p, topics in self._connections.items():
         if name in topics:
             targets.append(p)
     utils.broadcast(message, targets)
    def dataReceived(self, data):

        broadcast(data, self.factory.transports)
        self.message_count += 1

        if self.message_count == self.message_target:
            reactor.stop()
Exemplo n.º 3
0
    def add_user(self, data):
        """This function will start the process of adding a new ZNC user.

        It begins by retrieving a username and password from the socket via
        `parse_user_info()`, and then validates the desired username. If
        successful, it will add the user to ZNC, and then relay the
        success/failure status and message back to the client.

        Args:
            data: the raw data sent from the registration page client-side
                    to the server via a SockJS connection

        """

        username, password = self.parse_user_info(data)

        self.status, self.message = self.validate_username(username)

        if self.status:

            print 'Added a new user!  "' + username + '" is now registered.'

            self.znc_admin.add_user(username, password)

        broadcast(self.message, self.factory.transports)
Exemplo n.º 4
0
 def broadcast(self, name, message):
     targets = []
     message = ",".join(["msg", name, message])
     for p, topics in self._connections.items():
         if name in topics:
             targets.append(p)
     utils.broadcast(message, targets)
Exemplo n.º 5
0
    def send(self, message):
        """ This function simply sends a message via SockJS back to the client.
        It is defined outside of the protocol class so that it can be accessed
        outside of the instance of this factory class.

        :param message: the message to send back to the client

        """

        broadcast(message, self.transports)
Exemplo n.º 6
0
    def gotMessage(self, message_id, *messageParts):
        message = ''.join(messageParts)
        data = json.loads(message)
        key = '{}:{}'.format(data['organization_id'], data['project_id'])
        #print(key)
        #print(transports)
        channels = transports.get(key, False)
        if channels:
            broadcast(message, channels)

        self.reply(message_id, '')
Exemplo n.º 7
0
    def connectionMade(self):
        print 'made connection'
        if not hasattr(self.factory, "transports"):
            self.factory.transports = set()
        self.factory.transports.add(self.transport)

        # Load contents
        wiki_list = []
        if os.path.exists('data.p'):
            try:
                wiki_list = pickle.load( open("data.p", "rb"))
            except exceptions.EOFError:
                pickle.dump( wiki_list, open("data.p", "wb"))
        else:
            pickle.dump(wiki_list, open("data.p", "wb+"))

        broadcast(json.dumps(wiki_list), self.factory.transports)
Exemplo n.º 8
0
 def test_broadcast(self):
     targets = [MockTransport(), MockTransport(), MockTransport()]
     utils.broadcast("Hello!", targets, self.encoding)
     for t in targets:
         self.assertEqual(t.value, 'a["Hello!"]')
Exemplo n.º 9
0
 def dataReceived(self, data):
     print 'received data'
     wiki_list = json.loads(data)
     pickle.dump( wiki_list, open("data.p", "wb"))
     broadcast(json.dumps(wiki_list), self.factory.transports)
Exemplo n.º 10
0
 def dataReceived(self, data):
     broadcast(data, self.factory.transports)
Exemplo n.º 11
0
 def test_broadcast(self):
     targets = [MockTransport(), MockTransport(), MockTransport()]
     utils.broadcast("Hello!", targets, self.encoding)
     for t in targets:
         self.assertEqual(t.value, 'a["Hello!"]')
Exemplo n.º 12
0
 def dataReceived(self, data):
     print data
     broadcast('reply: ' + data, self.factory.transports)