Changeset 299


Ignore:
Timestamp:
11/30/08 05:20:49 (6 years ago)
Author:
xi
Message:

Permit emitting block scalars with leading spaces or breaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/emitter.py

    r222 r299  
    775775        allow_block = True 
    776776 
    777         # Leading and trailing whitespace are bad for plain scalars. We also 
    778         # do not want to mess with leading whitespaces for block scalars. 
    779         if leading_spaces or leading_breaks or trailing_spaces: 
    780             allow_flow_plain = allow_block_plain = allow_block = False 
    781  
    782         # Trailing breaks are fine for block scalars, but unacceptable for 
    783         # plain scalars. 
    784         if trailing_breaks: 
     777        # Leading and trailing whitespaces are bad for plain scalars. 
     778        if (leading_spaces or leading_breaks 
     779                or trailing_spaces or trailing_breaks): 
    785780            allow_flow_plain = allow_block_plain = False 
    786781 
    787         # The combination of (space+ break+) is only acceptable for block 
     782        # We do not permit trailing spaces for block scalars. 
     783        if trailing_spaces: 
     784            allow_block = False 
     785 
     786        # Spaces at the beginning of a new line are only acceptable for block 
    788787        # scalars. 
    789788        if inline_breaks_spaces: 
     
    10101009 
    10111010    def determine_chomp(self, text): 
     1011        hints = u'' 
     1012        if text and text[0] in u' \n\x85\u2028\u2029': 
     1013            hints += unicode(self.best_indent) 
    10121014        tail = text[-2:] 
    10131015        while len(tail) < 2: 
     
    10151017        if tail[-1] in u'\n\x85\u2028\u2029': 
    10161018            if tail[-2] in u'\n\x85\u2028\u2029': 
    1017                 return u'+' 
    1018             else: 
    1019                 return u'' 
    1020         else: 
    1021             return u'-' 
     1019                hints += u'+' 
     1020        else: 
     1021            hints += u'-' 
     1022        return hints 
    10221023 
    10231024    def write_folded(self, text): 
    1024         chomp = self.determine_chomp(text) 
    1025         self.write_indicator(u'>'+chomp, True) 
     1025        hints = self.determine_block_hints(text) 
     1026        self.write_indicator(u'>'+hints, True) 
    10261027        self.write_indent() 
    10271028        leading_space = False 
Note: See TracChangeset for help on using the changeset viewer.