# Path: templar/exceptions.py
# class TemplarError(Exception):
#     """Top-level exception for Templar."""
#     pass


from templar.exceptions import TemplarError
import re
        elif hasattr(self.pattern, 'sub') and callable(self.pattern.sub):
            return self.pattern.sub(self.substitute, content)
        raise InvalidRule(
            "{}'s pattern has type '{}', but expected a string or "
            "compiled regex.".format(type(self).__name__, type(self.pattern).__name__))


class VariableRule(Rule):
    """An abstract class that represents a rule that constructs variables given the content. For
    VariableRules, the apply method returns a dictionary mapping str -> str instead of returning
    transformed content (a string).
    """

    def extract(self, content):
        """A substitution function that returns the text with which to replace the given match.
        Subclasses should implement this method.
        """
        raise InvalidRule(
                '{} must implement the extract method to be '
                'a valid VariableRule'.format(type(self).__name__))

    def apply(self, content):
        variables = self.extract(content)
        if not isinstance(variables, dict):
            raise InvalidRule(
                "{} is a VariableRule, so its extract method should return a dict. Instead, it "
                "returned type '{}'".format(type(self).__name__, type(variables).__name__))
        return variables



# Path: templar/exceptions.py
# class TemplarError(Exception):
#     """Top-level exception for Templar."""
#     pass


# Path: templar/api/rules/core.py
from templar.exceptions import TemplarError
import re

        elif hasattr(self.pattern, 'sub') and callable(self.pattern.sub):
            return self.pattern.sub(self.substitute, content)
        raise InvalidRule(
            "{}'s pattern has type '{}', but expected a string or "
            "compiled regex.".format(type(self).__name__, type(self.pattern).__name__))


class VariableRule(Rule):
    """An abstract class that represents a rule that constructs variables given the content. For
    VariableRules, the apply method returns a dictionary mapping str -> str instead of returning
    transformed content (a string).
    """

    def extract(self, content):
        """A substitution function that returns the text with which to replace the given match.
        Subclasses should implement this method.
        """
        raise InvalidRule(
                '{} must implement the extract method to be '
                'a valid VariableRule'.format(type(self).__name__))

    def apply(self, content):
        variables = self.extract(content)
        if not isinstance(variables, dict):
            raise InvalidRule(
                "{} is a VariableRule, so its extract method should return a dict. Instead, it "
                "returned type '{}'".format(type(self).__name__, type(variables).__name__))
        return variables



class InvalidRule(TemplarError):