|
16 | 16 | else: |
17 | 17 | pyg_lexer, pyg_formatter = PythonLexer(), Terminal256Formatter(style='vim') |
18 | 18 |
|
| 19 | +try: |
| 20 | + from multidict import MultiDict |
| 21 | +except ImportError: |
| 22 | + MultiDict = None |
| 23 | + |
19 | 24 | __all__ = 'PrettyFormat', 'pformat', 'pprint' |
20 | 25 |
|
21 | 26 | PARENTHESES_LOOKUP = [ |
@@ -50,13 +55,15 @@ def __init__(self, |
50 | 55 | self._width = width |
51 | 56 | self._type_lookup = [ |
52 | 57 | (dict, self._format_dict), |
53 | | - (str, self._format_str_bytes), |
54 | | - (bytes, self._format_str_bytes), |
| 58 | + ((str, bytes), self._format_str_bytes), |
55 | 59 | (tuple, self._format_tuples), |
56 | 60 | ((list, set, frozenset), self._format_list_like), |
57 | 61 | (Generator, self._format_generators), |
58 | 62 | ] |
59 | 63 |
|
| 64 | + if MultiDict: |
| 65 | + self._type_lookup.append((MultiDict, self._format_dict)) |
| 66 | + |
60 | 67 | def __call__(self, value: Any, *, indent: int = 0, indent_first: bool = False, highlight: bool = False): |
61 | 68 | self._stream = io.StringIO() |
62 | 69 | self._format(value, indent_current=indent, indent_first=indent_first) |
@@ -86,6 +93,9 @@ def _format_dict(self, value: dict, value_repr: str, indent_current: int, indent |
86 | 93 | if isinstance(value, OrderedDict): |
87 | 94 | open_, split_, after_, close_ = 'OrderedDict([\n', ', ', '),\n', '])' |
88 | 95 | before_ += '(' |
| 96 | + elif MultiDict and isinstance(value, MultiDict): |
| 97 | + open_, close_ = '<{}(\n'.format(value.__class__.__name__), ')>' |
| 98 | + |
89 | 99 | self._stream.write(open_) |
90 | 100 | for k, v in value.items(): |
91 | 101 | self._stream.write(before_) |
|
0 commit comments