Patchwork encoding: make sure "wide" variable never be referenced from other modules

login
register
mail settings
Submitter Yuya Nishihara
Date May 29, 2017, 2:29 p.m.
Message ID <f54d0838ba7a86c9572c.1496068157@mimosa>
Download mbox | patch
Permalink /patch/21039/
State Accepted
Headers show

Comments

Yuya Nishihara - May 29, 2017, 2:29 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1496062671 -32400
#      Mon May 29 21:57:51 2017 +0900
# Node ID f54d0838ba7a86c9572cc00dab70a45adc49fa24
# Parent  aa333c1982abfe12a3940811d07468a286de93db
encoding: make sure "wide" variable never be referenced from other modules

Better to not expose (maybe-) unicode objects.
Augie Fackler - May 29, 2017, 2:30 p.m.
> On May 29, 2017, at 10:29 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1496062671 -32400
> #      Mon May 29 21:57:51 2017 +0900
> # Node ID f54d0838ba7a86c9572cc00dab70a45adc49fa24
> # Parent  aa333c1982abfe12a3940811d07468a286de93db
> encoding: make sure "wide" variable never be referenced from other modules

Queued, thanks.

Patch

diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -194,8 +194,8 @@  if not _nativeenviron:
                    for k, v in os.environ.items())  # re-exports
 
 # How to treat ambiguous-width characters. Set to 'wide' to treat as wide.
-wide = _sysstr(environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide"
-               and "WFA" or "WF")
+_wide = _sysstr(environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide"
+                and "WFA" or "WF")
 
 def colwidth(s):
     "Find the column width of a string for display in the local encoding"
@@ -205,7 +205,7 @@  def ucolwidth(d):
     "Find the column width of a Unicode string for display"
     eaw = getattr(unicodedata, 'east_asian_width', None)
     if eaw is not None:
-        return sum([eaw(c) in wide and 2 or 1 for c in d])
+        return sum([eaw(c) in _wide and 2 or 1 for c in d])
     return len(d)
 
 def getcols(s, start, c):