Skip to content

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

Conversation

bastimeyer
Copy link
Member

  • 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

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.

- 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
@gravyboat gravyboat merged commit 156b660 into streamlink:master Aug 13, 2022
@bastimeyer bastimeyer deleted the plugin/api/validate/xpath-args branch August 13, 2022 22:24
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants