Skip to content

Commit 7b03ae2

Browse files
author
annbgn
committed
run formatter
1 parent 7bcc7e0 commit 7b03ae2

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

cssselect/parser.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,23 @@ class Relation(object):
254254
"""
255255
Represents selector:has(subselector)
256256
"""
257+
257258
def __init__(self, selector, subselector):
258259
self.selector = selector
259260
self.subselector = subselector
260261

261262
def __repr__(self):
262-
return '%s[%r:has(%r)]' % (
263-
self.__class__.__name__, self.selector, self.subselector)
263+
return "%s[%r:has(%r)]" % (
264+
self.__class__.__name__,
265+
self.selector,
266+
self.subselector,
267+
)
264268

265269
def canonical(self):
266270
subsel = self.subselector.canonical()
267271
if len(subsel) > 1:
268-
subsel = subsel.lstrip('*')
269-
return '%s:has(%s)' % (self.selector.canonical(), subsel)
272+
subsel = subsel.lstrip("*")
273+
return "%s:has(%s)" % (self.selector.canonical(), subsel)
270274

271275
def specificity(self):
272276
a1, b1, c1 = self.selector.specificity()
@@ -564,7 +568,7 @@ def parse_simple_selector(stream, inside_negation=False):
564568
if next != ('DELIM', ')'):
565569
raise SelectorSyntaxError("Expected ')', got %s" % (next,))
566570
result = Negation(result, argument)
567-
elif ident.lower() == 'has':
571+
elif ident.lower() == "has":
568572
arguments = parse_relative_selector(stream)
569573
result = Relation(result, arguments)
570574
else:
@@ -586,25 +590,24 @@ def parse_arguments(stream):
586590
if next.type in ('IDENT', 'STRING', 'NUMBER') or next in [
587591
('DELIM', '+'), ('DELIM', '-')]:
588592
arguments.append(next)
589-
elif next == ('DELIM', ')'):
593+
elif next == ("DELIM", ")"):
590594
return arguments
591595
else:
592-
raise SelectorSyntaxError(
593-
"Expected an argument, got %s" % (next,))
596+
raise SelectorSyntaxError("Expected an argument, got %s" % (next,))
594597

595598

596599
def parse_relative_selector(stream):
597600
arguments = []
598601
stream.skip_whitespace()
599602
next = stream.next()
600-
if next in [('DELIM', '+'), ('DELIM', '-'), ('DELIM', '>'), ('DELIM', '~')]:
603+
if next in [("DELIM", "+"), ("DELIM", "-"), ("DELIM", ">"), ("DELIM", "~")]:
601604
arguments.append(next)
602-
elif next.type in ('IDENT', 'STRING', 'NUMBER'):
605+
elif next.type in ("IDENT", "STRING", "NUMBER"):
603606
arguments.append(Element(element=next.value))
604607
while 1:
605608
stream.skip_whitespace()
606609
next = stream.next()
607-
if next.type in ('IDENT', 'STRING', 'NUMBER'):
610+
if next.type in ("IDENT", "STRING", "NUMBER"):
608611
arguments.append(Element(element=next.value))
609612
elif next == ('DELIM', ')'):
610613
return arguments

cssselect/xpath.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def join(self, combiner, other, closing_combiner=None):
8383
if other.path != '*/':
8484
path += other.path
8585
self.path = path
86-
self.element = other.element + closing_combiner if closing_combiner else other.element
86+
self.element = (
87+
other.element + closing_combiner if closing_combiner else other.element
88+
)
8789
self.condition = other.condition
8890
return self
8991

@@ -277,11 +279,14 @@ def xpath_relation(self, relation):
277279
xpath = self.xpath(relation.selector)
278280
combinator, *subselector = relation.subselector
279281
if not subselector:
280-
combinator.value = ' '
282+
combinator.value = " "
281283
right = self.xpath(combinator)
282284
else:
283285
right = self.xpath(subselector[0])
284-
method = getattr(self, 'xpath_relation_%s_combinator' % self.combinator_mapping[combinator.value])
286+
method = getattr(
287+
self,
288+
"xpath_relation_%s_combinator" % self.combinator_mapping[combinator.value],
289+
)
285290
return method(xpath, right)
286291

287292
def xpath_function(self, function):
@@ -383,27 +388,34 @@ def xpath_indirect_adjacent_combinator(self, left, right):
383388

384389
def xpath_relation_descendant_combinator(self, left, right):
385390
"""right is a child, grand-child or further descendant of left; select left"""
386-
return left.join('/descendant-or-self::', right, closing_combiner='/ancestor-or-self::' + left.element)
391+
return left.join(
392+
"/descendant-or-self::",
393+
right,
394+
closing_combiner="/ancestor-or-self::" + left.element,
395+
)
387396

388397
def xpath_relation_child_combinator(self, left, right):
389398
"""right is an immediate child of left; select left"""
390-
return left.join('[./', right, closing_combiner=']')
399+
return left.join("[./", right, closing_combiner="]")
391400

392401
def xpath_relation_direct_adjacent_combinator(self, left, right):
393402
"""right is a sibling immediately after left; select left"""
394403
left_copy = copy.copy(left)
395-
xpath = left.join('/following-sibling::', right)
404+
xpath = left.join("/following-sibling::", right)
396405
xpath.add_name_test()
397-
xpath.add_condition('position() = 1')
406+
xpath.add_condition("position() = 1")
398407

399-
xpath = xpath.join('/preceding-sibling::', left_copy)
408+
xpath = xpath.join("/preceding-sibling::", left_copy)
400409
xpath.add_name_test()
401-
return xpath.add_condition('position() = 1')
410+
return xpath.add_condition("position() = 1")
402411

403412
def xpath_relation_indirect_adjacent_combinator(self, left, right):
404413
"""right is a sibling after left, immediately or not; select left"""
405-
return left.join('/following-sibling::', right, closing_combiner='/preceding-sibling::'+left.element)
406-
414+
return left.join(
415+
"/following-sibling::",
416+
right,
417+
closing_combiner="/preceding-sibling::" + left.element,
418+
)
407419

408420
# Function: dispatch by function/pseudo-class name
409421

0 commit comments

Comments
 (0)