1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-08-04 12:21:55 +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:
Nick Wellnhofer
2023-12-19 15:41:37 +01:00
parent b2dbcc432b
commit 7e511f35f1
14 changed files with 228 additions and 124 deletions

View File

@ -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")