Sorry -my bad - I meant the class (probably fieldStorage in Shlomi's case).
I just tried to emphasize overloading as a standard way of "hooking"
functions to modify the behavior.
Lior.
Nir Soffer wrote:
On 17 Jul, 2005, at 9:58, Lior Kesos wrote:
Another option for mocking would be a class that would inherit from
cgi and then overload the functions you want to manipulate.
meaning :
class mycgi(cgi):
def get_params(self):
doMyOwnMagic()
You can't subclass a module.
>>> import cgi
>>> class MockCGI(cgi):
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: function takes at most 2 arguments (3 given)
To replace a module, you need to replace the module in sys.modules,
but if you need to change only few functions, simply replace them:
>>> import cgi
>>> def mock_get_params(): return 'mocked pararms'
...
>>> cgi.get_params = mock_get_params
>>> cgi.get_params()
'mocked pararms'
Best Regards,
Nir Soffer
--
Lior Kesos - [EMAIL PROTECTED]
Content Development Team Leader
==============================
"Everything should be made as simple as possible -
but not simpler" -- Albert Einstein