Ticket #4405: trac_4405.patch
File trac_4405.patch, 4.8 KB (added by , 14 years ago) 


sage/misc/misc.py
# HG changeset patch # User Mike Hansen <mhansen@gmail.com> # Date 1232716044 28800 # Node ID 9e3e68c2c6f6ded61f0bee90a31a6b944e180996 # Parent 5064ee2b7c3f80447ee7bebf1db9874659938e03 Fixed #4405: double/single quotation marks in docstring diff r 5064ee2b7c3f r 9e3e68c2c6f6 sage/misc/misc.py
a b 1683 1683 # a backslash, or it is but both previous characters 1684 1684 # are backslashes. 1685 1685 if line[i1:i] != '\\' or line[i2:i] == '\\\\': 1686 if line[i] == "'": 1686 if line[i:i+3] in ['"""', "'''"]: 1687 if not in_quote(): 1688 in_triple_quote = True 1689 elif in_triple_quote: 1690 in_triple_quote = False 1691 elif line[i] == "'": 1687 1692 if not in_quote(): 1688 1693 in_single_quote = True 1689 1694 elif in_single_quote: 1690 1695 in_single_quote = False 1691 elif line[i:i+3] == '"""':1692 if not in_quote():1693 in_triple_quote = True1694 elif in_triple_quote:1695 in_triple_quote = False1696 1696 elif line[i] == '"': 1697 1697 if not in_quote(): 1698 1698 in_double_quote = True 
sage/misc/preparser.py
diff r 5064ee2b7c3f r 9e3e68c2c6f6 sage/misc/preparser.py
a b 654 654 655 655 def preparse(line, reset=True, do_time=False, ignore_prompts=False): 656 656 r""" 657 sage: preparse("ZZ.<x> = ZZ['x']") 658 "ZZ = ZZ['x']; (x,) = ZZ._first_ngens(Integer(1))" 659 sage: preparse("ZZ.<x> = ZZ['y']") 660 "ZZ = ZZ['y']; (x,) = ZZ._first_ngens(Integer(1))" 661 sage: preparse("ZZ.<x,y> = ZZ[]") 662 "ZZ = ZZ['x, y']; (x, y,) = ZZ._first_ngens(Integer(2))" 663 sage: preparse("ZZ.<x,y> = ZZ['u,v']") 664 "ZZ = ZZ['u,v']; (x, y,) = ZZ._first_ngens(Integer(2))" 665 sage: preparse("ZZ.<x> = QQ[2^(1/3)]") 666 'ZZ = QQ[Integer(2)**(Integer(1)/Integer(3))]; (x,) = ZZ._first_ngens(Integer(1))' 667 sage: QQ[2^(1/3)] 668 Number Field in a with defining polynomial x^3  2 657 EXAMPLES: 658 sage: preparse("ZZ.<x> = ZZ['x']") 659 "ZZ = ZZ['x']; (x,) = ZZ._first_ngens(Integer(1))" 660 sage: preparse("ZZ.<x> = ZZ['y']") 661 "ZZ = ZZ['y']; (x,) = ZZ._first_ngens(Integer(1))" 662 sage: preparse("ZZ.<x,y> = ZZ[]") 663 "ZZ = ZZ['x, y']; (x, y,) = ZZ._first_ngens(Integer(2))" 664 sage: preparse("ZZ.<x,y> = ZZ['u,v']") 665 "ZZ = ZZ['u,v']; (x, y,) = ZZ._first_ngens(Integer(2))" 666 sage: preparse("ZZ.<x> = QQ[2^(1/3)]") 667 'ZZ = QQ[Integer(2)**(Integer(1)/Integer(3))]; (x,) = ZZ._first_ngens(Integer(1))' 668 sage: QQ[2^(1/3)] 669 Number Field in a with defining polynomial x^3  2 669 670 670 sage: preparse("a^b") 671 'a**b' 672 sage: preparse("a^^b") 673 'a^b' 674 sage: 8^1 675 8 676 sage: 8^^1 677 9 678 sage: 9^^1 679 8 671 sage: preparse("a^b") 672 'a**b' 673 sage: preparse("a^^b") 674 'a^b' 675 sage: 8^1 676 8 677 sage: 8^^1 678 9 679 sage: 9^^1 680 8 681 682 We check to make sure that triple single quotes are handled 683 properly. See Trac ticket \#4405. In the following case, we 684 check to make sure that the single quote in the comment doesn't 685 prevent the carat from being turned into exponentiation. 686 687 sage: preparse("def foo(x):\n '''\n It's a comment.\n '''\n return x^2") 688 "def foo(x):\n '''\n It's a comment.\n '''\n return x**Integer(2)" 689 680 690 """ 681 691 try: 682 692 # [1,2,..,n] notation … … 751 761 # a backslash, or it is but both previous characters 752 762 # are backslashes. 753 763 if line[i1:i] != '\\' or line[i2:i] == '\\\\': 754 if line[i] == "'": 764 if line[i:i+3] in ['"""', "'''"]: 765 if not in_quote(): 766 in_triple_quote = True 767 i += 3 768 continue 769 elif in_triple_quote: 770 in_triple_quote = False 771 i += 3 772 continue 773 elif line[i] == "'": 755 774 if not in_quote(): 756 775 in_single_quote = True 757 776 i += 1 … … 759 778 elif in_single_quote: 760 779 in_single_quote = False 761 780 i += 1 762 continue763 elif line[i:i+3] == '"""':764 if not in_quote():765 in_triple_quote = True766 i += 3767 continue768 elif in_triple_quote:769 in_triple_quote = False770 i += 3771 781 continue 772 782 elif line[i] == '"': 773 783 if not in_quote():