summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2013-04-28 11:31:22 +0200
committerStefan Behnel <stefan_ml@behnel.de>2013-04-28 11:31:22 +0200
commit1d4ecb12d5bd2858a1ab5c29f9401518b7f87647 (patch)
treeb6238e054214c5705936fcaee7a2d9e146c4fe04
parenta8a5a39a135a2c2c31a764f0f759217a937df3bb (diff)
downloadpython-lxml-1d4ecb12d5bd2858a1ab5c29f9401518b7f87647.tar.gz
always restore parser context options after calling into libxml2's parser
-rw-r--r--CHANGES.txt3
-rw-r--r--src/lxml/parser.pxi7
2 files changed, 9 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 0b409489..acae7104 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,9 @@ Features added
Bugs fixed
----------
+* LP#673205: Parsing from a string disabled network access in the default
+ parser and made subsequent attempts to parse from a URL fail.
+
* LP#715687: lxml.html.clean no longer discards scripts that are explicitly
allowed by the user provided whitelist.
diff --git a/src/lxml/parser.pxi b/src/lxml/parser.pxi
index c036284f..644d42a4 100644
--- a/src/lxml/parser.pxi
+++ b/src/lxml/parser.pxi
@@ -334,6 +334,7 @@ cdef class _FileReaderContext:
c_read_callback = _readFileParser
c_callback_context = c_stream
+ orig_options = ctxt.options
with nogil:
if ctxt.html:
result = htmlparser.htmlCtxtReadIO(
@@ -347,6 +348,7 @@ cdef class _FileReaderContext:
result = xmlparser.xmlCtxtReadIO(
ctxt, c_read_callback, NULL, c_callback_context,
self._c_url, c_encoding, options)
+ ctxt.options = orig_options # work around libxml2 problem
self._close_file()
return result
@@ -938,6 +940,7 @@ cdef class _BaseParser:
__GLOBAL_PARSER_CONTEXT.initParserDict(pctxt)
c_text = python.PyUnicode_AS_DATA(utext)
+ orig_options = pctxt.options
with nogil:
if self._for_html:
result = htmlparser.htmlCtxtReadMemory(
@@ -951,6 +954,7 @@ cdef class _BaseParser:
result = xmlparser.xmlCtxtReadMemory(
pctxt, c_text, buffer_len, c_filename, _UNICODE_ENCODING,
self._parse_options)
+ pctxt.options = orig_options # work around libxml2 problem
return context._handleParseResultDoc(self, result, None)
finally:
@@ -978,6 +982,7 @@ cdef class _BaseParser:
else:
c_encoding = _cstr(self._default_encoding)
+ orig_options = pctxt.options
with nogil:
if self._for_html:
result = htmlparser.htmlCtxtReadMemory(
@@ -991,6 +996,7 @@ cdef class _BaseParser:
result = xmlparser.xmlCtxtReadMemory(
pctxt, c_text, c_len, c_filename,
c_encoding, self._parse_options)
+ pctxt.options = orig_options # work around libxml2 problem
return context._handleParseResultDoc(self, result, None)
finally:
@@ -1000,7 +1006,6 @@ cdef class _BaseParser:
cdef _ParserContext context
cdef xmlDoc* result
cdef xmlparser.xmlParserCtxt* pctxt
- cdef int orig_options
cdef char* c_encoding
result = NULL