"""
Example use of `decorator`

    from utils.decorator import decorator as d

    @d(app.route('/'))
    @jsonify
    @validate_form(MyForm)
    def index(my_form):
        return 'hi'

Where `app.route` is defined outside the project (and therefore needs to be
wrapped with standard function notation `d(...)` instead of decorator notation)
and `jsonify` and `validate_form` are defined in the project -- e.g.:

    @decorator
    def jsonify(f):
        ...
"""


from functools import update_wrapper


def decorator(d):

    def _d(f):
        _f = d(f)  # what `d` was designed to do
        update_wrapper(_f, f)
        _f.__wrapped__ = f.func_dict.get('__wrapped__', f)
        # the above line ensures base function is passed up entire chain of
        # decorators for easy testing
        return _f

    return _d


# apply `decorator` to itself so that it behaves like a proper decorator,
# updating the metadata and setting the `__wrapped__` field of the wrapper
# it returns
decorator = decorator(decorator)

@@ -1,12 +1,137 @@
 %22%22%22%0A
+Adapted from Peter Norvig's Design of Computer Programs%0A(https://www.udacity.com/course/design-of-computer-programs--cs212)%0A%0A
 Example 
@@ -643,16 +643,97 @@
 tor(d):%0A
+    %22make function %60d%60 a decorator: %60d%60 wraps function %60f%60 and takes on metadata%22
 %0A    def
@@ -984,16 +984,30 @@
 or easy 
+retrieval for 
 testing%0A

update documentation of `decorator.py`