What's the best way NOT to have to extracts the SAME KWARGS twice: once in the decorator (wrapper function) and once in the function itself.
Here is the function:
@close_logger
def close(**kwargs):
""" returns close object"""
# Get params
session_attributes = kwargs.get('sessionAttrbiutes', {})
message = kwargs.get('message', '')
LID = kwargs.get('LIData', {})
SANS = kwargs.get('SANS', [])
FS = kwargs.get('fulfillmentState', 'Fulfilled')
response = {
'sessionAttributes': session_attributes,
'dialogAction': {
'type': SANS,
'fulfillmentState': FS,
'message': {
'contentType': LID,
'content': message
}
}
}
return response
and here is the decorator (used for logging the close event):
def close_logger(func):
@functools.wraps(func)
def wrapper(**kwargs):
# Get params
session_attributes = kwargs.get('sessionAttrbiutes', {})
message = kwargs.get('message', '')
LID = kwargs.get('LIData', {})
SANS = kwargs.get('SANS', [])
FS = kwargs.get('fulfillmentState', 'Fulfilled')
logger.debug('Logging:\n Function:{} Session Attributes: {}\n \
Message{}\n: LID: {}\n SANS: {}\n FS: {}'.format(
func.__name__,
session_attributes,
message,
LID,
SANS,
FS
))
return func(**kwargs)
return wrapper