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

Adding docstrings for csstranslator #20

Merged
merged 2 commits into from
Aug 24, 2015
Merged
Changes from 1 commit
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
14 changes: 11 additions & 3 deletions parsel/csstranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,27 @@ def join(self, combiner, other):


class TranslatorMixin(object):
"""This mixin adds support to CSS pseudo elements via dynamic dispatch.

Currently supported pseudo-elements are ``::text`` and ``::attr(ATTR_NAME)``.
"""

def xpath_element(self, selector):
xpath = super(TranslatorMixin, self).xpath_element(selector)
return XPathExpr.from_xpath(xpath)

def xpath_pseudo_element(self, xpath, pseudo_element):
"""
Dispatch method that transform XPath to support pseudo-element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transforms

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Спасибо!

"""
if isinstance(pseudo_element, FunctionalPseudoElement):
method = 'xpath_%s_functional_pseudo_element' % (
pseudo_element.name.replace('-', '_'))
method = _unicode_safe_getattr(self, method, None)
if not method:
raise ExpressionError(
"The functional pseudo-element ::%s() is unknown"
% pseudo_element.name)
% pseudo_element.name)
xpath = method(xpath, pseudo_element)
else:
method = 'xpath_%s_simple_pseudo_element' % (
Expand All @@ -69,12 +76,14 @@ def xpath_pseudo_element(self, xpath, pseudo_element):
return xpath

def xpath_attr_functional_pseudo_element(self, xpath, function):
"""Support selecting attribute values using ::attr() pseudo-element
"""
if function.argument_types() not in (['STRING'], ['IDENT']):
raise ExpressionError(
"Expected a single string or ident for ::attr(), got %r"
% function.arguments)
return XPathExpr.from_xpath(xpath,
attribute=function.arguments[0].value)
attribute=function.arguments[0].value)

def xpath_text_simple_pseudo_element(self, xpath):
"""Support selecting text nodes using ::text pseudo-element"""
Expand All @@ -87,4 +96,3 @@ class GenericTranslator(TranslatorMixin, OriginalGenericTranslator):

class HTMLTranslator(TranslatorMixin, OriginalHTMLTranslator):
pass