# HG changeset patch # User Paul Boddie # Date 1374162877 -7200 # Node ID d01e634420e5e5aa5e9c88afb10f59bb2446c84e # Parent 8eeed259e92ab8220a39708e9aa98bde5dc18375 Improved error handling when obtaining remote HTML resources. diff -r 8eeed259e92a -r d01e634420e5 libxml2dom/macrolib/macrolib.py --- a/libxml2dom/macrolib/macrolib.py Sat Jun 01 17:01:05 2013 +0200 +++ b/libxml2dom/macrolib/macrolib.py Thu Jul 18 17:54:37 2013 +0200 @@ -3,7 +3,7 @@ """ DOM macros for virtual libxml2mod node methods and properties. -Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Paul Boddie +Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -595,8 +595,11 @@ context = libxml2mod.xmlCreateFileParserCtxt(s) return _parseXML(context, unfinished, validate, remote) else: - return libxml2mod.htmlReadFile(s, htmlencoding, + d = libxml2mod.htmlReadFile(s, htmlencoding, HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | html_net_flag(remote)) + if d is None: + raise LSException(LSException.PARSE_ERR, DOMError(DOMError.SEVERITY_FATAL_ERROR, get_parse_error_message())) + return d def parseString(s, html=0, htmlencoding=None, unfinished=0, validate=0, remote=0): if not html: @@ -605,8 +608,11 @@ else: # NOTE: URL given as None. html_url = None - return libxml2mod.htmlReadMemory(s, len(s), html_url, htmlencoding, + d = libxml2mod.htmlReadMemory(s, len(s), html_url, htmlencoding, HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING | html_net_flag(remote)) + if d is None: + raise LSException(LSException.PARSE_ERR, DOMError(DOMError.SEVERITY_FATAL_ERROR, get_parse_error_message())) + return d def parseURI(uri, html=0, htmlencoding=None, unfinished=0, validate=0, remote=0): if not html: diff -r 8eeed259e92a -r d01e634420e5 tests/test_bad_html.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_bad_html.py Thu Jul 18 17:54:37 2013 +0200 @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +import libxml2dom + +html = "