Created
January 22, 2012 16:28
-
-
Save mccutchen/1657592 to your computer and use it in GitHub Desktop.
Evil Python monkeypatching test
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
| import types | |
| assert int(True) == 1 and int(False) == 0 | |
| # Who knew that __bulitins__ was a different object depending on whether you | |
| # run a module directly or import it into another module? | |
| if isinstance(__builtins__, types.ModuleType): | |
| __builtins__.True, __builtins__.False = False, True | |
| else: | |
| __builtins__['True'], __builtins__['False'] = False, True | |
| assert int(True) == 0 and int(False) == 1 |
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
| assert int(True) == 1 and int(False) == 0 | |
| import evil | |
| assert int(True) == 0 and int(False) == 1 | |
| print 'Importing evil successfully inverted True and False in main' | |
| print 'int(True) => %d' % int(True) | |
| print 'int(False) => %d' % int(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment