Exemplo n.º 1
0
    def read_msg_STP_0(self):
        """read length STP 0 message"""
        if len(self.in_buffer) >= self.msg_length:
            """
            t = int(1000*time())
            if t - self._last_time > 1000:
                print self._msg_count
                self._msg_count = 0
                self._last_time = t
            else:
                self._msg_count += 1
            """
            command, msg = self.in_buffer[0:self.msg_length].split(BLANK, 1)
            self.in_buffer = self.in_buffer[self.msg_length:]
            self.msg_length = 0
            msg = msg.encode("UTF-8")
            command = command.encode("UTF-8")
            if command == "*services":
                services = msg.split(',')
                print "services available:\n ", "\n  ".join(services)
                if not self.force_stp_0 and 'stp-1' in services:
                    self.set_initializer_STP_1()
                    self.send_command_STP_0('*enable stp-1')
                    self._service_list = services
                else:
                    scope.set_service_list(services)
                for service in services:
                    scope.services_enabled[service] = False
            elif command in scope.services_enabled:
                self.send_STP0_message_to_client(command, msg)

            self.check_input = self.read_int_STP_0
            self.check_input()
Exemplo n.º 2
0
 def read_STP_1_initializer(self):
     self.in_buffer += self.recv(BUFFERSIZE)
     if self.in_buffer.startswith("STP/1\n"):
         self.in_buffer = self.in_buffer[6:]
         scope.set_STP_version("stp-1")
         scope.set_service_list(self._service_list)
         self._service_list = None
         self.buf_cursor = 4
         self.handle_read = self.handle_read_STP_1
         self.handle_stp1_msg = self.handle_stp1_msg_default
         if self.in_buffer: self.handle_read()
Exemplo n.º 3
0
 def read_STP_1_initializer(self):
     self.in_buffer += self.recv(BUFFERSIZE)
     if self.in_buffer.startswith("STP/1\n"):
         self.in_buffer = self.in_buffer[6:]
         scope.set_STP_version("stp-1")
         scope.set_service_list(self._service_list)
         self._service_list = None
         self.buf_cursor = 4
         self.handle_read = self.handle_read_STP_1
         self.handle_stp1_msg = self.handle_stp1_msg_default
         if self.in_buffer: self.handle_read()
Exemplo n.º 4
0
 def read_STP_1_initializer(self):
     """read the STP/1 tolken"""
     self.in_buffer += self.recv(BUFFERSIZE)
     if self.in_buffer.startswith("STP/1\n"):
         self.in_buffer = self.in_buffer[6:]
         scope.set_STP_version('stp-1')
         scope.set_service_list(self._service_list)
         self._service_list = None
         self.handle_read = self.handle_read_STP_1
         self.check_input = self.read_stp1_token
         self.handle_stp1_msg = self.handle_stp1_msg_default
         if self.in_buffer:
             self.check_input()
Exemplo n.º 5
0
    def read_msg_STP_0(self):
        """read length STP 0 message"""
        if len(self.in_buffer) >= self.msg_length:
            command, msg = self.in_buffer[0:self.msg_length].split(BLANK, 1)
            self.in_buffer = self.in_buffer[self.msg_length:]
            self.msg_length = 0
            msg = msg.encode("UTF-8")
            command = command.encode("UTF-8")
            if command == "*services":
                services = msg.split(',')
                print "services available:\n ", "\n  ".join(services)
                if not self.force_stp_0 and 'stp-1' in services:
                    self.set_initializer_STP_1()
                    self.send_command_STP_0('*enable stp-1')
                    self._service_list = services
                else:
                    scope.set_service_list(services)
                for service in services:
                    scope.services_enabled[service] = False
            elif command in scope.services_enabled:
                self.send_STP0_message_to_client(command, msg)

            self.check_input = self.read_int_STP_0
            self.check_input()