[PATCH 2 of 2] py3: fix str vs bytes in enough places to run `hg version` on Windows
Matt Harbison
mharbison72 at gmail.com
Fri Sep 14 22:30:24 EDT 2018
On Fri, 14 Sep 2018 08:09:14 -0400, Yuya Nishihara <yuya at tcha.org> wrote:
> On Fri, 14 Sep 2018 00:52:34 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison at yahoo.com>
>> # Date 1536890820 14400
>> # Thu Sep 13 22:07:00 2018 -0400
>> # Node ID a1c3c33e911a449c1e67d6c70a1320f34233f253
>> # Parent 82be987da1489e3ff7411540b473690e6039fd67
>> py3: fix str vs bytes in enough places to run `hg version` on Windows
>> @@ -484,7 +484,7 @@ if pycompat.iswindows:
>> w32effects = None
>> else:
>> origattr = csbi.wAttributes
>> - ansire = re.compile('\033\[([^m]*)m([^\033]*)(.*)',
>> + ansire = re.compile(r'\033\[([^m]*)m([^\033]*)(.*)',
>> re.MULTILINE | re.DOTALL)
>>
>> def win32print(ui, writefunc, *msgs, **opts):
>> @@ -520,16 +520,16 @@ if pycompat.iswindows:
>> text = '\033[m' + text
>>
>> # Look for ANSI-like codes embedded in text
>> - m = re.match(ansire, text)
>> + m = re.match(ansire, pycompat.sysstr(text))
>
> Why do you want to convert text to unicode here? It's converted back to
> bytes later.
I got this:
Traceback (most recent call last):
...
File "c:\Users\Matt\projects\hg\mercurial\commands.py", line 5868, in
version_
util.version())
File "c:\Users\Matt\projects\hg\mercurial\formatter.py", line 303, in
write
self._write(deftext % fielddata, **opts)
File "c:\Users\Matt\projects\hg\mercurial\ui.py", line 948, in write
self._writenobuf(*args, **opts)
File "c:\Users\Matt\projects\hg\mercurial\ui.py", line 954, in
_writenobuf
color.win32print(self, self._write, *args, **opts)
File "c:\Users\Matt\projects\hg\mercurial\color.py", line 492, in
win32print
_win32print(ui, text, writefunc, **opts)
File "c:\Users\Matt\projects\hg\mercurial\color.py", line 523, in
_win32print
m = re.match(ansire, text)
File "C:\Program Files\Python37\lib\re.py", line 173, in match
return _compile(pattern, flags).match(string)
TypeError: cannot use a string pattern on a bytes-like object
But it looks like changing a few r'' to b'' lets it work.
>> - for sattr in m.group(1).split(';'):
>> + for sattr in m.group(1).split(r';'):
>> if sattr:
>> attr = mapcolor(int(sattr), attr)
>> ui.flush()
>> _kernel32.SetConsoleTextAttribute(stdout, attr)
>> - writefunc(m.group(2), **opts)
>> + writefunc(encoding.unitolocal(m.group(2)), **opts)
More information about the Mercurial-devel
mailing list