1"""CSS Selectors based on XPath. 2 3This module supports selecting XML/HTML tags based on CSS selectors. 4See the `CSSSelector` class for details. 5 6This is a thin wrapper around cssselect 0.7 or later. 7""" 8 9from__future__importabsolute_import 10 11from.importetree 12try: 13importcssselectasexternal_cssselect 14exceptImportError: 15raiseImportError( 16'cssselect does not seem to be installed. ' 17'See http://packages.python.org/cssselect/') 18 19 20SelectorSyntaxError=external_cssselect.SelectorSyntaxError 21ExpressionError=external_cssselect.ExpressionError 22SelectorError=external_cssselect.SelectorError 23 24 25__all__=['SelectorSyntaxError','ExpressionError','SelectorError', 26'CSSSelector'] 27 28
34# Defined there, removed in later drafts: 35# http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors 36iffunction.argument_types()notin(['STRING'],['IDENT']): 37raiseExpressionError( 38"Expected a single string or ident for :contains(), got %r" 39%function.arguments) 40value=function.arguments[0].value 41returnxpath.add_condition( 42'contains(__lxml_internal_css:lower-case(string(.)), %s)' 43%self.xpath_literal(value.lower()))