Skip to content

Commit

Permalink
Run black (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
wRAR committed Aug 2, 2021
1 parent dc2eb7d commit d20db09
Show file tree
Hide file tree
Showing 17 changed files with 932 additions and 597 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- python-version: 3.9
env:
TOXENV: typing
- python-version: 3.9
env:
TOXENV: black

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ def pytest_collection_modifyitems(session, config, items):
# Avoid executing tests when executing `--flake8` flag (pytest-flake8)
try:
from pytest_flake8 import Flake8Item
if config.getoption('--flake8'):

if config.getoption("--flake8"):
items[:] = [item for item in items if isinstance(item, Flake8Item)]
except ImportError:
pass
14 changes: 7 additions & 7 deletions parsel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
or CSS selectors
"""

__author__ = 'Scrapy project'
__email__ = 'info@scrapy.org'
__version__ = '1.6.0'
__author__ = "Scrapy project"
__email__ = "info@scrapy.org"
__version__ = "1.6.0"
__all__ = [
'Selector',
'SelectorList',
'css2xpath',
'xpathfuncs',
"Selector",
"SelectorList",
"css2xpath",
"xpathfuncs",
]

from parsel.selector import Selector, SelectorList # NOQA
Expand Down
46 changes: 24 additions & 22 deletions parsel/csstranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def from_xpath(cls, xpath, textnode=False, attribute=None):
def __str__(self):
path = super().__str__()
if self.textnode:
if path == '*':
path = 'text()'
elif path.endswith('::*/*'):
path = path[:-3] + 'text()'
if path == "*":
path = "text()"
elif path.endswith("::*/*"):
path = path[:-3] + "text()"
else:
path += '/text()'
path += "/text()"

if self.attribute is not None:
if path.endswith('::*/*'):
if path.endswith("::*/*"):
path = path[:-2]
path += '/@%s' % self.attribute
path += "/@%s" % self.attribute

return path

Expand All @@ -58,34 +58,36 @@ def xpath_pseudo_element(self, xpath, pseudo_element):
Dispatch method that transforms XPath to support pseudo-element
"""
if isinstance(pseudo_element, FunctionalPseudoElement):
method = 'xpath_%s_functional_pseudo_element' % (
pseudo_element.name.replace('-', '_'))
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' % (
pseudo_element.replace('-', '_'))
method = "xpath_%s_simple_pseudo_element" % (
pseudo_element.replace("-", "_")
)
method = _unicode_safe_getattr(self, method, None)
if not method:
raise ExpressionError(
"The pseudo-element ::%s is unknown"
% pseudo_element)
"The pseudo-element ::%s is unknown" % pseudo_element
)
xpath = method(xpath)
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']):
"""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)
% function.arguments
)
return XPathExpr.from_xpath(xpath, attribute=function.arguments[0].value)

def xpath_text_simple_pseudo_element(self, xpath):
"""Support selecting text nodes using ::text pseudo-element"""
Expand All @@ -94,13 +96,13 @@ def xpath_text_simple_pseudo_element(self, xpath):

class GenericTranslator(TranslatorMixin, OriginalGenericTranslator):
@lru_cache(maxsize=256)
def css_to_xpath(self, css, prefix='descendant-or-self::'):
def css_to_xpath(self, css, prefix="descendant-or-self::"):
return super().css_to_xpath(css, prefix)


class HTMLTranslator(TranslatorMixin, OriginalHTMLTranslator):
@lru_cache(maxsize=256)
def css_to_xpath(self, css, prefix='descendant-or-self::'):
def css_to_xpath(self, css, prefix="descendant-or-self::"):
return super().css_to_xpath(css, prefix)


Expand Down

0 comments on commit d20db09

Please sign in to comment.