Patchwork [3,of,9] py3: replace "if ispy3" by pycompat.sysbytes() or util.forcebytestr()

login
register
mail settings
Submitter Yuya Nishihara
Date Feb. 3, 2018, 8:36 a.m.
Message ID <9b3d33f9e615002d0a7d.1517646974@mimosa>
Download mbox | patch
Permalink /patch/27263/
State Accepted
Headers show

Comments

Yuya Nishihara - Feb. 3, 2018, 8:36 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1517026446 -32400
#      Sat Jan 27 13:14:06 2018 +0900
# Node ID 9b3d33f9e615002d0a7da4d0d04ec04ae5c04cff
# Parent  ab13ecb04e6665222ad3e10308dc7c2b84b3138b
py3: replace "if ispy3" by pycompat.sysbytes() or util.forcebytestr()

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -939,9 +939,9 @@  def _exceptionwarning(ui):
     worst = None, ct, ''
     if ui.config('ui', 'supportcontact') is None:
         for name, mod in extensions.extensions():
-            testedwith = getattr(mod, 'testedwith', '')
-            if pycompat.ispy3 and isinstance(testedwith, str):
-                testedwith = testedwith.encode(u'utf-8')
+            # 'testedwith' should be bytes, but not all extensions are ported
+            # to py3 and we don't want UnicodeException because of that.
+            testedwith = util.forcebytestr(getattr(mod, 'testedwith', ''))
             report = getattr(mod, 'buglink', _('the extension author.'))
             if not testedwith.strip():
                 # We found an untested extension. It's likely the culprit.
@@ -976,11 +976,7 @@  def _exceptionwarning(ui):
             bugtracker = _("https://mercurial-scm.org/wiki/BugTracker")
         warning = (_("** unknown exception encountered, "
                      "please report by visiting\n** ") + bugtracker + '\n')
-    if pycompat.ispy3:
-        sysversion = sys.version.encode(u'utf-8')
-    else:
-        sysversion = sys.version
-    sysversion = sysversion.replace('\n', '')
+    sysversion = pycompat.sysbytes(sys.version).replace('\n', '')
     warning += ((_("** Python %s\n") % sysversion) +
                 (_("** Mercurial Distributed SCM (version %s)\n") %
                  util.version()) +