problem with :contains selector [1.2.1 regression]
The switch to cssselect introduced a bug with the :contains selector, which doesn't seem to work right in JQueryTranslator.
In cssselect, :contains() works fine:
>>> import cssselect.xpath >>> t = cssselect.xpath.GenericTranslator() >>> t.css_to_xpath(':contains("Your first name and initial")') u"descendant-or-self::*[contains(string(.), 'Your first name and initial')]"
In JQueryTranslator, :contains() is broken:
>>> from pyquery.cssselectpatch import JQueryTranslator >>> t = JQueryTranslator() >>> t.css_to_xpath(':contains("Your first name and initial")') u"descendant-or-self::*[contains(text(), '**[<STRING 'Your first name and initial' at 10>]**')]"
The easiest fix is just to remove xpath_contains_function from cssselectpatch.py entirely, and let it fall through to GenericTranslator. But if there's some reason not to do that, it looks like you need to do the string conversion the way it's done in GenericTranslator:
'contains(string(.), %s)' % self.xpath_literal(value)
It might also be worth taking a look at xpath_lt_function etc, which also seem to be accessing function.arguments directly in a way that might not work so well -- I didn't actually test those ones.
VERSIONS: I reproduced this bug on OS X 10.7.4, Python 2.7.1, pyquery 1.2.1. I wasn't able to reproduce it with ActivePython on Windows -- but I might have just been looking at an earlier version of pyquery or something.
(This may have been a little confused -- let me know if you need more details.)