How to use the soupsieve.css_types.SelectorTag function in soupsieve

To help you get started, we’ve selected a few soupsieve examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facelessuser / soupsieve / soupsieve / css_parser.py View on Github external
"""Parse combinator tokens."""

        combinator = m.group('relation').strip()
        if not combinator:
            combinator = WS_COMBINATOR
        if not has_selector:
            raise SelectorSyntaxError(
                "The combinator '{}' at postion {}, must have a selector before it".format(combinator, index),
                self.pattern,
                index
            )

        if combinator == COMMA_COMBINATOR:
            if not sel.tag and not is_pseudo:
                # Implied `*`
                sel.tag = ct.SelectorTag('*', None)
            sel.relations.extend(relations)
            selectors.append(sel)
            del relations[:]
        else:
            sel.relations.extend(relations)
            sel.rel_type = combinator
            del relations[:]
            relations.append(sel)
        sel = _Selector()

        has_selector = False
        return has_selector, sel
github facelessuser / soupsieve / soupsieve / css_parser.py View on Github external
index = m.end(0)
        except StopIteration:
            pass

        if is_open and not closed:
            raise SelectorSyntaxError(
                "Unclosed pseudo-class at position {}".format(index),
                self.pattern,
                index
            )

        if has_selector:
            if not sel.tag and not is_pseudo:
                # Implied `*`
                sel.tag = ct.SelectorTag('*', None)
            if is_relative:
                sel.rel_type = rel_type
                selectors[-1].relations.append(sel)
            else:
                sel.relations.extend(relations)
                del relations[:]
                selectors.append(sel)
        else:
            # We will always need to finish a selector when `:has()` is used as it leads with combining.
            raise SelectorSyntaxError(
                'Expected a selector at position {}'.format(index),
                self.pattern,
                index
            )

        # Some patterns require additional logic, such as default. We try to make these the
github facelessuser / soupsieve / soupsieve / css_types.py View on Github external
return self.selectors[index]


def _pickle(p):
    return p.__base__(), tuple([getattr(p, s) for s in p.__slots__[:-1]])


def pickle_register(obj):
    """Allow object to be pickled."""

    copyreg.pickle(obj, _pickle)


pickle_register(Selector)
pickle_register(SelectorNull)
pickle_register(SelectorTag)
pickle_register(SelectorAttribute)
pickle_register(SelectorContains)
pickle_register(SelectorNth)
pickle_register(SelectorLang)
pickle_register(SelectorList)
github facelessuser / soupsieve / soupsieve / css_types.py View on Github external
def __init__(self, name, prefix):
        """Initialize."""

        super(SelectorTag, self).__init__(
            name=name,
            prefix=prefix
        )
github facelessuser / soupsieve / soupsieve / css_parser.py View on Github external
def parse_tag_pattern(self, sel, m, has_selector):
        """Parse tag pattern from regex match."""

        prefix = css_unescape(m.group('tag_ns')[:-1]) if m.group('tag_ns') else None
        tag = css_unescape(m.group('tag_name'))
        sel.tag = ct.SelectorTag(tag, prefix)
        has_selector = True
        return has_selector