| 104 | return _safe_key(t[0]), _safe_key(t[1]) |
| 105 | |
| 106 | class PrettyPrinter: |
| 107 | def __init__(self, indent=1, width=80, depth=None, stream=None, *, |
| 108 | compact=False, sort_dicts=True, underscore_numbers=False): |
| 109 | """Handle pretty printing operations onto a stream using a set of |
| 110 | configured parameters. |
| 111 | |
| 112 | indent |
| 113 | Number of spaces to indent for each level of nesting. |
| 114 | |
| 115 | width |
| 116 | Attempted maximum number of columns in the output. |
| 117 | |
| 118 | depth |
| 119 | The maximum depth to print out nested structures. |
| 120 | |
| 121 | stream |
| 122 | The desired output stream. If omitted (or false), the standard |
| 123 | output stream available at construction will be used. |
| 124 | |
| 125 | compact |
| 126 | If true, several items will be combined in one line. |
| 127 | |
| 128 | sort_dicts |
| 129 | If true, dict keys are sorted. |
| 130 | |
| 131 | underscore_numbers |
| 132 | If true, digit groups are separated with underscores. |
| 133 | |
| 134 | """ |
| 135 | indent = int(indent) |
| 136 | width = int(width) |
| 137 | if indent < 0: |
| 138 | raise ValueError('indent must be >= 0') |
| 139 | if depth is not None and depth <= 0: |
| 140 | raise ValueError('depth must be > 0') |
| 141 | if not width: |
| 142 | raise ValueError('width must be != 0') |
| 143 | self._depth = depth |
| 144 | self._indent_per_level = indent |
| 145 | self._width = width |
| 146 | if stream is not None: |
| 147 | self._stream = stream |
| 148 | else: |
| 149 | self._stream = _sys.stdout |
| 150 | self._compact = bool(compact) |
| 151 | self._sort_dicts = sort_dicts |
| 152 | self._underscore_numbers = underscore_numbers |
| 153 | |
| 154 | def pprint(self, object): |
| 155 | if self._stream is not None: |
| 156 | self._format(object, self._stream, 0, 0, {}, 0) |
| 157 | self._stream.write("\n") |
| 158 | |
| 159 | def pformat(self, object): |
| 160 | sio = _StringIO() |
| 161 | self._format(object, sio, 0, 0, {}, 0) |
| 162 | return sio.getvalue() |
| 163 |
no outgoing calls
no test coverage detected