Issue #43 resolved

cssselectpatch will break in lxml 2.4

Simon Sapin
created an issue

Hi,

I see that pyquery uses internal, undocumented objects from lxml.cssselect to monkey-patch them and add support for additional pseudo-classes.

This will break with lxml 2.4 (not released yet.)

I recently took over cssselect and made it an independent project: http://packages.python.org/cssselect/

In 2.4, lxml.cssselect becomes a thin wrapper around the external cssselect, with most of the internal objects gone.

The good news is that the new cssselect can be used with any lxml version (before or after 2.4) if you avoid lxml.cssselect and use XPath explicitly. It also introduces "translator" classes that can be inherited from to add pseudo-classes or change the existing ones, without monkey-patching. pyquery is the typical use case.

Although I don’t have a patch, I think it would be very straightforward to adapt the current cssselectpatch to the new cssselect. The details are in the documentation (and mostly in the source) but I can help if you want.

Comments (8)

  1. Gael Pasgrimaud

    Looks good to me. Unfortunately I cant add you as a commiter. Maybe Olivier will do that if he still looking at the notifications... ;) But feel free to submit a pull request. I'll merge it. Just be sure to get all test running and don't forget to add an entry to the CHANGES logs.

  2. Simon Sapin reporter

    Well, I wanted to tell you when I noticed that my changes would break something, but I don’t use pyquery...

    However if cssselect can be improved to make it easier to use for you, I’m happy to help there.

  3. Simon Sapin reporter

    Is add_post_contidition the only addition to XPathExpr? What does it do exactly?

    If I understand correctly, the resulting xpath expressions are like path[condition][post_condition] Is it different from path[condition and post_condition] ?

  4. Log in to comment