Skip to content
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

Improve ElementPath #75829

Closed
scoder opened this issue Sep 30, 2017 · 7 comments
Closed

Improve ElementPath #75829

scoder opened this issue Sep 30, 2017 · 7 comments
Labels
3.7 expert-XML stdlib type-feature

Comments

@scoder
Copy link
Contributor

@scoder scoder commented Sep 30, 2017

BPO 31648
Nosy @scoder, @serhiy-storchaka
PRs
  • #3835
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-09-30.13:36:57.025>
    created_at = <Date 2017-09-30.08:16:42.055>
    labels = ['expert-XML', 'type-feature', 'library', '3.7']
    title = 'Improve ElementPath'
    updated_at = <Date 2017-09-30.13:36:57.024>
    user = 'https://github.com/scoder'

    bugs.python.org fields:

    activity = <Date 2017-09-30.13:36:57.024>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-30.13:36:57.025>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)', 'XML']
    creation = <Date 2017-09-30.08:16:42.055>
    creator = 'scoder'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31648
    keywords = ['patch']
    message_count = 7.0
    messages = ['303400', '303402', '303403', '303404', '303405', '303408', '303409']
    nosy_count = 3.0
    nosy_names = ['scoder', 'eli.bendersky', 'serhiy.storchaka']
    pr_nums = ['3835']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31648'
    versions = ['Python 3.7']

    @scoder
    Copy link
    Contributor Author

    @scoder scoder commented Sep 30, 2017

    • Allow whitespace around predicate parts, i.e. "[a = 'text']" instead of requiring the less readable "[a='text']".

    • Add support for text comparison of the current node, like "[.='text']".

    Both currently raise "invalid path" exceptions. PR coming.

    @scoder scoder added 3.7 stdlib expert-XML type-feature labels Sep 30, 2017
    @serhiy-storchaka
    Copy link
    Member

    @serhiy-storchaka serhiy-storchaka commented Sep 30, 2017

    Is this feature already implemented in lxml? Is it a part of some wider standard?

    @scoder
    Copy link
    Contributor Author

    @scoder scoder commented Sep 30, 2017

    Well, there's XPath for a standard:
    https://www.w3.org/TR/xpath/

    ElementPath deviates from it in its namespace syntax (it allows "{ns}tag" where XPath requires "p:tag" prefixes), but that's about it. All other differences are basically needless limitations of ElementPath.

    In fact, I had noticed these two limitations in lxml, so I implemented them for the next release. And since ElementPath in ElementTree is still mostly the same as ElementPath in lxml, here's the same thing for ET.

    @serhiy-storchaka
    Copy link
    Member

    @serhiy-storchaka serhiy-storchaka commented Sep 30, 2017

    I think the break in the loop for [.='text'] is not correct.

    >>> from xml.etree import ElementTree as ET
    >>> e = ET.XML('<root><a><b>text</b></a><a><b></b></a><a><b>text</b></a></root>')
    >>> list(e.findall('.//a[b="text"]'))
    [<Element 'a' at 0x7ffadb305d58>, <Element 'a' at 0x7ffadb305f58>]
    >>> list(e.findall('.//a[.="text"]'))
    [<Element 'a' at 0x7ffadb305d58>]

    I expect that findall() finds all matched elements, not just the first one. Both above requests should return the same result.

    @scoder
    Copy link
    Contributor Author

    @scoder scoder commented Sep 30, 2017

    Thanks for noticing. I added a test and fixed it.

    @serhiy-storchaka
    Copy link
    Member

    @serhiy-storchaka serhiy-storchaka commented Sep 30, 2017

    New changeset 101a5e8 by Serhiy Storchaka (scoder) in branch 'master':
    bpo-31648: Improve ElementPath (bpo-3835)
    101a5e8

    @serhiy-storchaka
    Copy link
    Member

    @serhiy-storchaka serhiy-storchaka commented Sep 30, 2017

    Thank you for your contribution Stefan! Good improvement.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 expert-XML stdlib type-feature
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants