Crash in "render_exception()"
myint opened this issue · comments
I noticed this today. If I recall correctly, this worked okay in the past for me.
$ python --version
Python 3.4.1
foo.rst
:
Hello
---
$ restview --strict foo.rst
Listening on http://localhost:53298/
<string>:2: (INFO/1) Possible title underline, too short for the title.
Treating it as ordinary text because it's so short.
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53299)
Traceback (most recent call last):
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 429, in rest_to_html
settings_overrides=settings_overrides)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/core.py", line 414, in publish_string
enable_exit_status=enable_exit_status)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/core.py", line 662, in publish_programmatically
output = pub.publish(enable_exit_status=enable_exit_status)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/core.py", line 217, in publish
self.settings)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/readers/__init__.py", line 72, in read
self.parse()
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/readers/__init__.py", line 78, in parse
self.parser.parse(self.input, document)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/parsers/rst/__init__.py", line 172, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/parsers/rst/states.py", line 170, in run
input_source=document['source'])
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/statemachine.py", line 239, in run
context, state, transitions)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/parsers/rst/states.py", line 2702, in underline
line=lineno)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/utils/__init__.py", line 213, in info
return self.system_message(self.INFO_LEVEL, *args, **kwargs)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/docutils/utils/__init__.py", line 193, in system_message
raise SystemMessage(msg, level)
docutils.utils.SystemMessage: <string>:2: (INFO/1) Possible title underline, too short for the title.
Treating it as ordinary text because it's so short.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socketserver.py", line 609, in process_request_thread
self.finish_request(request, client_address)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/socketserver.py", line 665, in __init__
self.handle()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/server.py", line 398, in handle
self.handle_one_request()
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/http/server.py", line 386, in handle_one_request
method()
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 79, in do_GET
content = self.do_GET_or_HEAD()
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 100, in do_GET_or_HEAD
return self.handle_rest_file(root)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 180, in handle_rest_file
return self.handle_rest_data(f.read(), mtime=mtime)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 201, in handle_rest_data
html = self.server.renderer.rest_to_html(data, mtime=mtime)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 431, in rest_to_html
html = self.render_exception(e.__class__.__name__, str(e), rest_input)
File "/Users/myint/Library/Python/3.4/lib/python/site-packages/restview/restviewhttp.py", line 439, in render_exception
.replace('$source', escape(source)))
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/html/__init__.py", line 19, in escape
s = s.replace("&", "&") # Must be done first!
TypeError: expected bytes, bytearray or buffer compatible object
This is what I get for not having a clear Unicode model in restview.
source
here is a bytestring because #16, while the rest are all unicode strings.
Found a related bug while writing tests for this one: if you enable --pypi-strict
on Python 3 you get
Traceback (most recent call last):
File "/usr/lib/python3.4/socketserver.py", line 609, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.4/socketserver.py", line 344, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.4/socketserver.py", line 665, in __init__
self.handle()
File "/usr/lib/python3.4/http/server.py", line 398, in handle
self.handle_one_request()
File "/usr/lib/python3.4/http/server.py", line 386, in handle_one_request
method()
File "./src/restview/restviewhttp.py", line 79, in do_GET
content = self.do_GET_or_HEAD()
File "./src/restview/restviewhttp.py", line 100, in do_GET_or_HEAD
return self.handle_rest_file(root)
File "./src/restview/restviewhttp.py", line 180, in handle_rest_file
return self.handle_rest_data(f.read(), mtime=mtime)
File "./src/restview/restviewhttp.py", line 201, in handle_rest_data
html = self.server.renderer.rest_to_html(data, mtime=mtime)
File "./src/restview/restviewhttp.py", line 416, in rest_to_html
rest_input = trim_docstring(rest_input)
File "./src/restview/pypi_support.py", line 73, in trim_docstring
return '\n'.join(trimmed)
TypeError: sequence item 0: expected str instance, bytes found
I'll release 2.1.1 with this fix once PyPI is back to full service.
Thanks, that fixed it for me.
restview 2.2.1 is on PyPI.