changeset 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 8266802f0fa4
children accdd5e62066
files mercurial/ui.py
diffstat 1 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Fri Mar 03 12:55:49 2017 -0500
+++ b/mercurial/ui.py	Fri Mar 03 14:10:06 2017 -0500
@@ -569,37 +569,38 @@
 
         def _parse_plain(parts, s, offset):
             whitespace = False
-            while offset < len(s) and (s[offset].isspace() or s[offset] == ','):
+            while offset < len(s) and (s[offset:offset + 1].isspace()
+                                       or s[offset:offset + 1] == ','):
                 whitespace = True
                 offset += 1
             if offset >= len(s):
                 return None, parts, offset
             if whitespace:
                 parts.append('')
-            if s[offset] == '"' and not parts[-1]:
+            if s[offset:offset + 1] == '"' and not parts[-1]:
                 return _parse_quote, parts, offset + 1
-            elif s[offset] == '"' and parts[-1][-1] == '\\':
-                parts[-1] = parts[-1][:-1] + s[offset]
+            elif s[offset:offset + 1] == '"' and parts[-1][-1] == '\\':
+                parts[-1] = parts[-1][:-1] + s[offset:offset + 1]
                 return _parse_plain, parts, offset + 1
-            parts[-1] += s[offset]
+            parts[-1] += s[offset:offset + 1]
             return _parse_plain, parts, offset + 1
 
         def _parse_quote(parts, s, offset):
-            if offset < len(s) and s[offset] == '"': # ""
+            if offset < len(s) and s[offset:offset + 1] == '"': # ""
                 parts.append('')
                 offset += 1
-                while offset < len(s) and (s[offset].isspace() or
-                        s[offset] == ','):
+                while offset < len(s) and (s[offset:offset + 1].isspace() or
+                        s[offset:offset + 1] == ','):
                     offset += 1
                 return _parse_plain, parts, offset
 
-            while offset < len(s) and s[offset] != '"':
-                if (s[offset] == '\\' and offset + 1 < len(s)
-                        and s[offset + 1] == '"'):
+            while offset < len(s) and s[offset:offset + 1] != '"':
+                if (s[offset:offset + 1] == '\\' and offset + 1 < len(s)
+                        and s[offset + 1:offset + 2] == '"'):
                     offset += 1
                     parts[-1] += '"'
                 else:
-                    parts[-1] += s[offset]
+                    parts[-1] += s[offset:offset + 1]
                 offset += 1
 
             if offset >= len(s):
@@ -613,11 +614,11 @@
                 return None, parts, offset
 
             offset += 1
-            while offset < len(s) and s[offset] in [' ', ',']:
+            while offset < len(s) and s[offset:offset + 1] in [' ', ',']:
                 offset += 1
 
             if offset < len(s):
-                if offset + 1 == len(s) and s[offset] == '"':
+                if offset + 1 == len(s) and s[offset:offset + 1] == '"':
                     parts[-1] += '"'
                     offset += 1
                 else: