-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
plugin.api.validate: rework XML validators #4732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gravyboat
merged 2 commits into
streamlink:master
from
bastimeyer:plugin/api/validate/xpath-args
Aug 13, 2022
Merged
plugin.api.validate: rework XML validators #4732
gravyboat
merged 2 commits into
streamlink:master
from
bastimeyer:plugin/api/validate/xpath-args
Aug 13, 2022
+147
−28
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Add supported `Element.xpath()` keywords to `validate.xml_xpath()` - `namespaces` for defining prefix-namespace mappings - `extensions` for defining custom XPath functions in Python - `smart_strings` for disabling element tree references on any string return values that will be kept in memory - `**variables` for being able to define custom XPath variables instead of having to embed strings in the XPath query itself - Add `namespaces`, `extensions` and `**variables` keywords to `validate.xml_xpath_string()` and always disable `smart_strings` - Add `namespaces` to `validate.xml_find()`, `validate.xml_findall()` and `validate.xml_findtext()` - Handle XPath evaluation errors via `lxml.etree.XPathError` and ElementPath syntax errors via `SyntaxError` - Update error messages of ElementPath-based validators - Remove unneeded `iselement` validation at the end of `xml_find()` - Fix docstrings of both XPath- and ElementPath-based validators - Add tests for the newly added keywords and XPath evaluation errors
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Aug 15, 2022
- Add supported `Element.xpath()` keywords to `validate.xml_xpath()` - `namespaces` for defining prefix-namespace mappings - `extensions` for defining custom XPath functions in Python - `smart_strings` for disabling element tree references on any string return values that will be kept in memory - `**variables` for being able to define custom XPath variables instead of having to embed strings in the XPath query itself - Add `namespaces`, `extensions` and `**variables` keywords to `validate.xml_xpath_string()` and always disable `smart_strings` - Add `namespaces` to `validate.xml_find()`, `validate.xml_findall()` and `validate.xml_findtext()` - Handle XPath evaluation errors via `lxml.etree.XPathError` and ElementPath syntax errors via `SyntaxError` - Update error messages of ElementPath-based validators - Remove unneeded `iselement` validation at the end of `xml_find()` - Fix docstrings of both XPath- and ElementPath-based validators - Add tests for the newly added keywords and XPath evaluation errors
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Aug 15, 2022
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Aug 17, 2022
- Add supported `Element.xpath()` keywords to `validate.xml_xpath()` - `namespaces` for defining prefix-namespace mappings - `extensions` for defining custom XPath functions in Python - `smart_strings` for disabling element tree references on any string return values that will be kept in memory - `**variables` for being able to define custom XPath variables instead of having to embed strings in the XPath query itself - Add `namespaces`, `extensions` and `**variables` keywords to `validate.xml_xpath_string()` and always disable `smart_strings` - Add `namespaces` to `validate.xml_find()`, `validate.xml_findall()` and `validate.xml_findtext()` - Handle XPath evaluation errors via `lxml.etree.XPathError` and ElementPath syntax errors via `SyntaxError` - Update error messages of ElementPath-based validators - Remove unneeded `iselement` validation at the end of `xml_find()` - Fix docstrings of both XPath- and ElementPath-based validators - Add tests for the newly added keywords and XPath evaluation errors
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Aug 17, 2022
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Sep 3, 2022
- Add supported `Element.xpath()` keywords to `validate.xml_xpath()` - `namespaces` for defining prefix-namespace mappings - `extensions` for defining custom XPath functions in Python - `smart_strings` for disabling element tree references on any string return values that will be kept in memory - `**variables` for being able to define custom XPath variables instead of having to embed strings in the XPath query itself - Add `namespaces`, `extensions` and `**variables` keywords to `validate.xml_xpath_string()` and always disable `smart_strings` - Add `namespaces` to `validate.xml_find()`, `validate.xml_findall()` and `validate.xml_findtext()` - Handle XPath evaluation errors via `lxml.etree.XPathError` and ElementPath syntax errors via `SyntaxError` - Update error messages of ElementPath-based validators - Remove unneeded `iselement` validation at the end of `xml_find()` - Fix docstrings of both XPath- and ElementPath-based validators - Add tests for the newly added keywords and XPath evaluation errors
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Sep 3, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Element.xpath()
keywords tovalidate.xml_xpath()
namespaces
for defining prefix-namespace mappingsextensions
for defining custom XPath functions in Pythonsmart_strings
for disabling element tree references on any stringreturn values that will be kept in memory
**variables
for being able to define custom XPath variablesinstead of having to embed strings in the XPath query itself
namespaces
,extensions
and**variables
keywords tovalidate.xml_xpath_string()
and always disablesmart_strings
namespaces
tovalidate.xml_find()
,validate.xml_findall()
and
validate.xml_findtext()
lxml.etree.XPathError
and ElementPath syntax errors via
SyntaxError
iselement
validation at the end ofxml_find()
The main intention of this PR is adding support for variables in XPath queries, hence the plugin changes included in the second commit. Since that required adding a keyword dict to the XPath validators, I decided to add the missing options to all the XML validators, even if it's probably not that useful, like namespaces, extensions and smart_strings. Having disabled smart_strings on
xml_xpath_string
is a nice optimization though. The changes also fix some docstring issues. See the added tests for clarification of all the changes.