Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 31156:e5aab82edf7f
ui: fix configlist on Python 3
Since we're working on bytestrings, we have to use [offset:offset+1]
to get consistent behavior on Python 2 and 3. I've only tested the
_parse_plain closure, not the _parse_quote one, but I have no real
reason to expect the latter to be broken since the fixes were fairly
mechanical.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 03 Mar 2017 14:10:06 -0500 |
parents | 0bb3089fe735 |
children | a7cabac20b62 |
comparison
equal
deleted
inserted
replaced
31155:8266802f0fa4 | 31156:e5aab82edf7f |
---|---|
567 ['this', 'is', 'a small', 'test'] | 567 ['this', 'is', 'a small', 'test'] |
568 """ | 568 """ |
569 | 569 |
570 def _parse_plain(parts, s, offset): | 570 def _parse_plain(parts, s, offset): |
571 whitespace = False | 571 whitespace = False |
572 while offset < len(s) and (s[offset].isspace() or s[offset] == ','): | 572 while offset < len(s) and (s[offset:offset + 1].isspace() |
573 or s[offset:offset + 1] == ','): | |
573 whitespace = True | 574 whitespace = True |
574 offset += 1 | 575 offset += 1 |
575 if offset >= len(s): | 576 if offset >= len(s): |
576 return None, parts, offset | 577 return None, parts, offset |
577 if whitespace: | 578 if whitespace: |
578 parts.append('') | 579 parts.append('') |
579 if s[offset] == '"' and not parts[-1]: | 580 if s[offset:offset + 1] == '"' and not parts[-1]: |
580 return _parse_quote, parts, offset + 1 | 581 return _parse_quote, parts, offset + 1 |
581 elif s[offset] == '"' and parts[-1][-1] == '\\': | 582 elif s[offset:offset + 1] == '"' and parts[-1][-1] == '\\': |
582 parts[-1] = parts[-1][:-1] + s[offset] | 583 parts[-1] = parts[-1][:-1] + s[offset:offset + 1] |
583 return _parse_plain, parts, offset + 1 | 584 return _parse_plain, parts, offset + 1 |
584 parts[-1] += s[offset] | 585 parts[-1] += s[offset:offset + 1] |
585 return _parse_plain, parts, offset + 1 | 586 return _parse_plain, parts, offset + 1 |
586 | 587 |
587 def _parse_quote(parts, s, offset): | 588 def _parse_quote(parts, s, offset): |
588 if offset < len(s) and s[offset] == '"': # "" | 589 if offset < len(s) and s[offset:offset + 1] == '"': # "" |
589 parts.append('') | 590 parts.append('') |
590 offset += 1 | 591 offset += 1 |
591 while offset < len(s) and (s[offset].isspace() or | 592 while offset < len(s) and (s[offset:offset + 1].isspace() or |
592 s[offset] == ','): | 593 s[offset:offset + 1] == ','): |
593 offset += 1 | 594 offset += 1 |
594 return _parse_plain, parts, offset | 595 return _parse_plain, parts, offset |
595 | 596 |
596 while offset < len(s) and s[offset] != '"': | 597 while offset < len(s) and s[offset:offset + 1] != '"': |
597 if (s[offset] == '\\' and offset + 1 < len(s) | 598 if (s[offset:offset + 1] == '\\' and offset + 1 < len(s) |
598 and s[offset + 1] == '"'): | 599 and s[offset + 1:offset + 2] == '"'): |
599 offset += 1 | 600 offset += 1 |
600 parts[-1] += '"' | 601 parts[-1] += '"' |
601 else: | 602 else: |
602 parts[-1] += s[offset] | 603 parts[-1] += s[offset:offset + 1] |
603 offset += 1 | 604 offset += 1 |
604 | 605 |
605 if offset >= len(s): | 606 if offset >= len(s): |
606 real_parts = _configlist(parts[-1]) | 607 real_parts = _configlist(parts[-1]) |
607 if not real_parts: | 608 if not real_parts: |
611 parts = parts[:-1] | 612 parts = parts[:-1] |
612 parts.extend(real_parts) | 613 parts.extend(real_parts) |
613 return None, parts, offset | 614 return None, parts, offset |
614 | 615 |
615 offset += 1 | 616 offset += 1 |
616 while offset < len(s) and s[offset] in [' ', ',']: | 617 while offset < len(s) and s[offset:offset + 1] in [' ', ',']: |
617 offset += 1 | 618 offset += 1 |
618 | 619 |
619 if offset < len(s): | 620 if offset < len(s): |
620 if offset + 1 == len(s) and s[offset] == '"': | 621 if offset + 1 == len(s) and s[offset:offset + 1] == '"': |
621 parts[-1] += '"' | 622 parts[-1] += '"' |
622 offset += 1 | 623 offset += 1 |
623 else: | 624 else: |
624 parts.append('') | 625 parts.append('') |
625 else: | 626 else: |