<commit_before># coding: utf8
"""
    cssselect.parser
    ================

    Tokenizer, parser and parsed objects for CSS selectors.


    :copyright: (c) 2007-2012 <NAME> and contributors.
                See AUTHORS for more details.
    :license: BSD, see LICENSE for more details.

"""

import sys
import re
import operator


if sys.version_info[0] < 3:
    _unicode = unicode
    _unichr = unichr
else:
    _unicode = str
    _unichr = chr


def ascii_lower(string):
    """Lower-case, but only in the ASCII range."""
    return string.encode('utf8').lower().decode('utf8')


class SelectorError(Exception):
    """Common parent for :class:`SelectorSyntaxError` and
    :class:`ExpressionError`.

    You can just use ``except SelectorError:`` when calling
    :meth:`~GenericTranslator.css_to_xpath` and handle both exceptions types.

    """

class SelectorSyntaxError(SelectorError, SyntaxError):
    """Parsing a selector that does not match the grammar."""


#### Parsed objects

class Selector(object):
    """
    Represents a parsed selector.

    :meth:`~GenericTranslator.selector_to_xpath` accepts this object,
    but ignores :attr:`pseudo_element`. It is the user’s responsibility
    to account for pseudo-elements and reject selectors with unknown
    or unsupported pseudo-elements.

    """
    def __init__(self, tree, pseudo_element=None):
        self.parsed_tree = tree
        if pseudo_element is not None and not isinstance(
                pseudo_element, FunctionalPseudoElement):
            pseudo_element = ascii_lower(pseudo_element)
        #: The identifier for the pseudo-element as a string, or ``None``.
        #:
        #: +-------------------------+----------------+----------------+
        #: |                         | Selector       | Pseudo-element |
        #: +=========================+================+================+
        #: | CSS3 syntax             | ``a::before``  | ``'before'``   |
        #: +-------------------------+----------------+----------------+
        #: | Older syntax            | ``a:before``   | ``'before'``   |
        #: +-------------------------+----------------+----------------+
        #: | From the Lists3_ draft, | ``li::marker`` | ``'marker'``   |
        #: | not in Selectors3       |                |                |
        #: +-------------------------+----------------+----------------+
        #: | Invalid pseudo-class    | ``li:marker``  | ``None``       |<commit_msg>Document functional pseudo-elements.<commit_after># coding: utf8
"""
    cssselect.parser
    ================

    Tokenizer, parser and parsed objects for CSS selectors.


    :copyright: (c) 2007-2012 <NAME> and contributors.
                See AUTHORS for more details.
    :license: BSD, see LICENSE for more details.

"""

import sys
import re
import operator


if sys.version_info[0] < 3:
    _unicode = unicode
    _unichr = unichr
else:
    _unicode = str
    _unichr = chr


def ascii_lower(string):
    """Lower-case, but only in the ASCII range."""
    return string.encode('utf8').lower().decode('utf8')


class SelectorError(Exception):
    """Common parent for :class:`SelectorSyntaxError` and
    :class:`ExpressionError`.

    You can just use ``except SelectorError:`` when calling
    :meth:`~GenericTranslator.css_to_xpath` and handle both exceptions types.

    """

class SelectorSyntaxError(SelectorError, SyntaxError):
    """Parsing a selector that does not match the grammar."""


#### Parsed objects

class Selector(object):
    """
    Represents a parsed selector.

    :meth:`~GenericTranslator.selector_to_xpath` accepts this object,
    but ignores :attr:`pseudo_element`. It is the user’s responsibility
    to account for pseudo-elements and reject selectors with unknown
    or unsupported pseudo-elements.

    """
    def __init__(self, tree, pseudo_element=None):
        self.parsed_tree = tree
        if pseudo_element is not None and not isinstance(
                pseudo_element, FunctionalPseudoElement):
            pseudo_element = ascii_lower(pseudo_element)
        #: A :class:`FunctionalPseudoElement`,
        #: or the identifier for the pseudo-element as a string,
        #  or ``None``.
        #:
        #: +-------------------------+----------------+----------------+
        #: |                         | Selector       | Pseudo-element |
        #: +=========================+================+================+
        #: | CSS3 syntax             | ``a::before``  | ``'before'``   |
        #: +-------------------------+----------------+----------------+
        #: | Older syntax            | ``a:before``   | ``'before'``   |
        #: +-------------------------+----------------+----------------+
        #: | From the Lists3_ draft, | ``li::marker`` | ``'marker'``   |
        #: | not in Selectors3       |                |                |
        #: +-------------------------+----------------+----------------+
        #: | Invalid pseudo-class    | ``li:marker``  | ``None``       |
{'fraction_non_alphanumeric': 0.22982107355864811, 'fraction_numerical': 0.006361829025844931, 'mean_word_length': 1.8248175182481752, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '874952', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1267, 'n_words': 357}