# Path: lib/soupsieve/util.py
# class SelectorSyntaxError(SyntaxError):
#     """Syntax error in a CSS selector."""
# 
#     def __init__(self, msg, pattern=None, index=None):
#         """Initialize."""
# 
#         self.line = None
#         self.col = None
#         self.context = None
# 
#         if pattern is not None and index is not None:
#             # Format pattern to show line and column position
#             self.context, self.line, self.col = get_pattern_context(pattern, index)
#             msg = '{}\n  line {}:\n{}'.format(msg, self.line, self.context)
# 
#         super(SelectorSyntaxError, self).__init__(msg)


import re
from . import util
from . import css_match as cm
from . import css_types as ct
from collections import OrderedDict
from .util import SelectorSyntaxError


@util.lru_cache(maxsize=_MAXCACHE)
def _cached_css_compile(pattern, namespaces, custom, flags):
    """Cached CSS compile."""

    custom_selectors = process_custom(custom)
    return cm.SoupSieve(
        pattern,
        CSSParser(pattern, custom=custom_selectors, flags=flags).process_selectors(),
        namespaces,
        custom,
        flags
    )


def _purge_cache():
    """Purge the cache."""

    _cached_css_compile.cache_clear()


def process_custom(custom):
    """Process custom."""

    custom_selectors = {}
    if custom is not None:
        for key, value in custom.items():
            name = util.lower(key)
            if RE_CUSTOM.match(name) is None:

# Path: lib/soupsieve/util.py
# class SelectorSyntaxError(SyntaxError):
#     """Syntax error in a CSS selector."""
# 
#     def __init__(self, msg, pattern=None, index=None):
#         """Initialize."""
# 
#         self.line = None
#         self.col = None
#         self.context = None
# 
#         if pattern is not None and index is not None:
#             # Format pattern to show line and column position
#             self.context, self.line, self.col = get_pattern_context(pattern, index)
#             msg = '{}\n  line {}:\n{}'.format(msg, self.line, self.context)
# 
#         super(SelectorSyntaxError, self).__init__(msg)


# Path: lib/soupsieve/css_parser.py
import re
from . import util
from . import css_match as cm
from . import css_types as ct
from collections import OrderedDict
from .util import SelectorSyntaxError



@util.lru_cache(maxsize=_MAXCACHE)
def _cached_css_compile(pattern, namespaces, custom, flags):
    """Cached CSS compile."""

    custom_selectors = process_custom(custom)
    return cm.SoupSieve(
        pattern,
        CSSParser(pattern, custom=custom_selectors, flags=flags).process_selectors(),
        namespaces,
        custom,
        flags
    )


def _purge_cache():
    """Purge the cache."""

    _cached_css_compile.cache_clear()


def process_custom(custom):
    """Process custom."""

    custom_selectors = {}
    if custom is not None:
        for key, value in custom.items():
            name = util.lower(key)
            if RE_CUSTOM.match(name) is None:

                raise SelectorSyntaxError("The name '{}' is not a valid custom pseudo-class name".format(name))