Patchwork [07,of,10,py3] revsetlang: slice out single bytes instead of indexing

login
register
mail settings
Submitter Augie Fackler
Date March 12, 2017, 6:57 p.m.
Message ID <7f013bdcdbddcc8ed86d.1489345067@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/19205/
State Accepted
Headers show

Comments

Augie Fackler - March 12, 2017, 6:57 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1489297619 18000
#      Sun Mar 12 00:46:59 2017 -0500
# Node ID 7f013bdcdbddcc8ed86dcb373e88f6956bcbdd51
# Parent  30c4b444e0beaea64ab35b594bb976bafba9aa34
revsetlang: slice out single bytes instead of indexing

For portability with Python 3.

Patch

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -96,7 +96,7 @@  def tokenize(program, lookup=None, symin
 
     pos, l = 0, len(program)
     while pos < l:
-        c = program[pos]
+        c = program[pos:pos + 1]
         if c.isspace(): # skip inter-token whitespace
             pass
         elif c == ':' and program[pos:pos + 2] == '::': # look ahead carefully
@@ -114,14 +114,14 @@  def tokenize(program, lookup=None, symin
               program[pos:pos + 2] in ("r'", 'r"')): # handle quoted strings
             if c == 'r':
                 pos += 1
-                c = program[pos]
+                c = program[pos:pos + 1]
                 decode = lambda x: x
             else:
                 decode = parser.unescapestr
             pos += 1
             s = pos
             while pos < l: # find closing quote
-                d = program[pos]
+                d = program[pos:pos + 1]
                 if d == '\\': # skip over escaped characters
                     pos += 2
                     continue
@@ -136,10 +136,11 @@  def tokenize(program, lookup=None, symin
             s = pos
             pos += 1
             while pos < l: # find end of symbol
-                d = program[pos]
+                d = program[pos:pos + 1]
                 if d not in symletters:
                     break
-                if d == '.' and program[pos - 1] == '.': # special case for ..
+                if (d == '.'
+                    and program[pos - 1:pos] == '.'): # special case for ..
                     pos -= 1
                     break
                 pos += 1