Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Commit

Permalink
A less naive strategy for getting view closure var
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
mverteuil committed Jun 24, 2015
1 parent ed84746 commit f029564
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rest_framework_swagger/decorators.py
Expand Up @@ -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
Expand Down

0 comments on commit f029564

Please sign in to comment.