| 81 | raise argparse.ArgumentError(action, '\n'.join(msg)) |
| 82 | |
| 83 | def parse_known_args(self, args, namespace=None): |
| 84 | parsed, remaining = super().parse_known_args(args, namespace) |
| 85 | terminal_encoding = getattr(sys.stdin, 'encoding', 'utf-8') |
| 86 | if terminal_encoding is None: |
| 87 | # In some cases, sys.stdin won't have an encoding set, |
| 88 | # (e.g if it's set to a StringIO). In this case we just |
| 89 | # default to utf-8. |
| 90 | terminal_encoding = 'utf-8' |
| 91 | for arg, value in vars(parsed).items(): |
| 92 | if isinstance(value, bytes): |
| 93 | setattr(parsed, arg, value.decode(terminal_encoding)) |
| 94 | elif isinstance(value, list): |
| 95 | encoded = [] |
| 96 | for v in value: |
| 97 | if isinstance(v, bytes): |
| 98 | encoded.append(v.decode(terminal_encoding)) |
| 99 | else: |
| 100 | encoded.append(v) |
| 101 | setattr(parsed, arg, encoded) |
| 102 | return parsed, remaining |
| 103 | |
| 104 | def error(self, message): |
| 105 | """error(message: string) |