# Path: code/regreg/doctemplates.py
# def doc_templater(doc_dict=None, doc_error=True):
#     """ Return class decorator to record and provide doc templates
# 
#     Parameters
#     ----------
#     doc_dict : dict
#         Extra key / value pairs for this class to fill template docstrings.
#         Parameters in this input dict override parameters from inherited
#         classes.
#     doc_error : {True, False}, optional
#         Whether to raise error in case of non-empty docstring that will be
#         thrown away by using docstring template, where the docstring has not
#         itself been marked for use as a template.
# 
#     Returns
#     -------
#     kdec : function
#         Class decorator
#     """
#     if doc_dict is None:
#         doc_dict = {}
#     def kdec(klass):
#         if hasattr(klass, '_doc_templates'): # inherited
#             klass._doc_templates = klass._doc_templates.copy()
#         else:
#             klass._doc_templates = {}
#         if hasattr(klass, '_doc_dict'): # inherited
#             klass_doc_dict = klass._doc_dict.copy()
#             klass_doc_dict.update(doc_dict)
#         else:
#             klass_doc_dict = doc_dict
#         for obj in klass.__dict__.values():
#             if hasattr(obj, '_doc_template') and hasattr(obj, 'func_name'):
#                 klass._doc_templates[obj.func_name] = obj._doc_template
#             if hasattr(obj, '_uses_doc_template') and hasattr(obj, 'func_name'):
#                 if doc_error and not obj.func_doc is None:
#                     raise ValueError("Refusing to discard unexpected docstring for %s" % repr(obj) +
#                                      " - set `doc_error` to False if you want " + 
#                                      "to allow this")
#                 template = klass._doc_templates[obj.func_name]
#                 obj.func_doc = template % klass_doc_dict
#         klass._doc_dict = klass_doc_dict
#         return klass
#     return kdec


from .doctemplates import doc_templater
""" Implement doc templates using objective templates and vars
"""



def objective_doc_templater(doc_dict=None, doc_errors=True):
    """ Return doc_templater class generator for klasses with objective docs

    Check for specific case where class being decorated has attributes
    ``object_template`` and ``objective_vars``.  Set new entry ``objective`` into class
    ``doc_dict`` using these class attributes.  Then continue decorating as for
    ``doct_templater``.
    """
    if doc_dict is None:
        doc_dict = {}
    def obj_kdec(klass):
        if (hasattr(klass, 'objective_template') and
            hasattr(klass, 'objective_vars')):
            doc_dict['objective'] = (klass.objective_template %
                                     klass.objective_vars)
            for k, v in klass.objective_vars.items():
                doc_dict[k] = v

# Path: code/regreg/doctemplates.py
# def doc_templater(doc_dict=None, doc_error=True):
#     """ Return class decorator to record and provide doc templates
# 
#     Parameters
#     ----------
#     doc_dict : dict
#         Extra key / value pairs for this class to fill template docstrings.
#         Parameters in this input dict override parameters from inherited
#         classes.
#     doc_error : {True, False}, optional
#         Whether to raise error in case of non-empty docstring that will be
#         thrown away by using docstring template, where the docstring has not
#         itself been marked for use as a template.
# 
#     Returns
#     -------
#     kdec : function
#         Class decorator
#     """
#     if doc_dict is None:
#         doc_dict = {}
#     def kdec(klass):
#         if hasattr(klass, '_doc_templates'): # inherited
#             klass._doc_templates = klass._doc_templates.copy()
#         else:
#             klass._doc_templates = {}
#         if hasattr(klass, '_doc_dict'): # inherited
#             klass_doc_dict = klass._doc_dict.copy()
#             klass_doc_dict.update(doc_dict)
#         else:
#             klass_doc_dict = doc_dict
#         for obj in klass.__dict__.values():
#             if hasattr(obj, '_doc_template') and hasattr(obj, 'func_name'):
#                 klass._doc_templates[obj.func_name] = obj._doc_template
#             if hasattr(obj, '_uses_doc_template') and hasattr(obj, 'func_name'):
#                 if doc_error and not obj.func_doc is None:
#                     raise ValueError("Refusing to discard unexpected docstring for %s" % repr(obj) +
#                                      " - set `doc_error` to False if you want " + 
#                                      "to allow this")
#                 template = klass._doc_templates[obj.func_name]
#                 obj.func_doc = template % klass_doc_dict
#         klass._doc_dict = klass_doc_dict
#         return klass
#     return kdec


# Path: code/regreg/objdoctemplates.py
from .doctemplates import doc_templater

""" Implement doc templates using objective templates and vars
"""



def objective_doc_templater(doc_dict=None, doc_errors=True):
    """ Return doc_templater class generator for klasses with objective docs

    Check for specific case where class being decorated has attributes
    ``object_template`` and ``objective_vars``.  Set new entry ``objective`` into class
    ``doc_dict`` using these class attributes.  Then continue decorating as for
    ``doct_templater``.
    """
    if doc_dict is None:
        doc_dict = {}
    def obj_kdec(klass):
        if (hasattr(klass, 'objective_template') and
            hasattr(klass, 'objective_vars')):
            doc_dict['objective'] = (klass.objective_template %
                                     klass.objective_vars)
            for k, v in klass.objective_vars.items():
                doc_dict[k] = v

        return doc_templater(doc_dict, doc_errors)(klass)