michaelcontento/revolver — pull request #10 by imankulov (2012-11-10 16:09:47+00:00)
Title: Bugfix in inject_use_sudo

Fixed the way how the code defines arguments of function to patch.

Actually, `func.func_code.co_varnames` returns all local variables used in function, and the list should be limited. According to [python data model](http://docs.python.org/2/reference/datamodel.html):

> `co_argcount` is the number of positional arguments (including arguments with default values); <...> `co_varnames` is a tuple containing the names of the local variables (starting with the argument names)

The misconception leads to incorrect patching of `cuisine.file_write` which accidentally contains `use_sudo` in the list of its local variables:

>>> from cuisine import file_write
>>> file_write.func_code.co_varnames
('location', 'content', 'mode', 'owner', 'group', 'sudo', 'check', 'use_sudo', 'sig', 'fd', 'local_path', 'result', 'file_sig')
>>> inspect.getargspec(file_write).args
['location', 'content', 'mode', 'owner', 'group', 'sudo', 'check']