From 80535a2c0b298a8a90eaf7a594ae27f3dd525ce3 Mon Sep 17 00:00:00 2001 From: "M. de Verteuil" Date: Fri, 19 Jun 2015 09:24:57 -0400 Subject: [PATCH] A less naive strategy for getting view closure var - Now handles views decorated with functions that have positional arguments - Searches for a types.FunctionType argument in the closure, rather than assuming the first argument is the view. --- rest_framework_swagger/decorators.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rest_framework_swagger/decorators.py b/rest_framework_swagger/decorators.py index 3103ac08..045d2e3e 100644 --- a/rest_framework_swagger/decorators.py +++ b/rest_framework_swagger/decorators.py @@ -35,10 +35,16 @@ def closure_n_code(func): def get_closure_var(func, name=None): unwrap = closure_n_code(func) - i = 0 if name: - i = unwrap.code.co_freevars.index(name) - return unwrap.closure[i].cell_contents + index = unwrap.code.co_freevars.index(name) + return unwrap.closure[index].cell_contents + else: + for closure_var in unwrap.closure: + if isinstance(closure_var.cell_contents, types.FunctionType): + return closure_var.cell_contents + else: + return None + def wrapper_to_func(wrapper): noms = wrapper.http_method_names