durin42 created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The big annoyance here was having to feed textwrap unicodes instead of
  bytes, but it all seems to work.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5053

AFFECTED FILES
  hgext/releasenotes.py

CHANGE DETAILS

diff --git a/hgext/releasenotes.py b/hgext/releasenotes.py
--- a/hgext/releasenotes.py
+++ b/hgext/releasenotes.py
@@ -59,6 +59,20 @@
 
 BULLET_SECTION = _('Other Changes')
 
+if pycompat.ispy3:
+    class byteswrapper(object):
+        def __init__(self, **kwargs):
+            for k in kwargs:
+                v = kwargs[k]
+                if not isinstance(v, str) and isinstance(v, bytes):
+                    kwargs[k] = v.decode('utf8')
+            self._tw = textwrap.TextWrapper(**kwargs)
+        def wrap(self, data):
+            return [
+                l.encode('utf8') for l in self._tw.wrap(data.decode('utf8'))]
+else:
+    byteswrapper = textwrap.TextWrapper
+
 class parsedreleasenotes(object):
     def __init__(self):
         self.sections = {}
@@ -444,7 +458,7 @@
             lines.append('-' * len(title))
             lines.append('')
 
-            wrapper = textwrap.TextWrapper(width=78)
+            wrapper = byteswrapper(width=78)
             for i, para in enumerate(paragraphs):
                 if i:
                     lines.append('')
@@ -466,14 +480,14 @@
             lines.append('')
 
         for paragraphs in nontitled:
-            wrapper = textwrap.TextWrapper(initial_indent='* ',
-                                           subsequent_indent='  ',
-                                           width=78)
+            wrapper = byteswrapper(initial_indent='* ',
+                                   subsequent_indent='  ',
+                                   width=78)
             lines.extend(wrapper.wrap(' '.join(paragraphs[0])))
 
-            wrapper = textwrap.TextWrapper(initial_indent='  ',
-                                           subsequent_indent='  ',
-                                           width=78)
+            wrapper = byteswrapper(initial_indent='  ',
+                                   subsequent_indent='  ',
+                                   width=78)
             for para in paragraphs[1:]:
                 lines.append('')
                 lines.extend(wrapper.wrap(' '.join(para)))



To: durin42, #hg-reviewers
Cc: mjpieters, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to