[PATCH 6 of 6 py3] ui: fix configlist on Python 3

Augie Fackler raf at durin42.com
Fri Mar 3 14:30:09 EST 2017


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1488568206 18000
#      Fri Mar 03 14:10:06 2017 -0500
# Node ID bcec46d842ea6b75a899427d53a4ed585b7a7058
# Parent  168a2acc512f0dbcc9d1469ae97ea4226fc18243
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.

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -569,37 +569,38 @@ class ui(object):
 
         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 @@ class ui(object):
                 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:


More information about the Mercurial-devel mailing list