Skip to content

Commit 95e655d

Browse files
committed
Reduce nesting level in the parser.
1 parent 35a2f57 commit 95e655d

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

cssselect/parser.py

+25-28
Original file line numberDiff line numberDiff line change
@@ -373,36 +373,33 @@ def parse_simple_selector(stream, inside_negation=False):
373373
# Any new pseudo-element must have two.
374374
pseudo_element = ident
375375
continue
376-
if stream.peek() == '(':
377-
stream.next()
378-
stream.skip_whitespace()
379-
is_negation = ident.lower() == 'not'
380-
if is_negation:
381-
if inside_negation:
382-
raise SelectorSyntaxError('Got nested :not()')
383-
argument, argument_pseudo_element = parse_simple_selector(
384-
stream, inside_negation=True)
385-
if argument_pseudo_element:
386-
raise SelectorSyntaxError(
387-
'Pseudo-elements are not allowed inside :not()')
388-
else:
389-
peek = stream.peek()
390-
if isinstance(peek, (Symbol, String)):
391-
argument = stream.next()
392-
else:
393-
raise SelectorSyntaxError(
394-
"Expected argument, got '%s'" % peek)
395-
stream.skip_whitespace()
396-
next = stream.next()
397-
if not next == ')':
376+
if stream.peek() != '(':
377+
result = Pseudo(result, ident)
378+
continue
379+
stream.next()
380+
stream.skip_whitespace()
381+
if ident.lower() == 'not':
382+
if inside_negation:
383+
raise SelectorSyntaxError('Got nested :not()')
384+
argument, argument_pseudo_element = parse_simple_selector(
385+
stream, inside_negation=True)
386+
if argument_pseudo_element:
398387
raise SelectorSyntaxError(
399-
"Expected ')', got '%s'" % next)
400-
if is_negation:
401-
result = Negation(result, argument)
402-
else:
403-
result = Function(result, ident, argument)
388+
'Pseudo-elements are not allowed inside :not()')
389+
result = Negation(result, argument)
404390
else:
405-
result = Pseudo(result, ident)
391+
peek = stream.peek()
392+
if isinstance(peek, (Symbol, String)):
393+
argument = stream.next()
394+
else:
395+
raise SelectorSyntaxError(
396+
"Expected argument, got '%s'" % peek)
397+
result = Function(result, ident, argument)
398+
stream.skip_whitespace()
399+
next = stream.next()
400+
if not next == ')':
401+
raise SelectorSyntaxError(
402+
"Expected ')', got '%s'" % next)
406403
continue
407404
else:
408405
raise SelectorSyntaxError(

0 commit comments

Comments
 (0)