Patchwork [09,of,10,py3] help: work around textwrap.dedent() only working on strings

login
register
mail settings
Submitter Augie Fackler
Date May 29, 2017, 2:32 p.m.
Message ID <f1be99397daee2fa8bd9.1496068351@imladris.local>
Download mbox | patch
Permalink /patch/21054/
State Accepted
Headers show

Comments

Augie Fackler - May 29, 2017, 2:32 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1496001067 14400
#      Sun May 28 15:51:07 2017 -0400
# Node ID f1be99397daee2fa8bd9d04cb1296cb7e0260c0d
# Parent  c52ab13885c505252bddf459e3ef86fe1fb8f560
help: work around textwrap.dedent() only working on strings

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -270,7 +270,8 @@  def makeitemsdoc(ui, topic, doc, marker,
             continue
         text = gettext(text)
         if dedent:
-            text = textwrap.dedent(text)
+            # Abuse latin1 to use textwrap.dedent() on bytes.
+            text = textwrap.dedent(text.decode('latin1')).encode('latin1')
         lines = text.splitlines()
         doclines = [(lines[0])]
         for l in lines[1:]: