Show More
@@ -196,19 +196,22 b' class PrettyPrinter(_PrettyPrinterBase):' | |||
|
196 | 196 | self.group_queue = GroupQueue(root_group) |
|
197 | 197 | self.indentation = 0 |
|
198 | 198 | |
|
199 |
def _break_o |
|
|
199 | def _break_one_group(self, group): | |
|
200 | while group.breakables: | |
|
201 | x = self.buffer.popleft() | |
|
202 | self.output_width = x.output(self.output, self.output_width) | |
|
203 | self.buffer_width -= x.width | |
|
204 | while self.buffer and isinstance(self.buffer[0], Text): | |
|
205 | x = self.buffer.popleft() | |
|
206 | self.output_width = x.output(self.output, self.output_width) | |
|
207 | self.buffer_width -= x.width | |
|
208 | ||
|
209 | def _break_outer_groups(self, force=): | |
|
200 | 210 | while self.max_width < self.output_width + self.buffer_width: |
|
201 | 211 | group = self.group_queue.deq() |
|
202 | 212 | if not group: |
|
203 | 213 | return |
|
204 | while group.breakables: | |
|
205 | x = self.buffer.popleft() | |
|
206 | self.output_width = x.output(self.output, self.output_width) | |
|
207 | self.buffer_width -= x.width | |
|
208 | while self.buffer and isinstance(self.buffer[0], Text): | |
|
209 | x = self.buffer.popleft() | |
|
210 | self.output_width = x.output(self.output, self.output_width) | |
|
211 | self.buffer_width -= x.width | |
|
214 | self._break_one_group(group) | |
|
212 | 215 | |
|
213 | 216 | def text(self, obj): |
|
214 | 217 | """Add literal text to the output.""" |
@@ -248,6 +251,9 b' class PrettyPrinter(_PrettyPrinterBase):' | |||
|
248 | 251 | """ |
|
249 | 252 | Explicitly insert a newline into the output, maintaining correct indentation. |
|
250 | 253 | """ |
|
254 | group = self.group_queue.deq() | |
|
255 | if group: | |
|
256 | self._break_one_group(group) | |
|
251 | 257 | self.flush() |
|
252 | 258 | self.output.write(self.newline) |
|
253 | 259 | self.output.write(' ' * self.indentation) |
@@ -688,13 +694,11 b' def _repr_pprint(obj, p, cycle):' | |||
|
688 | 694 | # Find newlines and replace them with p.break_() |
|
689 | 695 | output = repr(obj) |
|
690 | 696 | lines = output.splitlines() |
|
691 | # insert a leading newline for multi-line objects that are indented | |
|
692 | if len(lines) > 1 and p.indentation != p.output_width: | |
|
693 | p.break_() | |
|
694 | for idx, output_line in enumerate(lines): | |
|
695 | if idx: | |
|
696 | p.break_() | |
|
697 | p.text(output_line) | |
|
697 | with p.group(): | |
|
698 | for idx, output_line in enumerate(lines): | |
|
699 | if idx: | |
|
700 | p.break_() | |
|
701 | p.text(output_line) | |
|
698 | 702 | |
|
699 | 703 | |
|
700 | 704 | def _function_pprint(obj, p, cycle): |
General Comments 0
You need to be logged in to leave comments.
Login now