[svn r37437] Made stuff a bit more robust by converting non-strings to strings in some

places.

--HG--
branch : trunk
This commit is contained in:
guido 2007-01-27 16:36:20 +01:00
parent 241ef0ff4a
commit 7ebd7ec888
2 changed files with 19 additions and 6 deletions

View File

@ -15,6 +15,8 @@ import py
def escape(txt): def escape(txt):
"""escape ReST markup""" """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 # XXX this takes a very naive approach to escaping, but it seems to be
# sufficient... # sufficient...
for c in '\\*`|:_': for c in '\\*`|:_':
@ -231,6 +233,8 @@ class AbstractText(AbstractNode):
return self.start + text + self.end return self.start + text + self.end
def escape(self, text): def escape(self, text):
if not isinstance(text, str) and not isinstance(text, unicode):
text = str(text)
if self.start: if self.start:
text = text.replace(self.start, '\\%s' % (self.start,)) text = text.replace(self.start, '\\%s' % (self.start,))
if self.end and self.end != self.start: if self.end and self.end != self.start:

View File

@ -429,16 +429,25 @@ def test_directive_content():
def test_title_following_links_empty_line(): def test_title_following_links_empty_line():
expected = """\ expected = """\
Foo, bar and `baz`_. Foo, bar and `baz`_
Spam
====
Spam, eggs and spam.
.. _`baz`: http://www.baz.com .. _`baz`: http://www.baz.com
Spam
----
Spam, eggs and spam.
""" """
txt = Rest(Paragraph("Foo, bar and ", Link("baz", "http://www.baz.com")), 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) checkrest(txt)
def test_nonstring_text():
expected = """\
/foo/bar.py
"""
txt = Rest(Paragraph(Text(py.path.local('/foo/bar.py')))).text()
assert txt == expected