# Path: pulp_auto/namespace.py
# def load_ns(d, leaf_processor=lambda x: x):
#     '''a recursive dict-to-Namespace loader'''
#     if not isinstance(d, dict):
#         if isinstance(d, list):
#             return [load_ns(item) for item in d]
#         if isinstance(d, tuple):
#             return tuple([load_ns(item) for item in d])
#         return leaf_processor(d)
#     ns = Namespace()
#     for k, v in d.items():
#         ns[k] = load_ns(v, leaf_processor)
#     return ns


import logging, profile
        import functools
from pulp_auto.namespace import load_ns 
log = logging.getLogger(__name__)

def format_function_call(fn_name, args, kvs):
    '''return a string representation of a fn_name(*args, **kvs) call'''
    rargs = map(lambda x: repr(x), args)
    rkvs = map(lambda x: "%s=%r" % (x[0], x[1]), kvs)
    return "%s(" % fn_name  + ", ".join(rargs + rkvs) + ")"

def logged(log_method=log.info):
    '''decorate a method to log its calls and returned value'''
    def decorator_maker(method):
        @functools.wraps(method)
        def logged_wrapper(self, *args, **kvs):
            ret = None
            try:
                ret = method(self, *args, **kvs)
            finally:
                log_method(repr(self) + "." + format_function_call(method.__name__, args, kvs) + " == " + repr(ret))
            return ret
        return logged_wrapper
    return decorator_maker

def unit_method(method):
    '''maps a method on all the units;
    *args -> units, options, unit_type; **kvs -> PROFILE;
    return PROFILE
    '''
    def wrapped_method(self, *args, **kvs):
        units = load_ns(args[0])

# Path: pulp_auto/namespace.py
# def load_ns(d, leaf_processor=lambda x: x):
#     '''a recursive dict-to-Namespace loader'''
#     if not isinstance(d, dict):
#         if isinstance(d, list):
#             return [load_ns(item) for item in d]
#         if isinstance(d, tuple):
#             return tuple([load_ns(item) for item in d])
#         return leaf_processor(d)
#     ns = Namespace()
#     for k, v in d.items():
#         ns[k] = load_ns(v, leaf_processor)
#     return ns


# Path: pulp_auto/handler/handler.py
import logging, profile
        import functools
from pulp_auto.namespace import load_ns 

log = logging.getLogger(__name__)

def format_function_call(fn_name, args, kvs):
    '''return a string representation of a fn_name(*args, **kvs) call'''
    rargs = map(lambda x: repr(x), args)
    rkvs = map(lambda x: "%s=%r" % (x[0], x[1]), kvs)
    return "%s(" % fn_name  + ", ".join(rargs + rkvs) + ")"

def logged(log_method=log.info):
    '''decorate a method to log its calls and returned value'''
    def decorator_maker(method):
        @functools.wraps(method)
        def logged_wrapper(self, *args, **kvs):
            ret = None
            try:
                ret = method(self, *args, **kvs)
            finally:
                log_method(repr(self) + "." + format_function_call(method.__name__, args, kvs) + " == " + repr(ret))
            return ret
        return logged_wrapper
    return decorator_maker

def unit_method(method):
    '''maps a method on all the units;
    *args -> units, options, unit_type; **kvs -> PROFILE;
    return PROFILE
    '''
    def wrapped_method(self, *args, **kvs):
        units = load_ns(args[0])

        options = load_ns(args[-1])