Show More
@@ -122,6 +122,7 b' else:' | |||
|
122 | 122 | __all__ = ['pretty', 'pprint', 'PrettyPrinter', 'RepresentationPrinter', |
|
123 | 123 | 'for_type', 'for_type_by_name'] |
|
124 | 124 | |
|
125 | ||
|
125 | 126 | _re_pattern_type = type(re.compile('')) |
|
126 | 127 | |
|
127 | 128 | def _failed_repr(obj, e): |
@@ -325,7 +326,17 b' class PrettyPrinter(_PrettyPrinterBase):' | |||
|
325 | 326 | self.group_stack.append(group) |
|
326 | 327 | self.group_queue.enq(group) |
|
327 | 328 | self.indentation += indent |
|
328 | ||
|
329 | ||
|
330 | def _enumerate(self, seq): | |
|
331 | """like enumerate, but with an upper limit on the number of items""" | |
|
332 | for idx, x in enumerate(seq): | |
|
333 | if idx >= self.max_seq_length: | |
|
334 | self.text(',') | |
|
335 | self.breakable() | |
|
336 | self.text('...') | |
|
337 | raise StopIteration | |
|
338 | yield idx, x | |
|
339 | ||
|
329 | 340 | def end_group(self, dedent=0, close=''): |
|
330 | 341 | """End a group. See `begin_group` for more details.""" |
|
331 | 342 | self.indentation -= dedent |
@@ -583,13 +594,6 b' def _default_pprint(obj, p, cycle):' | |||
|
583 | 594 | p.end_group(1, '>') |
|
584 | 595 | |
|
585 | 596 | |
|
586 | def _enumerate(seq, limit): | |
|
587 | """like enumerate, but with an upper limit on the number of items""" | |
|
588 | for idx, x in enumerate(seq): | |
|
589 | if idx >= limit: | |
|
590 | raise StopIteration | |
|
591 | yield idx, x | |
|
592 | ||
|
593 | 597 | def _seq_pprinter_factory(start, end, basetype): |
|
594 | 598 | """ |
|
595 | 599 | Factory that returns a pprint function useful for sequences. Used by |
@@ -605,17 +609,12 b' def _seq_pprinter_factory(start, end, basetype):' | |||
|
605 | 609 | return p.text(start + '...' + end) |
|
606 | 610 | step = len(start) |
|
607 | 611 | p.begin_group(step, start) |
|
608 |
for idx, x in _enumerate(obj |
|
|
612 | for idx, x in p._enumerate(obj): | |
|
609 | 613 | if idx: |
|
610 | 614 | p.text(',') |
|
611 | 615 | p.breakable() |
|
612 | 616 | p.pretty(x) |
|
613 | ||
|
614 | if len(obj) >= p.max_seq_length: | |
|
615 | p.text(',') | |
|
616 | p.breakable() | |
|
617 | p.text('...') | |
|
618 | elif len(obj) == 1 and type(obj) is tuple: | |
|
617 | if len(obj) == 1 and type(obj) is tuple: | |
|
619 | 618 | # Special case for 1-item tuples. |
|
620 | 619 | p.text(',') |
|
621 | 620 | p.end_group(step, end) |
@@ -647,16 +646,11 b' def _set_pprinter_factory(start, end, basetype):' | |||
|
647 | 646 | except Exception: |
|
648 | 647 | # Sometimes the items don't sort. |
|
649 | 648 | pass |
|
650 |
for idx, x in _enumerate(items |
|
|
649 | for idx, x in p._enumerate(items): | |
|
651 | 650 | if idx: |
|
652 | 651 | p.text(',') |
|
653 | 652 | p.breakable() |
|
654 | 653 | p.pretty(x) |
|
655 | ||
|
656 | if len(obj) >= p.max_seq_length: | |
|
657 | p.text(',') | |
|
658 | p.breakable() | |
|
659 | p.text('...') | |
|
660 | 654 | p.end_group(step, end) |
|
661 | 655 | return inner |
|
662 | 656 | |
@@ -681,18 +675,13 b' def _dict_pprinter_factory(start, end, basetype=None):' | |||
|
681 | 675 | except Exception as e: |
|
682 | 676 | # Sometimes the keys don't sort. |
|
683 | 677 | pass |
|
684 |
for idx, key in _enumerate(keys |
|
|
678 | for idx, key in p._enumerate(keys): | |
|
685 | 679 | if idx: |
|
686 | 680 | p.text(',') |
|
687 | 681 | p.breakable() |
|
688 | 682 | p.pretty(key) |
|
689 | 683 | p.text(': ') |
|
690 | 684 | p.pretty(obj[key]) |
|
691 | ||
|
692 | if len(obj) >= p.max_seq_length: | |
|
693 | p.text(',') | |
|
694 | p.breakable() | |
|
695 | p.text('...') | |
|
696 | 685 | p.end_group(1, end) |
|
697 | 686 | return inner |
|
698 | 687 |
General Comments 0
You need to be logged in to leave comments.
Login now