| 131 | logging.error('unknown command %s', command) |
| 132 | |
| 133 | def _parse_command(self, data): |
| 134 | # commands: |
| 135 | # add: {"server_port": 8000, "password": "foobar"} |
| 136 | # remove: {"server_port": 8000"} |
| 137 | data = common.to_str(data) |
| 138 | parts = data.split(':', 1) |
| 139 | if len(parts) < 2: |
| 140 | return data, None |
| 141 | command, config_json = parts |
| 142 | try: |
| 143 | config = shell.parse_json_in_str(config_json) |
| 144 | if 'method' in config: |
| 145 | config['method'] = common.to_str(config['method']) |
| 146 | return command, config |
| 147 | except Exception as e: |
| 148 | logging.error(e) |
| 149 | return None |
| 150 | |
| 151 | def stat_callback(self, port, data_len): |
| 152 | self._statistics[port] += data_len |