|
26 | 26 | PRECEDENCE, |
27 | 27 | minint, |
28 | 28 | ) |
29 | | -from uncompyle6.semantics.helper import find_code_node, flatten_list |
| 29 | +from uncompyle6.semantics.helper import find_code_node, flatten_list, print_docstring |
30 | 30 | from uncompyle6.util import better_repr, get_code_name |
31 | 31 |
|
32 | 32 |
|
@@ -541,70 +541,7 @@ def n_docstring(self, node): |
541 | 541 | else: |
542 | 542 | docstring = node[0].pattr |
543 | 543 |
|
544 | | - quote = '"""' |
545 | | - if docstring.find(quote) >= 0: |
546 | | - if docstring.find("'''") == -1: |
547 | | - quote = "'''" |
548 | | - |
549 | | - self.write(indent) |
550 | | - docstring = repr(docstring.expandtabs())[1:-1] |
551 | | - |
552 | | - for orig, replace in ( |
553 | | - ("\\\\", "\t"), |
554 | | - ("\\r\\n", "\n"), |
555 | | - ("\\n", "\n"), |
556 | | - ("\\r", "\n"), |
557 | | - ('\\"', '"'), |
558 | | - ("\\'", "'"), |
559 | | - ): |
560 | | - docstring = docstring.replace(orig, replace) |
561 | | - |
562 | | - # Do a raw string if there are backslashes but no other escaped characters: |
563 | | - # also check some edge cases |
564 | | - if ( |
565 | | - "\t" in docstring |
566 | | - and "\\" not in docstring |
567 | | - and len(docstring) >= 2 |
568 | | - and docstring[-1] != "\t" |
569 | | - and (docstring[-1] != '"' or docstring[-2] == "\t") |
570 | | - ): |
571 | | - self.write("r") # raw string |
572 | | - # Restore backslashes unescaped since raw |
573 | | - docstring = docstring.replace("\t", "\\") |
574 | | - else: |
575 | | - # Escape the last character if it is the same as the |
576 | | - # triple quote character. |
577 | | - quote1 = quote[-1] |
578 | | - if len(docstring) and docstring[-1] == quote1: |
579 | | - docstring = docstring[:-1] + "\\" + quote1 |
580 | | - |
581 | | - # Escape triple quote when needed |
582 | | - if quote == '"""': |
583 | | - replace_str = '\\"""' |
584 | | - else: |
585 | | - assert quote == "'''" |
586 | | - replace_str = "\\'''" |
587 | | - |
588 | | - docstring = docstring.replace(quote, replace_str) |
589 | | - docstring = docstring.replace("\t", "\\\\") |
590 | | - |
591 | | - lines = docstring.split("\n") |
592 | | - |
593 | | - self.write(quote) |
594 | | - if len(lines) == 0: |
595 | | - self.println(quote) |
596 | | - elif len(lines) == 1: |
597 | | - self.println(lines[0], quote) |
598 | | - else: |
599 | | - self.println(lines[0]) |
600 | | - for line in lines[1:-1]: |
601 | | - if line: |
602 | | - self.println(line) |
603 | | - else: |
604 | | - self.println("\n\n") |
605 | | - pass |
606 | | - pass |
607 | | - self.println(lines[-1], quote) |
| 544 | + print_docstring(self, indent, docstring) |
608 | 545 | self.prune() |
609 | 546 |
|
610 | 547 | def n_elifelsestmtr(self, node: SyntaxTree): |
|
0 commit comments