Changeset 328 for pyyaml/trunk/lib3/yaml/emitter.py
- Timestamp:
- 12/29/08 12:24:05 (4 years ago)
- Location:
- pyyaml/trunk/lib3
- Files:
-
- 1 edited
- 1 copied
-
. (copied) (copied from pyyaml/trunk/lib)
-
yaml/emitter.py (modified) (65 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/lib3/yaml/emitter.py
r313 r328 9 9 __all__ = ['Emitter', 'EmitterError'] 10 10 11 from error import YAMLError12 from events import *11 from .error import YAMLError 12 from .events import * 13 13 14 14 class EmitterError(YAMLError): 15 15 pass 16 16 17 class ScalarAnalysis (object):17 class ScalarAnalysis: 18 18 def __init__(self, scalar, empty, multiline, 19 19 allow_flow_plain, allow_block_plain, … … 29 29 self.allow_block = allow_block 30 30 31 class Emitter (object):31 class Emitter: 32 32 33 33 DEFAULT_TAG_PREFIXES = { 34 u'!' : u'!',35 u'tag:yaml.org,2002:' : u'!!',34 '!' : '!', 35 'tag:yaml.org,2002:' : '!!', 36 36 } 37 37 … … 89 89 if width and width > self.best_indent*2: 90 90 self.best_width = width 91 self.best_line_break = u'\n'92 if line_break in [ u'\r', u'\n', u'\r\n']:91 self.best_line_break = '\n' 92 if line_break in ['\r', '\n', '\r\n']: 93 93 self.best_line_break = line_break 94 94 … … 155 155 def expect_stream_start(self): 156 156 if isinstance(self.event, StreamStartEvent): 157 if self.event.encoding :157 if self.event.encoding and not hasattr(self.stream, 'encoding'): 158 158 self.encoding = self.event.encoding 159 159 self.write_stream_start() … … 174 174 if isinstance(self.event, DocumentStartEvent): 175 175 if (self.event.version or self.event.tags) and self.open_ended: 176 self.write_indicator( u'...', True)176 self.write_indicator('...', True) 177 177 self.write_indent() 178 178 if self.event.version: … … 194 194 if not implicit: 195 195 self.write_indent() 196 self.write_indicator( u'---', True)196 self.write_indicator('---', True) 197 197 if self.canonical: 198 198 self.write_indent() … … 200 200 elif isinstance(self.event, StreamEndEvent): 201 201 if self.open_ended: 202 self.write_indicator( u'...', True)202 self.write_indicator('...', True) 203 203 self.write_indent() 204 204 self.write_stream_end() … … 212 212 self.write_indent() 213 213 if self.event.explicit: 214 self.write_indicator( u'...', True)214 self.write_indicator('...', True) 215 215 self.write_indent() 216 216 self.flush_stream() … … 235 235 self.expect_alias() 236 236 elif isinstance(self.event, (ScalarEvent, CollectionStartEvent)): 237 self.process_anchor( u'&')237 self.process_anchor('&') 238 238 self.process_tag() 239 239 if isinstance(self.event, ScalarEvent): … … 257 257 if self.event.anchor is None: 258 258 raise EmitterError("anchor is not specified for alias") 259 self.process_anchor( u'*')259 self.process_anchor('*') 260 260 self.state = self.states.pop() 261 261 … … 269 269 270 270 def expect_flow_sequence(self): 271 self.write_indicator( u'[', True, whitespace=True)271 self.write_indicator('[', True, whitespace=True) 272 272 self.flow_level += 1 273 273 self.increase_indent(flow=True) … … 278 278 self.indent = self.indents.pop() 279 279 self.flow_level -= 1 280 self.write_indicator( u']', False)280 self.write_indicator(']', False) 281 281 self.state = self.states.pop() 282 282 else: … … 291 291 self.flow_level -= 1 292 292 if self.canonical: 293 self.write_indicator( u',', False)293 self.write_indicator(',', False) 294 294 self.write_indent() 295 self.write_indicator( u']', False)295 self.write_indicator(']', False) 296 296 self.state = self.states.pop() 297 297 else: 298 self.write_indicator( u',', False)298 self.write_indicator(',', False) 299 299 if self.canonical or self.column > self.best_width: 300 300 self.write_indent() … … 305 305 306 306 def expect_flow_mapping(self): 307 self.write_indicator( u'{', True, whitespace=True)307 self.write_indicator('{', True, whitespace=True) 308 308 self.flow_level += 1 309 309 self.increase_indent(flow=True) … … 314 314 self.indent = self.indents.pop() 315 315 self.flow_level -= 1 316 self.write_indicator( u'}', False)316 self.write_indicator('}', False) 317 317 self.state = self.states.pop() 318 318 else: … … 323 323 self.expect_node(mapping=True, simple_key=True) 324 324 else: 325 self.write_indicator( u'?', True)325 self.write_indicator('?', True) 326 326 self.states.append(self.expect_flow_mapping_value) 327 327 self.expect_node(mapping=True) … … 332 332 self.flow_level -= 1 333 333 if self.canonical: 334 self.write_indicator( u',', False)334 self.write_indicator(',', False) 335 335 self.write_indent() 336 self.write_indicator( u'}', False)336 self.write_indicator('}', False) 337 337 self.state = self.states.pop() 338 338 else: 339 self.write_indicator( u',', False)339 self.write_indicator(',', False) 340 340 if self.canonical or self.column > self.best_width: 341 341 self.write_indent() … … 344 344 self.expect_node(mapping=True, simple_key=True) 345 345 else: 346 self.write_indicator( u'?', True)346 self.write_indicator('?', True) 347 347 self.states.append(self.expect_flow_mapping_value) 348 348 self.expect_node(mapping=True) 349 349 350 350 def expect_flow_mapping_simple_value(self): 351 self.write_indicator( u':', False)351 self.write_indicator(':', False) 352 352 self.states.append(self.expect_flow_mapping_key) 353 353 self.expect_node(mapping=True) … … 356 356 if self.canonical or self.column > self.best_width: 357 357 self.write_indent() 358 self.write_indicator( u':', True)358 self.write_indicator(':', True) 359 359 self.states.append(self.expect_flow_mapping_key) 360 360 self.expect_node(mapping=True) … … 376 376 else: 377 377 self.write_indent() 378 self.write_indicator( u'-', True, indention=True)378 self.write_indicator('-', True, indention=True) 379 379 self.states.append(self.expect_block_sequence_item) 380 380 self.expect_node(sequence=True) … … 399 399 self.expect_node(mapping=True, simple_key=True) 400 400 else: 401 self.write_indicator( u'?', True, indention=True)401 self.write_indicator('?', True, indention=True) 402 402 self.states.append(self.expect_block_mapping_value) 403 403 self.expect_node(mapping=True) 404 404 405 405 def expect_block_mapping_simple_value(self): 406 self.write_indicator( u':', False)406 self.write_indicator(':', False) 407 407 self.states.append(self.expect_block_mapping_key) 408 408 self.expect_node(mapping=True) … … 410 410 def expect_block_mapping_value(self): 411 411 self.write_indent() 412 self.write_indicator( u':', True, indention=True)412 self.write_indicator(':', True, indention=True) 413 413 self.states.append(self.expect_block_mapping_key) 414 414 self.expect_node(mapping=True) … … 429 429 event = self.events[0] 430 430 return (isinstance(event, ScalarEvent) and event.anchor is None 431 and event.tag is None and event.implicit and event.value == u'')431 and event.tag is None and event.implicit and event.value == '') 432 432 433 433 def check_simple_key(self): … … 474 474 return 475 475 if self.event.implicit[0] and tag is None: 476 tag = u'!'476 tag = '!' 477 477 self.prepared_tag = None 478 478 else: … … 537 537 if major != 1: 538 538 raise EmitterError("unsupported YAML version: %d.%d" % (major, minor)) 539 return u'%d.%d' % (major, minor)539 return '%d.%d' % (major, minor) 540 540 541 541 def prepare_tag_handle(self, handle): 542 542 if not handle: 543 543 raise EmitterError("tag handle must not be empty") 544 if handle[0] != u'!' or handle[-1] != u'!': 545 raise EmitterError("tag handle must start and end with '!': %r" 546 % (handle.encode('utf-8'))) 544 if handle[0] != '!' or handle[-1] != '!': 545 raise EmitterError("tag handle must start and end with '!': %r" % handle) 547 546 for ch in handle[1:-1]: 548 if not ( u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \549 or ch in u'-_'):547 if not ('0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \ 548 or ch in '-_'): 550 549 raise EmitterError("invalid character %r in the tag handle: %r" 551 % (ch .encode('utf-8'), handle.encode('utf-8')))550 % (ch, handle)) 552 551 return handle 553 552 … … 557 556 chunks = [] 558 557 start = end = 0 559 if prefix[0] == u'!':558 if prefix[0] == '!': 560 559 end = 1 561 560 while end < len(prefix): 562 561 ch = prefix[end] 563 if u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z'\564 or ch in u'-;/?!:@&=+$,_.~*\'()[]':562 if '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \ 563 or ch in '-;/?!:@&=+$,_.~*\'()[]': 565 564 end += 1 566 565 else: … … 570 569 data = ch.encode('utf-8') 571 570 for ch in data: 572 chunks.append( u'%%%02X' % ord(ch))571 chunks.append('%%%02X' % ord(ch)) 573 572 if start < end: 574 573 chunks.append(prefix[start:end]) 575 return u''.join(chunks)574 return ''.join(chunks) 576 575 577 576 def prepare_tag(self, tag): 578 577 if not tag: 579 578 raise EmitterError("tag must not be empty") 580 if tag == u'!':579 if tag == '!': 581 580 return tag 582 581 handle = None … … 584 583 for prefix in self.tag_prefixes: 585 584 if tag.startswith(prefix) \ 586 and (prefix == u'!' or len(prefix) < len(tag)):585 and (prefix == '!' or len(prefix) < len(tag)): 587 586 handle = self.tag_prefixes[prefix] 588 587 suffix = tag[len(prefix):] … … 591 590 while end < len(suffix): 592 591 ch = suffix[end] 593 if u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z'\594 or ch in u'-;/?:@&=+$,_.~*\'()[]' \595 or (ch == u'!' and handle != u'!'):592 if '0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \ 593 or ch in '-;/?:@&=+$,_.~*\'()[]' \ 594 or (ch == '!' and handle != '!'): 596 595 end += 1 597 596 else: … … 601 600 data = ch.encode('utf-8') 602 601 for ch in data: 603 chunks.append( u'%%%02X' % ord(ch))602 chunks.append('%%%02X' % ord(ch)) 604 603 if start < end: 605 604 chunks.append(suffix[start:end]) 606 suffix_text = u''.join(chunks)605 suffix_text = ''.join(chunks) 607 606 if handle: 608 return u'%s%s' % (handle, suffix_text)609 else: 610 return u'!<%s>' % suffix_text607 return '%s%s' % (handle, suffix_text) 608 else: 609 return '!<%s>' % suffix_text 611 610 612 611 def prepare_anchor(self, anchor): … … 614 613 raise EmitterError("anchor must not be empty") 615 614 for ch in anchor: 616 if not ( u'0' <= ch <= u'9' or u'A' <= ch <= 'Z' or u'a' <= ch <= 'z' \617 or ch in u'-_'):615 if not ('0' <= ch <= '9' or 'A' <= ch <= 'Z' or 'a' <= ch <= 'z' \ 616 or ch in '-_'): 618 617 raise EmitterError("invalid character %r in the anchor: %r" 619 % (ch .encode('utf-8'), anchor.encode('utf-8')))618 % (ch, anchor)) 620 619 return anchor 621 620 … … 644 643 645 644 # Check document indicators. 646 if scalar.startswith( u'---') or scalar.startswith(u'...'):645 if scalar.startswith('---') or scalar.startswith('...'): 647 646 block_indicators = True 648 647 flow_indicators = True … … 653 652 # Last character or followed by a whitespace. 654 653 followed_by_whitespace = (len(scalar) == 1 or 655 scalar[1] in u'\0 \t\r\n\x85\u2028\u2029')654 scalar[1] in '\0 \t\r\n\x85\u2028\u2029') 656 655 657 656 # The previous character is a space. … … 668 667 if index == 0: 669 668 # Leading indicators are special characters. 670 if ch in u'#,[]{}&*!|>\'\"%@`':669 if ch in '#,[]{}&*!|>\'\"%@`': 671 670 flow_indicators = True 672 671 block_indicators = True 673 if ch in u'?:':672 if ch in '?:': 674 673 flow_indicators = True 675 674 if followed_by_whitespace: 676 675 block_indicators = True 677 if ch == u'-' and followed_by_whitespace:676 if ch == '-' and followed_by_whitespace: 678 677 flow_indicators = True 679 678 block_indicators = True 680 679 else: 681 680 # Some indicators cannot appear within a scalar as well. 682 if ch in u',?[]{}':681 if ch in ',?[]{}': 683 682 flow_indicators = True 684 if ch == u':':683 if ch == ':': 685 684 flow_indicators = True 686 685 if followed_by_whitespace: 687 686 block_indicators = True 688 if ch == u'#' and preceeded_by_whitespace:687 if ch == '#' and preceeded_by_whitespace: 689 688 flow_indicators = True 690 689 block_indicators = True 691 690 692 691 # Check for line breaks, special, and unicode characters. 693 if ch in u'\n\x85\u2028\u2029':692 if ch in '\n\x85\u2028\u2029': 694 693 line_breaks = True 695 if not (ch == u'\n' or u'\x20' <= ch <= u'\x7E'):696 if (ch == u'\x85' or u'\xA0' <= ch <= u'\uD7FF'697 or u'\uE000' <= ch <= u'\uFFFD') and ch != u'\uFEFF':694 if not (ch == '\n' or '\x20' <= ch <= '\x7E'): 695 if (ch == '\x85' or '\xA0' <= ch <= '\uD7FF' 696 or '\uE000' <= ch <= '\uFFFD') and ch != '\uFEFF': 698 697 unicode_characters = True 699 698 if not self.allow_unicode: … … 703 702 704 703 # Detect important whitespace combinations. 705 if ch == u' ':704 if ch == ' ': 706 705 if index == 0: 707 706 leading_space = True … … 712 711 previous_space = True 713 712 previous_break = False 714 elif ch in u'\n\x85\u2028\u2029':713 elif ch in '\n\x85\u2028\u2029': 715 714 if index == 0: 716 715 leading_break = True … … 727 726 # Prepare for the next character. 728 727 index += 1 729 preceeded_by_whitespace = (ch in u'\0 \t\r\n\x85\u2028\u2029')728 preceeded_by_whitespace = (ch in '\0 \t\r\n\x85\u2028\u2029') 730 729 followed_by_whitespace = (index+1 >= len(scalar) or 731 scalar[index+1] in u'\0 \t\r\n\x85\u2028\u2029')730 scalar[index+1] in '\0 \t\r\n\x85\u2028\u2029') 732 731 733 732 # Let's decide what styles are allowed. … … 788 787 # Write BOM if needed. 789 788 if self.encoding and self.encoding.startswith('utf-16'): 790 self.stream.write( u'\xFF\xFE'.encode(self.encoding))789 self.stream.write('\xFF\xFE'.encode(self.encoding)) 791 790 792 791 def write_stream_end(self): … … 798 797 data = indicator 799 798 else: 800 data = u' '+indicator799 data = ' '+indicator 801 800 self.whitespace = whitespace 802 801 self.indention = self.indention and indention … … 814 813 if self.column < indent: 815 814 self.whitespace = True 816 data = u' '*(indent-self.column)815 data = ' '*(indent-self.column) 817 816 self.column = indent 818 817 if self.encoding: … … 832 831 833 832 def write_version_directive(self, version_text): 834 data = u'%%YAML %s' % version_text833 data = '%%YAML %s' % version_text 835 834 if self.encoding: 836 835 data = data.encode(self.encoding) … … 839 838 840 839 def write_tag_directive(self, handle_text, prefix_text): 841 data = u'%%TAG %s %s' % (handle_text, prefix_text)840 data = '%%TAG %s %s' % (handle_text, prefix_text) 842 841 if self.encoding: 843 842 data = data.encode(self.encoding) … … 848 847 849 848 def write_single_quoted(self, text, split=True): 850 self.write_indicator( u'\'', True)849 self.write_indicator('\'', True) 851 850 spaces = False 852 851 breaks = False … … 857 856 ch = text[end] 858 857 if spaces: 859 if ch is None or ch != u' ':858 if ch is None or ch != ' ': 860 859 if start+1 == end and self.column > self.best_width and split \ 861 860 and start != 0 and end != len(text): … … 869 868 start = end 870 869 elif breaks: 871 if ch is None or ch not in u'\n\x85\u2028\u2029':872 if text[start] == u'\n':870 if ch is None or ch not in '\n\x85\u2028\u2029': 871 if text[start] == '\n': 873 872 self.write_line_break() 874 873 for br in text[start:end]: 875 if br == u'\n':874 if br == '\n': 876 875 self.write_line_break() 877 876 else: … … 880 879 start = end 881 880 else: 882 if ch is None or ch in u' \n\x85\u2028\u2029' or ch == u'\'':881 if ch is None or ch in ' \n\x85\u2028\u2029' or ch == '\'': 883 882 if start < end: 884 883 data = text[start:end] … … 888 887 self.stream.write(data) 889 888 start = end 890 if ch == u'\'':891 data = u'\'\''889 if ch == '\'': 890 data = '\'\'' 892 891 self.column += 2 893 892 if self.encoding: … … 896 895 start = end + 1 897 896 if ch is not None: 898 spaces = (ch == u' ')899 breaks = (ch in u'\n\x85\u2028\u2029')897 spaces = (ch == ' ') 898 breaks = (ch in '\n\x85\u2028\u2029') 900 899 end += 1 901 self.write_indicator( u'\'', False)900 self.write_indicator('\'', False) 902 901 903 902 ESCAPE_REPLACEMENTS = { 904 u'\0': u'0',905 u'\x07': u'a',906 u'\x08': u'b',907 u'\x09': u't',908 u'\x0A': u'n',909 u'\x0B': u'v',910 u'\x0C': u'f',911 u'\x0D': u'r',912 u'\x1B': u'e',913 u'\"': u'\"',914 u'\\': u'\\',915 u'\x85': u'N',916 u'\xA0': u'_',917 u'\u2028': u'L',918 u'\u2029': u'P',903 '\0': '0', 904 '\x07': 'a', 905 '\x08': 'b', 906 '\x09': 't', 907 '\x0A': 'n', 908 '\x0B': 'v', 909 '\x0C': 'f', 910 '\x0D': 'r', 911 '\x1B': 'e', 912 '\"': '\"', 913 '\\': '\\', 914 '\x85': 'N', 915 '\xA0': '_', 916 '\u2028': 'L', 917 '\u2029': 'P', 919 918 } 920 919 921 920 def write_double_quoted(self, text, split=True): 922 self.write_indicator( u'"', True)921 self.write_indicator('"', True) 923 922 start = end = 0 924 923 while end <= len(text): … … 926 925 if end < len(text): 927 926 ch = text[end] 928 if ch is None or ch in u'"\\\x85\u2028\u2029\uFEFF' \929 or not ( u'\x20' <= ch <= u'\x7E'927 if ch is None or ch in '"\\\x85\u2028\u2029\uFEFF' \ 928 or not ('\x20' <= ch <= '\x7E' 930 929 or (self.allow_unicode 931 and ( u'\xA0' <= ch <= u'\uD7FF'932 or u'\uE000' <= ch <= u'\uFFFD'))):930 and ('\xA0' <= ch <= '\uD7FF' 931 or '\uE000' <= ch <= '\uFFFD'))): 933 932 if start < end: 934 933 data = text[start:end] … … 940 939 if ch is not None: 941 940 if ch in self.ESCAPE_REPLACEMENTS: 942 data = u'\\'+self.ESCAPE_REPLACEMENTS[ch]943 elif ch <= u'\xFF':944 data = u'\\x%02X' % ord(ch)945 elif ch <= u'\uFFFF':946 data = u'\\u%04X' % ord(ch)941 data = '\\'+self.ESCAPE_REPLACEMENTS[ch] 942 elif ch <= '\xFF': 943 data = '\\x%02X' % ord(ch) 944 elif ch <= '\uFFFF': 945 data = '\\u%04X' % ord(ch) 947 946 else: 948 data = u'\\U%08X' % ord(ch)947 data = '\\U%08X' % ord(ch) 949 948 self.column += len(data) 950 949 if self.encoding: … … 952 951 self.stream.write(data) 953 952 start = end+1 954 if 0 < end < len(text)-1 and (ch == u' ' or start >= end)\953 if 0 < end < len(text)-1 and (ch == ' ' or start >= end) \ 955 954 and self.column+(end-start) > self.best_width and split: 956 data = text[start:end]+ u'\\'955 data = text[start:end]+'\\' 957 956 if start < end: 958 957 start = end … … 964 963 self.whitespace = False 965 964 self.indention = False 966 if text[start] == u' ':967 data = u'\\'965 if text[start] == ' ': 966 data = '\\' 968 967 self.column += len(data) 969 968 if self.encoding: … … 971 970 self.stream.write(data) 972 971 end += 1 973 self.write_indicator( u'"', False)972 self.write_indicator('"', False) 974 973 975 974 def determine_block_hints(self, text): 976 hints = u''975 hints = '' 977 976 if text: 978 if text[0] in u' \n\x85\u2028\u2029':979 hints += unicode(self.best_indent)980 if text[-1] not in u'\n\x85\u2028\u2029':981 hints += u'-'982 elif len(text) == 1 or text[-2] in u'\n\x85\u2028\u2029':983 hints += u'+'977 if text[0] in ' \n\x85\u2028\u2029': 978 hints += str(self.best_indent) 979 if text[-1] not in '\n\x85\u2028\u2029': 980 hints += '-' 981 elif len(text) == 1 or text[-2] in '\n\x85\u2028\u2029': 982 hints += '+' 984 983 return hints 985 984 986 985 def write_folded(self, text): 987 986 hints = self.determine_block_hints(text) 988 self.write_indicator( u'>'+hints, True)989 if hints[-1:] == u'+':987 self.write_indicator('>'+hints, True) 988 if hints[-1:] == '+': 990 989 self.open_ended = True 991 990 self.write_line_break() … … 999 998 ch = text[end] 1000 999 if breaks: 1001 if ch is None or ch not in u'\n\x85\u2028\u2029':1002 if not leading_space and ch is not None and ch != u' '\1003 and text[start] == u'\n':1000 if ch is None or ch not in '\n\x85\u2028\u2029': 1001 if not leading_space and ch is not None and ch != ' ' \ 1002 and text[start] == '\n': 1004 1003 self.write_line_break() 1005 leading_space = (ch == u' ')1004 leading_space = (ch == ' ') 1006 1005 for br in text[start:end]: 1007 if br == u'\n':1006 if br == '\n': 1008 1007 self.write_line_break() 1009 1008 else: … … 1013 1012 start = end 1014 1013 elif spaces: 1015 if ch != u' ':1014 if ch != ' ': 1016 1015 if start+1 == end and self.column > self.best_width: 1017 1016 self.write_indent() … … 1024 1023 start = end 1025 1024 else: 1026 if ch is None or ch in u' \n\x85\u2028\u2029':1025 if ch is None or ch in ' \n\x85\u2028\u2029': 1027 1026 data = text[start:end] 1028 1027 if self.encoding: … … 1033 1032 start = end 1034 1033 if ch is not None: 1035 breaks = (ch in u'\n\x85\u2028\u2029')1036 spaces = (ch == u' ')1034 breaks = (ch in '\n\x85\u2028\u2029') 1035 spaces = (ch == ' ') 1037 1036 end += 1 1038 1037 1039 1038 def write_literal(self, text): 1040 1039 hints = self.determine_block_hints(text) 1041 self.write_indicator( u'|'+hints, True)1042 if hints[-1:] == u'+':1040 self.write_indicator('|'+hints, True) 1041 if hints[-1:] == '+': 1043 1042 self.open_ended = True 1044 1043 self.write_line_break() … … 1050 1049 ch = text[end] 1051 1050 if breaks: 1052 if ch is None or ch not in u'\n\x85\u2028\u2029':1051 if ch is None or ch not in '\n\x85\u2028\u2029': 1053 1052 for br in text[start:end]: 1054 if br == u'\n':1053 if br == '\n': 1055 1054 self.write_line_break() 1056 1055 else: … … 1060 1059 start = end 1061 1060 else: 1062 if ch is None or ch in u'\n\x85\u2028\u2029':1061 if ch is None or ch in '\n\x85\u2028\u2029': 1063 1062 data = text[start:end] 1064 1063 if self.encoding: … … 1069 1068 start = end 1070 1069 if ch is not None: 1071 breaks = (ch in u'\n\x85\u2028\u2029')1070 breaks = (ch in '\n\x85\u2028\u2029') 1072 1071 end += 1 1073 1072 … … 1078 1077 return 1079 1078 if not self.whitespace: 1080 data = u' '1079 data = ' ' 1081 1080 self.column += len(data) 1082 1081 if self.encoding: … … 1093 1092 ch = text[end] 1094 1093 if spaces: 1095 if ch != u' ':1094 if ch != ' ': 1096 1095 if start+1 == end and self.column > self.best_width and split: 1097 1096 self.write_indent() … … 1106 1105 start = end 1107 1106 elif breaks: 1108 if ch not in u'\n\x85\u2028\u2029':1109 if text[start] == u'\n':1107 if ch not in '\n\x85\u2028\u2029': 1108 if text[start] == '\n': 1110 1109 self.write_line_break() 1111 1110 for br in text[start:end]: 1112 if br == u'\n':1111 if br == '\n': 1113 1112 self.write_line_break() 1114 1113 else: … … 1119 1118 start = end 1120 1119 else: 1121 if ch is None or ch in u' \n\x85\u2028\u2029':1120 if ch is None or ch in ' \n\x85\u2028\u2029': 1122 1121 data = text[start:end] 1123 1122 self.column += len(data) … … 1127 1126 start = end 1128 1127 if ch is not None: 1129 spaces = (ch == u' ')1130 breaks = (ch in u'\n\x85\u2028\u2029')1128 spaces = (ch == ' ') 1129 breaks = (ch in '\n\x85\u2028\u2029') 1131 1130 end += 1 1132 1131
Note: See TracChangeset
for help on using the changeset viewer.
