Kozea/WeasyPrint — pull request #84 by ariofrio (2013-05-17 08:19:15+00:00)
Title: Crash when stylesheet is not available

All browsers ignore unavailable stylesheets and print a message to the console to this effect. Instead, WeasyPrint crashes.

Example: http://www.w3.org/Style/CSS/Test/Print/1.0/20070802/t1302-page-01-b.htm

Traceback (most recent call last):
File "/home/ariofrio/Repositories/WeasyPrint/env/bin/weasyprint", line 8, in
load_entry_point('WeasyPrint==0.19.1', 'console_scripts', 'weasyprint')()
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/__main__.py", line 141, in main
getattr(html, 'write_' + format_)(output, **kwargs)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/__init__.py", line 159, in write_pdf
return self.render(stylesheets).write_pdf(target, zoom)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/__init__.py", line 131, in render
return Document._render(self, stylesheets, enable_hinting)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/document.py", line 253, in _render
for css in stylesheets or []])
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/css/__init__.py", line 431, in get_all_computed_styles
element_tree, device_media_type, url_fetcher))
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/css/__init__.py", line 189, in find_stylesheets
_check_mime_type=True, media_type=device_media_type)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/__init__.py", line 219, in __init__
check_css_mime_type=_check_mime_type,)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/__init__.py", line 271, in _select_source
result = url_fetcher(url)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/urls.py", line 281, in wrapped_fetcher
result = url_fetcher(url)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/urls.py", line 281, in wrapped_fetcher
result = url_fetcher(url)
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/urls.py", line 262, in default_url_fetcher
url, headers={'User-Agent': VERSION_STRING}))
File "/home/ariofrio/Repositories/WeasyPrint/weasyprint/compat.py", line 80, in urlopen_contenttype
result = urlopen(url)
File "/usr/lib64/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.7/urllib2.py", line 406, in open
response = meth(req, response)
File "/usr/lib64/python2.7/urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.7/urllib2.py", line 444, in error
return self._call_chain(*args)
File "/usr/lib64/python2.7/urllib2.py", line 378, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found