summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-04-19 06:28:48 +0200
committerStefan Behnel <stefan_ml@behnel.de>2019-04-19 06:28:48 +0200
commit013ae28b8503ea21e1f86453340413e6690b910e (patch)
tree8d11394b3f9b592c42a618100a9bc9424394766d /src
parente6db92a2fb84dddd58ec0e87cb0d8efad5b5d707 (diff)
downloadpython-lxml-013ae28b8503ea21e1f86453340413e6690b910e.tar.gz
Make failures to write an XSLT output file raise an IOError, instead of incorrectly trying (and failing) to instantiate an XSLTSaveError and raising an AttributeError instead.
Diffstat (limited to 'src')
-rw-r--r--src/lxml/tests/test_xslt.py14
-rw-r--r--src/lxml/xslt.pxi2
2 files changed, 14 insertions, 2 deletions
diff --git a/src/lxml/tests/test_xslt.py b/src/lxml/tests/test_xslt.py
index f6b48fb9..08d03514 100644
--- a/src/lxml/tests/test_xslt.py
+++ b/src/lxml/tests/test_xslt.py
@@ -12,7 +12,7 @@ import os.path
import unittest
import contextlib
from textwrap import dedent
-from tempfile import NamedTemporaryFile
+from tempfile import NamedTemporaryFile, mkdtemp
this_dir = os.path.dirname(__file__)
if this_dir not in sys.path:
@@ -223,6 +223,18 @@ class ETreeXSLTTestCase(HelperTestCase):
finally:
os.unlink(f.name)
+ def test_xslt_write_output_file_oserror(self):
+ with self._xslt_setup(expected='') as res:
+ tempdir = mkdtemp()
+ try:
+ res[0].write_output(os.path.join(tempdir, 'missing_subdir', 'out.xml'))
+ except IOError:
+ res[0] = ''
+ else:
+ self.fail("IOError not raised")
+ finally:
+ os.rmdir(tempdir)
+
def test_xslt_unicode(self):
expected = '''
<?xml version="1.0"?>
diff --git a/src/lxml/xslt.pxi b/src/lxml/xslt.pxi
index ee7b0719..ce187a9b 100644
--- a/src/lxml/xslt.pxi
+++ b/src/lxml/xslt.pxi
@@ -745,7 +745,7 @@ cdef class _XSLTResultTree(_ElementTree):
if writer is not None:
writer._exc_context._raise_if_stored()
if r < 0 or rclose < 0:
- python.PyErr_SetFromErrno(XSLTSaveError) # raises
+ python.PyErr_SetFromErrno(IOError) # raises IOError
cdef _saveToStringAndSize(self, xmlChar** s, int* l):
cdef _Document doc