From patchwork Sun Mar 3 09:34:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D6051: encoding: use raw strings for encoding arguments From: phabricator X-Patchwork-Id: 39015 Message-Id: <56cf5570f01d6ad05ec125de2f85fef1@localhost.localdomain> To: mercurial-devel@mercurial-scm.org Date: Sun, 3 Mar 2019 09:34:24 +0000 This revision was automatically updated to reflect the committed changes. Closed by commit rHG25694a78e4a4: encoding: use raw strings for encoding arguments (authored by indygreg, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6051?vs=14300&id=14316 REVISION DETAIL https://phab.mercurial-scm.org/D6051 AFFECTED FILES mercurial/encoding.py CHANGE DETAILS To: indygreg, #hg-reviewers Cc: mercurial-devel diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -65,7 +65,7 @@ else: # preferred encoding isn't known yet; use utf-8 to avoid unicode error # and recreate it once encoding is settled - environ = dict((k.encode(u'utf-8'), v.encode(u'utf-8')) + environ = dict((k.encode(r'utf-8'), v.encode(r'utf-8')) for k, v in os.environ.items()) # re-exports _encodingrewrites = { @@ -152,24 +152,24 @@ if encoding == 'UTF-8': # fast path return s - r = u.encode(_sysstr(encoding), u"replace") + r = u.encode(_sysstr(encoding), r"replace") if u == r.decode(_sysstr(encoding)): # r is a safe, non-lossy encoding of s return safelocalstr(r) return localstr(s, r) except UnicodeDecodeError: # we should only get here if we're looking at an ancient changeset try: u = s.decode(_sysstr(fallbackencoding)) - r = u.encode(_sysstr(encoding), u"replace") + r = u.encode(_sysstr(encoding), r"replace") if u == r.decode(_sysstr(encoding)): # r is a safe, non-lossy encoding of s return safelocalstr(r) return localstr(u.encode('UTF-8'), r) except UnicodeDecodeError: u = s.decode("utf-8", "replace") # last ditch # can't round-trip - return u.encode(_sysstr(encoding), u"replace") + return u.encode(_sysstr(encoding), r"replace") except LookupError as k: raise error.Abort(k, hint="please check your locale settings") @@ -230,7 +230,7 @@ if not _nativeenviron: # now encoding and helper functions are available, recreate the environ # dict to be exported to other modules - environ = dict((tolocal(k.encode(u'utf-8')), tolocal(v.encode(u'utf-8'))) + environ = dict((tolocal(k.encode(r'utf-8')), tolocal(v.encode(r'utf-8'))) for k, v in os.environ.items()) # re-exports if pycompat.ispy3: @@ -251,7 +251,7 @@ def colwidth(s): "Find the column width of a string for display in the local encoding" - return ucolwidth(s.decode(_sysstr(encoding), u'replace')) + return ucolwidth(s.decode(_sysstr(encoding), r'replace')) def ucolwidth(d): "Find the column width of a Unicode string for display"