# HG changeset patch # User Augie Fackler # Date 1539415641 14400 # Node ID 3fc2ef49959cefa8b550686a600e696d9926b7c4 # Parent 6309128ff61f3ccb0c08ccfe1788dfe67d16d14f relnotes: port to Python 3 The big annoyance here was having to feed textwrap unicodes instead of bytes, but it all seems to work. Differential Revision: https://phab.mercurial-scm.org/D5053 diff -r 6309128ff61f -r 3fc2ef49959c hgext/releasenotes.py --- a/hgext/releasenotes.py Sat Oct 13 11:01:38 2018 +0200 +++ b/hgext/releasenotes.py Sat Oct 13 03:27:21 2018 -0400 @@ -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)))