Skip to content

Commit fded99d

Browse files
committed
fixed ReStructuredText encoding with Python 3
1 parent 9700ae5 commit fded99d

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ install:
9393
- pip install psycopg2
9494
- pip install gpg pytz whoosh pyjwt
9595
- pip install pytest-cov codecov
96+
- if [[ $TRAVIS_PYTHON_VERSION != "3.4"* ]]; then pip install docutils; fi
9697

9798
before_script:
9899
# set up mysql database

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Fixed:
103103
- issue2551051: Return a 403 on non-existing or non-searchable
104104
transitive properties when queried via REST-API (same behavior for
105105
sorting and searching).
106+
- Fixed ReStructuredText encoding with Python 3.
106107

107108
2019-10-23 2.0.0 alpha 0
108109

roundup/cgi/templating.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,8 +1599,7 @@ def rst(self, hyperlink=1):
15991599
s = self.plain(escape=0, hyperlink=0)
16001600
if hyperlink:
16011601
s = self.hyper_re.sub(self._hyper_repl_rst, s)
1602-
return ReStructuredText(s, writer_name="html")["html_body"].encode("utf-8",
1603-
"replace")
1602+
return u2s(ReStructuredText(s, writer_name="html")["html_body"])
16041603

16051604
def field(self, **kwargs):
16061605
""" Render the property as a field in HTML.

test/test_templating.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
from roundup.cgi.templating import *
66
from .test_actions import MockNull, true
77

8+
try:
9+
from docutils.core import publish_parts as ReStructuredText
10+
except ImportError:
11+
ReStructuredText = None
12+
13+
from roundup.anypy.strings import u2s, s2u
14+
815
class MockDatabase(MockNull):
916
def getclass(self, name):
1017
return self.classes[name]
@@ -210,6 +217,13 @@ def test_string_plain_or_hyperlinked(self):
210217

211218
self.assertEqual(p.hyperlinked(), 'A string &lt;b&gt; with <a href="mailto:[email protected]">[email protected]</a> embedded &amp;lt; html&lt;/b&gt;')
212219

220+
def test_string_rst(self):
221+
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', u2s(u'A string with [email protected] *embedded* \u00df'))
222+
if ReStructuredText:
223+
self.assertEqual(p.rst(), u2s(u'<div class="document">\n<p>A string with <a class="reference external" href="mailto:cmeerw&#64;example.com">cmeerw&#64;example.com</a> <em>embedded</em> \u00df</p>\n</div>\n'))
224+
else:
225+
self.assertEqual(p.rst(), u2s(u'A string with <a href="mailto:[email protected]">[email protected]</a> *embedded* \u00df'))
226+
213227
def test_string_field(self):
214228
p = StringHTMLProperty(self.client, 'test', '1', None, 'test', 'A string <b> with [email protected] embedded &lt; html</b>')
215229
self.assertEqual(p.field(), '<input name="test1@test" size="30" type="text" value="A string &lt;b&gt; with [email protected] embedded &amp;lt; html&lt;/b&gt;">')

0 commit comments

Comments
 (0)