Patchwork [2,of,5,stable] py3: fix bytes iteration

login
register
mail settings
Submitter Manuel Jacob
Date June 16, 2020, 1:50 a.m.
Message ID <343142bb73bafe1ad2a2.1592272227@tmp>
Download mbox | patch
Permalink /patch/46512/
State Accepted
Headers show

Comments

Manuel Jacob - June 16, 2020, 1:50 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1592184624 -7200
#      Mon Jun 15 03:30:24 2020 +0200
# Branch stable
# Node ID 343142bb73bafe1ad2a244905e63770fb31a0ee0
# Parent  0dddc84a6a1ac5bb027b66c12d79aa5916d2b05b
# EXP-Topic convert-svn
py3: fix bytes iteration
Yuya Nishihara - June 16, 2020, 9:46 a.m.
On Tue, 16 Jun 2020 03:50:27 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1592184624 -7200
> #      Mon Jun 15 03:30:24 2020 +0200
> # Branch stable
> # Node ID 343142bb73bafe1ad2a244905e63770fb31a0ee0
> # Parent  0dddc84a6a1ac5bb027b66c12d79aa5916d2b05b
> # EXP-Topic convert-svn
> py3: fix bytes iteration
> 
> diff --git a/hgext/convert/common.py b/hgext/convert/common.py
> --- a/hgext/convert/common.py
> +++ b/hgext/convert/common.py
> @@ -87,7 +87,7 @@
>  def encodeargs(args):
>      def encodearg(s):
>          lines = base64.encodestring(s)
> -        lines = [l.splitlines()[0] for l in lines]
> +        lines = [l.splitlines()[0] for l in pycompat.iterbytestr(lines)]
>          return b''.join(lines)

This is fine, but the original code looks strange. Maybe it should do
b''.joins(lines.splitlines()) to remove '\n's?
Manuel Jacob - June 16, 2020, 10:38 a.m.
On 2020-06-16 11:46, Yuya Nishihara wrote:
> On Tue, 16 Jun 2020 03:50:27 +0200, Manuel Jacob wrote:
>> # HG changeset patch
>> # User Manuel Jacob <me@manueljacob.de>
>> # Date 1592184624 -7200
>> #      Mon Jun 15 03:30:24 2020 +0200
>> # Branch stable
>> # Node ID 343142bb73bafe1ad2a244905e63770fb31a0ee0
>> # Parent  0dddc84a6a1ac5bb027b66c12d79aa5916d2b05b
>> # EXP-Topic convert-svn
>> py3: fix bytes iteration
>> 
>> diff --git a/hgext/convert/common.py b/hgext/convert/common.py
>> --- a/hgext/convert/common.py
>> +++ b/hgext/convert/common.py
>> @@ -87,7 +87,7 @@
>>  def encodeargs(args):
>>      def encodearg(s):
>>          lines = base64.encodestring(s)
>> -        lines = [l.splitlines()[0] for l in lines]
>> +        lines = [l.splitlines()[0] for l in 
>> pycompat.iterbytestr(lines)]
>>          return b''.join(lines)
> 
> This is fine, but the original code looks strange. Maybe it should do
> b''.joins(lines.splitlines()) to remove '\n's?

Considering that the tests for this module don’t run on Python 3 in any 
CI in the moment, I’d like to postpone further cleanups.

Patch

diff --git a/hgext/convert/common.py b/hgext/convert/common.py
--- a/hgext/convert/common.py
+++ b/hgext/convert/common.py
@@ -87,7 +87,7 @@ 
 def encodeargs(args):
     def encodearg(s):
         lines = base64.encodestring(s)
-        lines = [l.splitlines()[0] for l in lines]
+        lines = [l.splitlines()[0] for l in pycompat.iterbytestr(lines)]
         return b''.join(lines)
 
     s = pickle.dumps(args)