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

Let extended translators override what XPathExpr class is used #22

Merged
merged 1 commit into from
Jan 10, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cssselect/xpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down