def _connect_callback(self): if MessageMap.has_map(): self._http_connection.return_service_list(self._service_list) self._http_connection = None else: MessageMap(self._service_list, self._connection, self._connect_callback, self._http_connection.context)
def main_func(): args = _parse_args() if not args.ip: print "failed to get the IP of the machine" return if not os.path.isdir(args.root): parser.error("""Root directory "%s" does not exist""" % args.root) return if args.message_filter: from utils import MessageMap MessageMap.set_filter(args.message_filter) os.chdir(args.root) try: _run_proxy(args) except KeyboardInterrupt: args.upnp_device.notify_byby() asyncore.loop(timeout=args.poll_timeout, count=6) for fd, obj in asyncore.socket_map.items(): obj.close() sys.exit()
def return_scope_message_STP_1(self, msg, sender): """ return a message to the client message TransportMessage { required string service = 1; required uint32 commandID = 2; required uint32 format = 3; optional uint32 status = 4; optional uint32 tag = 5; required binary payload = 8; } """ if not msg[8]: # workaround, status 204 does not work msg[8] = ' ' if self.debug and (not self.debug_only_errors or msg[4] == MSG_TYPE_ERROR): pretty_print("send to client:", msg, self.debug_format, self.debug_format_payload, self.verbose_debug) if self.is_timing: tag = str(msg[5]) if tag in command_times: item = command_times.pop(tag) print item[0], print MessageMap.get_cmd_name(item[0], item[1]), print time() * 1000 - item[2] self.out_buffer += self.SCOPE_MESSAGE_STP_1 % ( get_timestamp(), msg[1], # service msg[2], # command msg[4], # status msg[5], # tag len(msg[8]), msg[8], # payload ) self.timeout = 0 if not sender == self: self.handle_write()