(self, *args, **kwargs)
| 47 | self.colors['cs'] = '33' #client-to-server is yellow |
| 48 | |
| 49 | def write(self, *args, **kwargs): |
| 50 | if not self.format_is_set: |
| 51 | if 'clientip' in kwargs: |
| 52 | self.set_format(self._CONNECTION_FORMAT) |
| 53 | else: |
| 54 | self.set_format(self._PACKET_FORMAT) |
| 55 | self.format_is_set = True |
| 56 | |
| 57 | # a template string for data output |
| 58 | colorformat = "\x1b[%sm%s\x1b[0m" |
| 59 | |
| 60 | # Iterate over the args and try to parse out any raw data strings |
| 61 | rawdata = [] |
| 62 | for arg in args: |
| 63 | if type(arg) == dshell.core.Blob: |
| 64 | if arg.data: |
| 65 | rawdata.append((arg.data, arg.direction)) |
| 66 | elif type(arg) == dshell.core.Connection: |
| 67 | for blob in arg.blobs: |
| 68 | if blob.data: |
| 69 | rawdata.append((blob.data, blob.direction)) |
| 70 | elif type(arg) == dshell.core.Packet: |
| 71 | rawdata.append((arg.pkt.body_bytes, kwargs.get('direction', '--'))) |
| 72 | elif type(arg) == tuple: |
| 73 | rawdata.append(arg) |
| 74 | else: |
| 75 | rawdata.append((arg, kwargs.get('direction', '--'))) |
| 76 | |
| 77 | # Clean up the rawdata into something more presentable |
| 78 | if self.hexmode: |
| 79 | cleanup_func = dshell.util.hex_plus_ascii |
| 80 | else: |
| 81 | cleanup_func = dshell.util.printable_text |
| 82 | for k, v in enumerate(rawdata): |
| 83 | newdata = cleanup_func(v[0]) |
| 84 | rawdata[k] = (newdata, v[1]) |
| 85 | |
| 86 | # Convert the raw data strings into color-coded output |
| 87 | data = [] |
| 88 | for arg in rawdata: |
| 89 | datastring = colorformat % (self.colors.get(arg[1], '0'), arg[0]) |
| 90 | data.append(datastring) |
| 91 | |
| 92 | super().write(counter=self.counter, *data, **kwargs) |
| 93 | self.counter += 1 |
| 94 | |
| 95 | obj = ColorOutput |
nothing calls this directly
no test coverage detected