mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-23 01:52:48 +03:00
io: Pass error codes from xmlFileOpenReal to xmlNewInputFromFile
This allows to report the reason why opening a file failed to the parser context and improve error messages. Now we can also remove the stat call before opening a file.
This commit is contained in:
@@ -10,7 +10,7 @@ import libxml2
|
||||
# Memory debug specific
|
||||
libxml2.debugMemory(1)
|
||||
|
||||
expect='--> I/O --> warning : --> failed to load external entity "missing.xml"\n'
|
||||
expect='--> I/O --> warning : --> failed to load "missing.xml": No such file or directory\n'
|
||||
err=""
|
||||
def callback(ctx, str):
|
||||
global err
|
||||
|
@@ -91,7 +91,7 @@ run_test(desc="Loading entity without custom callback",
|
||||
exp_status="not loaded", exp_err=[
|
||||
(-1, "I/O "),
|
||||
(-1, "warning : "),
|
||||
(-1, "failed to load external entity \"py://strings/xml/sample.xml\"\n")
|
||||
(-1, "failed to load \"py://strings/xml/sample.xml\": No such file or directory\n")
|
||||
])
|
||||
|
||||
# Register handler and try to load the same entity
|
||||
@@ -99,7 +99,7 @@ libxml2.registerInputCallback(my_input_cb)
|
||||
run_test(desc="Loading entity with custom callback",
|
||||
docpath=startURL, catalog=None,
|
||||
exp_status="loaded", exp_err=[
|
||||
( 3, "Attempt to load network entity http://example.com/dtds/sample.dtd"),
|
||||
( 3, 'failed to load "http://example.com/dtds/sample.dtd": Attempt to load network entity\n'),
|
||||
( 4, "Entity 'sample.entity' not defined\n")
|
||||
])
|
||||
|
||||
@@ -112,7 +112,7 @@ run_test(desc="Loading entity and unregistering callback",
|
||||
docpath=startURL, catalog=catURL,
|
||||
test_callback=lambda: libxml2.popInputCallbacks(),
|
||||
exp_status="loaded", exp_err=[
|
||||
( 3, "failed to load external entity \"py://strings/dtds/sample.dtd\"\n"),
|
||||
( 3, "failed to load \"py://strings/dtds/sample.dtd\": No such file or directory\n"),
|
||||
( 4, "Entity 'sample.entity' not defined\n")
|
||||
])
|
||||
|
||||
@@ -122,7 +122,7 @@ run_test(desc="Retry loading document after unregistering callback",
|
||||
exp_status="not loaded", exp_err=[
|
||||
(-1, "I/O "),
|
||||
(-1, "warning : "),
|
||||
(-1, "failed to load external entity \"py://strings/xml/sample.xml\"\n")
|
||||
(-1, "failed to load \"py://strings/xml/sample.xml\": No such file or directory\n")
|
||||
])
|
||||
|
||||
# But should be able to read standard I/O yet...
|
||||
@@ -142,7 +142,7 @@ run_test(desc="Loading using standard i/o after unregistering all callbacks",
|
||||
exp_status="not loaded", exp_err=[
|
||||
(-1, "I/O "),
|
||||
(-1, "warning : "),
|
||||
(-1, "failed to load external entity \"tst.xml\"\n")
|
||||
(-1, "failed to load \"tst.xml\": No such file or directory\n")
|
||||
])
|
||||
|
||||
print("OK")
|
||||
|
@@ -58,8 +58,8 @@ class TestCase(unittest.TestCase):
|
||||
("dummy.xml",None,0),
|
||||
libxml2.treeError,
|
||||
domain=libxml2.XML_FROM_IO,
|
||||
code=libxml2.XML_IO_LOAD_ERROR,
|
||||
message='failed to load external entity "dummy.xml"\n',
|
||||
code=libxml2.XML_IO_ENOENT,
|
||||
message='failed to load "dummy.xml": No such file or directory\n',
|
||||
level=libxml2.XML_ERR_WARNING,
|
||||
file=None,
|
||||
line=0)
|
||||
|
Reference in New Issue
Block a user