Patchwork [1,of,8] templatefilters: use encoding.unifromlocal/unitolocal() for py3 compatibility

login
register
mail settings
Submitter Yuya Nishihara
Date March 1, 2018, 2:17 p.m.
Message ID <905fd8fbfd54838f8e07.1519913828@mimosa>
Download mbox | patch
Permalink /patch/28548/
State Accepted
Headers show

Comments

Yuya Nishihara - March 1, 2018, 2:17 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519904317 18000
#      Thu Mar 01 06:38:37 2018 -0500
# Node ID 905fd8fbfd54838f8e079719e5ada074d975b824
# Parent  4b9e9e3f450c7c8a8717e0a2ed9573a067903ce6
templatefilters: use encoding.unifromlocal/unitolocal() for py3 compatibility
Pulkit Goyal - March 1, 2018, 7:42 p.m.
Using my new super powers, I queued the series. Thanks

On Thu, Mar 1, 2018 at 7:47 PM, Yuya Nishihara <yuya@tcha.org> wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1519904317 18000
> #      Thu Mar 01 06:38:37 2018 -0500
> # Node ID 905fd8fbfd54838f8e079719e5ada074d975b824
> # Parent  4b9e9e3f450c7c8a8717e0a2ed9573a067903ce6
> templatefilters: use encoding.unifromlocal/unitolocal() for py3 compatibility
>
> diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
> --- a/mercurial/templatefilters.py
> +++ b/mercurial/templatefilters.py
> @@ -152,12 +152,12 @@ def fill(text, width, initindent='', han
>          while True:
>              m = para_re.search(text, start)
>              if not m:
> -                uctext = unicode(text[start:], encoding.encoding)
> +                uctext = encoding.unifromlocal(text[start:])
>                  w = len(uctext)
>                  while 0 < w and uctext[w - 1].isspace():
>                      w -= 1
> -                yield (uctext[:w].encode(encoding.encoding),
> -                       uctext[w:].encode(encoding.encoding))
> +                yield (encoding.unitolocal(uctext[:w]),
> +                       encoding.unitolocal(uctext[w:]))
>                  break
>              yield text[start:m.start(0)], m.group(1)
>              start = m.end(1)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -152,12 +152,12 @@  def fill(text, width, initindent='', han
         while True:
             m = para_re.search(text, start)
             if not m:
-                uctext = unicode(text[start:], encoding.encoding)
+                uctext = encoding.unifromlocal(text[start:])
                 w = len(uctext)
                 while 0 < w and uctext[w - 1].isspace():
                     w -= 1
-                yield (uctext[:w].encode(encoding.encoding),
-                       uctext[w:].encode(encoding.encoding))
+                yield (encoding.unitolocal(uctext[:w]),
+                       encoding.unitolocal(uctext[w:]))
                 break
             yield text[start:m.start(0)], m.group(1)
             start = m.end(1)