Created
March 11, 2012 23:32
-
-
Save notmyname/2018680 to your computer and use it in GitHub Desktop.
evil with the import statement
This file contains 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
'''evil with the import statement''' | |
import sys | |
def foo_func(x): | |
return x * x | |
sys.modules['foobar'] = foo_func | |
import foobar | |
print foobar(10) | |
class Klass(object): | |
'''a classy class''' | |
def bar(self, x): | |
return x * x * x | |
sys.modules['classy'] = Klass | |
import classy | |
print classy().bar(10) | |
sys.modules['yarr'] = Klass() | |
import yarr | |
print yarr.bar(10) | |
sys.modules['argh'] = Klass().bar | |
import argh | |
print argh(10) | |
sys.modules['blargh'] = 10 | |
import blargh | |
print argh(blargh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment