Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #22 from dangra/xpathexpr_cls

Let extended translators override what XPathExpr class is used
  • Loading branch information...
commit 8cf8755675ccbce6f4af78c69d8df014756f3e52 2 parents 653a5a5 + 91e752d
@SimonSapin authored
Showing with 5 additions and 2 deletions.
  1. +5 −2 cssselect/xpath.py
View
7 cssselect/xpath.py
@@ -146,6 +146,9 @@ class GenericTranslator(object):
lower_case_attribute_names = False
lower_case_attribute_values = False
+ # class used to represent and xpath expression
+ xpathexpr_cls = XPathExpr
+
def css_to_xpath(self, css, prefix='descendant-or-self::'):
"""Translate a *group of selectors* to XPath.
@@ -190,7 +193,7 @@ def selector_to_xpath(self, selector, prefix='descendant-or-self::'):
if not tree:
raise TypeError('Expected a parsed selector, got %r' % (selector,))
xpath = self.xpath(tree)
- assert isinstance(xpath, XPathExpr) # help debug a missing 'return'
+ assert isinstance(xpath, self.xpathexpr_cls) # help debug a missing 'return'
return (prefix or '') + _unicode(xpath)
@staticmethod
@@ -305,7 +308,7 @@ def xpath_element(self, selector):
# http://www.w3.org/TR/css3-namespace/#prefixes
element = '%s:%s' % (selector.namespace, element)
safe = safe and is_safe_name(selector.namespace)
- xpath = XPathExpr(element=element)
+ xpath = self.xpathexpr_cls(element=element)
if not safe:
xpath.add_name_test()
return xpath
Please sign in to comment.
Something went wrong with that request. Please try again.