Changeset 308
- Timestamp:
- 12/27/08 06:07:47 (4 years ago)
- Location:
- pyyaml/trunk
- Files:
-
- 2 edited
-
lib/yaml/emitter.py (modified) (7 diffs)
-
setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/lib/yaml/emitter.py
r307 r308 626 626 special_characters = False 627 627 628 # Whitespaces. 629 inline_spaces = False # non-space space+ non-space 630 inline_breaks = False # non-space break+ non-space 631 leading_spaces = False # ^ space+ (non-space | $) 632 leading_breaks = False # ^ break+ (non-space | $) 633 trailing_spaces = False # (^ | non-space) space+ $ 634 trailing_breaks = False # (^ | non-space) break+ $ 635 inline_breaks_spaces = False # non-space break+ space+ non-space 636 mixed_breaks_spaces = False # anything else 628 # Important whitespace combinations. 629 leading_space = False 630 leading_break = False 631 trailing_space = False 632 trailing_break = False 633 break_space = False 634 space_break = False 637 635 638 636 # Check document indicators. … … 642 640 643 641 # First character or preceded by a whitespace. 644 preceeded_by_ space = True642 preceeded_by_whitespace = True 645 643 646 644 # Last character or followed by a whitespace. 647 followed_by_ space = (len(scalar) == 1 or645 followed_by_whitespace = (len(scalar) == 1 or 648 646 scalar[1] in u'\0 \t\r\n\x85\u2028\u2029') 649 647 650 # The current series of whitespaces contain plain spaces. 651 spaces = False 652 653 # The current series of whitespaces contain line breaks. 654 breaks = False 655 656 # The current series of whitespaces contain a space followed by a 657 # break. 658 mixed = False 659 660 # The current series of whitespaces start at the beginning of the 661 # scalar. 662 leading = False 648 # The previous character is a space. 649 previous_space = False 650 651 # The previous character is a break. 652 previous_break = False 663 653 664 654 index = 0 … … 667 657 668 658 # Check for indicators. 669 670 659 if index == 0: 671 660 # Leading indicators are special characters. … … 675 664 if ch in u'?:': 676 665 flow_indicators = True 677 if followed_by_ space:666 if followed_by_whitespace: 678 667 block_indicators = True 679 if ch == u'-' and followed_by_ space:668 if ch == u'-' and followed_by_whitespace: 680 669 flow_indicators = True 681 670 block_indicators = True … … 686 675 if ch == u':': 687 676 flow_indicators = True 688 if followed_by_ space:677 if followed_by_whitespace: 689 678 block_indicators = True 690 if ch == u'#' and preceeded_by_ space:679 if ch == u'#' and preceeded_by_whitespace: 691 680 flow_indicators = True 692 681 block_indicators = True 693 682 694 683 # Check for line breaks, special, and unicode characters. 695 696 684 if ch in u'\n\x85\u2028\u2029': 697 685 line_breaks = True … … 705 693 special_characters = True 706 694 707 # Spaces, line breaks, and how they are mixed. State machine. 708 709 # Start or continue series of whitespaces. 710 if ch in u' \n\x85\u2028\u2029': 711 if spaces and breaks: 712 if ch != u' ': # break+ (space+ break+) => mixed 713 mixed = True 714 elif spaces: 715 if ch != u' ': # (space+ break+) => mixed 716 breaks = True 717 mixed = True 718 elif breaks: 719 if ch == u' ': # break+ space+ 720 spaces = True 721 else: 722 leading = (index == 0) 723 if ch == u' ': # space+ 724 spaces = True 725 else: # break+ 726 breaks = True 727 728 # Series of whitespaces ended with a non-space. 729 elif spaces or breaks: 730 if leading: 731 if spaces and breaks: 732 mixed_breaks_spaces = True 733 elif spaces: 734 leading_spaces = True 735 elif breaks: 736 leading_breaks = True 737 else: 738 if mixed: 739 mixed_breaks_spaces = True 740 elif spaces and breaks: 741 inline_breaks_spaces = True 742 elif spaces: 743 inline_spaces = True 744 elif breaks: 745 inline_breaks = True 746 spaces = breaks = mixed = leading = False 747 748 # Series of whitespaces reach the end. 749 if (spaces or breaks) and (index == len(scalar)-1): 750 if spaces and breaks: 751 mixed_breaks_spaces = True 752 elif spaces: 753 trailing_spaces = True 754 if leading: 755 leading_spaces = True 756 elif breaks: 757 trailing_breaks = True 758 if leading: 759 leading_breaks = True 760 spaces = breaks = mixed = leading = False 695 # Detect important whitespace combinations. 696 if ch == u' ': 697 if index == 0: 698 leading_space = True 699 if index == len(scalar)-1: 700 trailing_space = True 701 if previous_break: 702 break_space = True 703 previous_space = True 704 previous_break = False 705 elif ch in u'\n\x85\u2028\u2029': 706 if index == 0: 707 leading_break = True 708 if index == len(scalar)-1: 709 trailing_break = True 710 if previous_space: 711 space_break = True 712 previous_space = False 713 previous_break = True 714 else: 715 previous_space = False 716 previous_break = False 761 717 762 718 # Prepare for the next character. 763 719 index += 1 764 preceeded_by_ space = (ch in u'\0 \t\r\n\x85\u2028\u2029')765 followed_by_ space = (index+1 >= len(scalar) or720 preceeded_by_whitespace = (ch in u'\0 \t\r\n\x85\u2028\u2029') 721 followed_by_whitespace = (index+1 >= len(scalar) or 766 722 scalar[index+1] in u'\0 \t\r\n\x85\u2028\u2029') 767 723 … … 774 730 775 731 # Leading and trailing whitespaces are bad for plain scalars. 776 if (leading_space s or leading_breaks777 or trailing_space s or trailing_breaks):732 if (leading_space or leading_break 733 or trailing_space or trailing_break): 778 734 allow_flow_plain = allow_block_plain = False 779 735 780 736 # We do not permit trailing spaces for block scalars. 781 if trailing_space s:737 if trailing_space: 782 738 allow_block = False 783 739 784 740 # Spaces at the beginning of a new line are only acceptable for block 785 741 # scalars. 786 if inline_breaks_spaces:742 if break_space: 787 743 allow_flow_plain = allow_block_plain = allow_single_quoted = False 788 744 789 # Mixed spaces andbreaks, as well as special character are only745 # Spaces followed by breaks, as well as special character are only 790 746 # allowed for double quoted scalars. 791 if mixed_breaks_spacesor special_characters:747 if space_break or special_characters: 792 748 allow_flow_plain = allow_block_plain = \ 793 749 allow_single_quoted = allow_block = False 794 750 795 # We don't emit multiline plain scalars. 751 # Although the plain scalar writer supports breaks, we never emit 752 # multiline plain scalars. 796 753 if line_breaks: 797 754 allow_flow_plain = allow_block_plain = False -
pyyaml/trunk/setup.py
r306 r308 81 81 except ImportError: 82 82 with_pyrex = False 83 84 83 85 84
Note: See TracChangeset
for help on using the changeset viewer.
