Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def series(css):
selector, = parse(':nth-child(%s)' % css)
args = selector.parsed_tree.arguments
try:
return parse_series(args)
except ValueError:
return None
def specificity(css):
selectors = parse(css)
assert len(selectors) == 1
return selectors[0].specificity()
def repr_parse(css):
selectors = parse(css)
for selector in selectors:
assert selector.pseudo_element is None
return [repr(selector.parsed_tree).replace("(u'", "('")
for selector in selectors]
def get_error(css):
try:
parse(css)
except SelectorSyntaxError:
# Py2, Py3, ...
return str(sys.exc_info()[1]).replace("(u'", "('")
def series(css):
selector, = parse(':nth-child(%s)' % css)
args = selector.parsed_tree.arguments
try:
return parse_series(args)
except ValueError:
return None
def specificity(css):
selectors = parse(css)
assert len(selectors) == 1
return selectors[0].specificity()
def get_error(css):
try:
parse(css)
except SelectorSyntaxError:
# Py2, Py3, ...
return str(sys.exc_info()[1]).replace("(u'", "('")
def _token_list_matches_tree(self, token_list):
"""
Returns whether the token list matches the HTML tree
:param selector: A Token list to check
:type selector: list of Token objects
:returns: True if the token list has matches in self.tree
:rtype: bool
"""
try:
parsed_selector = cssselect.parse(
''.join(token.as_css() for token in token_list))[0]
return bool(
self.tree.xpath(
self.xpath_translator.selector_to_xpath(parsed_selector)))
except:
# On error, assume the selector matches the tree
return True