@@ -254,19 +254,23 @@ class Relation(object):
254
254
"""
255
255
Represents selector:has(subselector)
256
256
"""
257
+
257
258
def __init__ (self , selector , subselector ):
258
259
self .selector = selector
259
260
self .subselector = subselector
260
261
261
262
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
+ )
264
268
265
269
def canonical (self ):
266
270
subsel = self .subselector .canonical ()
267
271
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 )
270
274
271
275
def specificity (self ):
272
276
a1 , b1 , c1 = self .selector .specificity ()
@@ -564,7 +568,7 @@ def parse_simple_selector(stream, inside_negation=False):
564
568
if next != ('DELIM' , ')' ):
565
569
raise SelectorSyntaxError ("Expected ')', got %s" % (next ,))
566
570
result = Negation (result , argument )
567
- elif ident .lower () == ' has' :
571
+ elif ident .lower () == " has" :
568
572
arguments = parse_relative_selector (stream )
569
573
result = Relation (result , arguments )
570
574
else :
@@ -586,25 +590,24 @@ def parse_arguments(stream):
586
590
if next .type in ('IDENT' , 'STRING' , 'NUMBER' ) or next in [
587
591
('DELIM' , '+' ), ('DELIM' , '-' )]:
588
592
arguments .append (next )
589
- elif next == (' DELIM' , ')' ):
593
+ elif next == (" DELIM" , ")" ):
590
594
return arguments
591
595
else :
592
- raise SelectorSyntaxError (
593
- "Expected an argument, got %s" % (next ,))
596
+ raise SelectorSyntaxError ("Expected an argument, got %s" % (next ,))
594
597
595
598
596
599
def parse_relative_selector (stream ):
597
600
arguments = []
598
601
stream .skip_whitespace ()
599
602
next = stream .next ()
600
- if next in [(' DELIM' , '+' ), (' DELIM' , '-' ), (' DELIM' , '>' ), (' DELIM' , '~' )]:
603
+ if next in [(" DELIM" , "+" ), (" DELIM" , "-" ), (" DELIM" , ">" ), (" DELIM" , "~" )]:
601
604
arguments .append (next )
602
- elif next .type in (' IDENT' , ' STRING' , ' NUMBER' ):
605
+ elif next .type in (" IDENT" , " STRING" , " NUMBER" ):
603
606
arguments .append (Element (element = next .value ))
604
607
while 1 :
605
608
stream .skip_whitespace ()
606
609
next = stream .next ()
607
- if next .type in (' IDENT' , ' STRING' , ' NUMBER' ):
610
+ if next .type in (" IDENT" , " STRING" , " NUMBER" ):
608
611
arguments .append (Element (element = next .value ))
609
612
elif next == ('DELIM' , ')' ):
610
613
return arguments
0 commit comments