diff --git a/py/rest/rst.py b/py/rest/rst.py index 585cf42ce..228402781 100644 --- a/py/rest/rst.py +++ b/py/rest/rst.py @@ -15,6 +15,8 @@ import py def escape(txt): """escape ReST markup""" + if not isinstance(txt, str) and not isinstance(txt, unicode): + txt = str(txt) # XXX this takes a very naive approach to escaping, but it seems to be # sufficient... for c in '\\*`|:_': @@ -231,6 +233,8 @@ class AbstractText(AbstractNode): return self.start + text + self.end def escape(self, text): + if not isinstance(text, str) and not isinstance(text, unicode): + text = str(text) if self.start: text = text.replace(self.start, '\\%s' % (self.start,)) if self.end and self.end != self.start: diff --git a/py/rest/testing/test_rst.py b/py/rest/testing/test_rst.py index 696470369..0d680387b 100644 --- a/py/rest/testing/test_rst.py +++ b/py/rest/testing/test_rst.py @@ -429,16 +429,25 @@ def test_directive_content(): def test_title_following_links_empty_line(): expected = """\ -Foo, bar and `baz`_. +Foo, bar and `baz`_ + +Spam +==== + +Spam, eggs and spam. .. _`baz`: http://www.baz.com -Spam ----- - -Spam, eggs and spam. """ txt = Rest(Paragraph("Foo, bar and ", Link("baz", "http://www.baz.com")), - Title('Spam'), Paragraph('Spam, eggs and spam.')) + Title('Spam'), Paragraph('Spam, eggs and spam.')).text() + assert txt == expected checkrest(txt) +def test_nonstring_text(): + expected = """\ +/foo/bar.py +""" + txt = Rest(Paragraph(Text(py.path.local('/foo/bar.py')))).text() + assert txt == expected +