Patchwork [6,of,7] py3: slice over bytes to prevent getting ascii values

login
register
mail settings
Submitter Pulkit Goyal
Date May 3, 2017, 9:59 a.m.
Message ID <07bd56e106d472c526d9.1493805565@pulkit-goyal>
Download mbox | patch
Permalink /patch/20401/
State Accepted
Headers show

Comments

Pulkit Goyal - May 3, 2017, 9:59 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1493320932 -19800
#      Fri Apr 28 00:52:12 2017 +0530
# Node ID 07bd56e106d472c526d99caf3154c2d2727f8d79
# Parent  4b5015610049afd91ae99357657a6fad7c234547
py3: slice over bytes to prevent getting ascii values
Yuya Nishihara - May 4, 2017, 2:16 a.m.
On Wed, 03 May 2017 15:29:25 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1493320932 -19800
> #      Fri Apr 28 00:52:12 2017 +0530
> # Node ID 07bd56e106d472c526d99caf3154c2d2727f8d79
> # Parent  4b5015610049afd91ae99357657a6fad7c234547
> py3: slice over bytes to prevent getting ascii values

Can you check if bytestr is usable?

> diff -r 4b5015610049 -r 07bd56e106d4 mercurial/changelog.py
> --- a/mercurial/changelog.py	Fri Apr 21 00:53:38 2017 +0530
> +++ b/mercurial/changelog.py	Fri Apr 28 00:52:12 2017 +0530
> @@ -190,7 +190,7 @@
>  
>          # The list of files may be empty. Which means nl3 is the first of the
>          # double newline that precedes the description.
> -        if text[nl3 + 1] == '\n':
> +        if text[nl3 + 1:nl3 + 2] == '\n':

I think this is simple enough to not use bytestr helper.

> --- a/mercurial/templater.py	Fri Apr 21 00:53:38 2017 +0530
> +++ b/mercurial/templater.py	Fri Apr 28 00:52:12 2017 +0530
> @@ -54,7 +54,7 @@
>      with term if specified"""
>      pos = start
>      while pos < end:
> -        c = program[pos]
> +        c = program[pos:pos + 1]

but here we have too many [x:x + 1] so we should use bytestr instead.

Patch

diff -r 4b5015610049 -r 07bd56e106d4 mercurial/changelog.py
--- a/mercurial/changelog.py	Fri Apr 21 00:53:38 2017 +0530
+++ b/mercurial/changelog.py	Fri Apr 28 00:52:12 2017 +0530
@@ -190,7 +190,7 @@ 
 
         # The list of files may be empty. Which means nl3 is the first of the
         # double newline that precedes the description.
-        if text[nl3 + 1] == '\n':
+        if text[nl3 + 1:nl3 + 2] == '\n':
             doublenl = nl3
         else:
             doublenl = text.index('\n\n', nl3 + 1)
diff -r 4b5015610049 -r 07bd56e106d4 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Fri Apr 21 00:53:38 2017 +0530
+++ b/mercurial/cmdutil.py	Fri Apr 28 00:52:12 2017 +0530
@@ -490,10 +490,10 @@ 
         patlen = len(pat)
         i = 0
         while i < patlen:
-            c = pat[i]
+            c = pat[i:i + 1]
             if c == '%':
                 i += 1
-                c = pat[i]
+                c = pat[i:i + 1]
                 c = expander[c]()
             newname.append(c)
             i += 1
diff -r 4b5015610049 -r 07bd56e106d4 mercurial/templater.py
--- a/mercurial/templater.py	Fri Apr 21 00:53:38 2017 +0530
+++ b/mercurial/templater.py	Fri Apr 28 00:52:12 2017 +0530
@@ -54,7 +54,7 @@ 
     with term if specified"""
     pos = start
     while pos < end:
-        c = program[pos]
+        c = program[pos:pos + 1]
         if c.isspace(): # skip inter-token whitespace
             pass
         elif c in "(=,)%|+-*/": # handle simple operators
@@ -69,7 +69,7 @@ 
             c = program[pos + 1]
             s = pos = pos + 2
             while pos < end: # find closing quote
-                d = program[pos]
+                d = program[pos:pos + 1]
                 if d == '\\': # skip over escaped characters
                     pos += 2
                     continue
@@ -82,7 +82,7 @@ 
         elif c.isdigit():
             s = pos
             while pos < end:
-                d = program[pos]
+                d = program[pos:pos + 1]
                 if not d.isdigit():
                     break
                 pos += 1
@@ -126,7 +126,7 @@ 
             s = pos
             pos += 1
             while pos < end: # find end of symbol
-                d = program[pos]
+                d = program[pos:pos + 1]
                 if not (d.isalnum() or d == "_"):
                     break
                 pos += 1
diff -r 4b5015610049 -r 07bd56e106d4 mercurial/util.py
--- a/mercurial/util.py	Fri Apr 21 00:53:38 2017 +0530
+++ b/mercurial/util.py	Fri Apr 28 00:52:12 2017 +0530
@@ -1917,7 +1917,7 @@ 
         found = [True for p in part if ("%"+p) in format]
         if not found:
             date += "@" + defaults[part][usenow]
-            format += "@%" + part[0]
+            format += "@%" + part[0:1]
         else:
             # We've found a specific time element, less specific time
             # elements are relative to today
@@ -1981,13 +1981,13 @@ 
             # this piece is for rounding the specific end of unknowns
             b = bias.get(part)
             if b is None:
-                if part[0] in "HMS":
+                if part[0:1] in "HMS":
                     b = "00"
                 else:
                     b = "0"
 
             # this piece is for matching the generic end to today's date
-            n = datestr(now, "%" + part[0])
+            n = datestr(now, "%" + part[0:1])
 
             defaults[part] = (b, n)
 
@@ -2058,17 +2058,17 @@ 
 
     if not date:
         raise Abort(_("dates cannot consist entirely of whitespace"))
-    elif date[0] == "<":
+    elif date[0:1] == "<":
         if not date[1:]:
             raise Abort(_("invalid day spec, use '<DATE'"))
         when = upper(date[1:])
         return lambda x: x <= when
-    elif date[0] == ">":
+    elif date[0:1] == ">":
         if not date[1:]:
             raise Abort(_("invalid day spec, use '>DATE'"))
         when = lower(date[1:])
         return lambda x: x >= when
-    elif date[0] == "-":
+    elif date[0:1] == "-":
         try:
             days = int(date[1:])
         except ValueError: