From 7ebd7ec8889b1495cd7b69e39fdd439904d0f069 Mon Sep 17 00:00:00 2001 From: guido Date: Sat, 27 Jan 2007 16:36:20 +0100 Subject: [PATCH] [svn r37437] Made stuff a bit more robust by converting non-strings to strings in some places. --HG-- branch : trunk --- py/rest/rst.py | 4 ++++ py/rest/testing/test_rst.py | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) 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 +