Created
September 2, 2013 23:52
-
-
Save GrahamDumpleton/6418300 to your computer and use it in GitHub Desktop.
Example of a module proxy which selectively overrides behaviour of specific functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import wrapt | |
import time | |
import sys | |
class TimeModuleProxy(wrapt.ObjectProxy): | |
def __init__(self, module=time): | |
super(TimeModuleProxy, self).__init__(module) | |
def sleep(self, seconds): | |
print('I am going to sleep for %ss.' % seconds) | |
return self._self_wrapped.sleep(seconds) | |
sys.modules['wrapt_time'] = TimeModuleProxy() | |
from wrapt_time import sleep, asctime, tzname | |
print(tzname) | |
print(asctime()) | |
sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment