The pprint function for regular expression patterns.
(obj, p, cycle)
| 624 | |
| 625 | |
| 626 | def _re_pattern_pprint(obj, p, cycle): |
| 627 | """The pprint function for regular expression patterns.""" |
| 628 | p.text('re.compile(') |
| 629 | pattern = repr(obj.pattern) |
| 630 | if pattern[:1] in 'uU': |
| 631 | pattern = pattern[1:] |
| 632 | prefix = 'ur' |
| 633 | else: |
| 634 | prefix = 'r' |
| 635 | pattern = prefix + pattern.replace('\\\\', '\\') |
| 636 | p.text(pattern) |
| 637 | if obj.flags: |
| 638 | p.text(',') |
| 639 | p.breakable() |
| 640 | done_one = False |
| 641 | for flag in ('TEMPLATE', 'IGNORECASE', 'LOCALE', 'MULTILINE', 'DOTALL', |
| 642 | 'UNICODE', 'VERBOSE', 'DEBUG'): |
| 643 | if obj.flags & getattr(re, flag): |
| 644 | if done_one: |
| 645 | p.text('|') |
| 646 | p.text('re.' + flag) |
| 647 | done_one = True |
| 648 | p.text(')') |
| 649 | |
| 650 | |
| 651 | def _types_simplenamespace_pprint(obj, p, cycle): |