Python zlib.py() Examples
The following are 30
code examples of zlib.py().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
zlib
, or try the search function
.
Example #1
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testBoth(self): files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, test_pyc)} self.doTest(pyc_ext, files, TESTMOD)
Example #2
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testImport_WithStuff(self): # try importing from a zipfile which contains additional # stuff at the beginning of the file files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD, stuff=b"Some Stuff"*31)
Example #3
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testPy(self): files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD)
Example #4
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testBoth(self): files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, test_pyc)} self.doTest(pyc_ext, files, TESTMOD)
Example #5
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testEmptyPy(self): files = {TESTMOD + ".py": (NOW, "")} self.doTest(None, files, TESTMOD)
Example #6
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testBadMagic(self): # make pyc magic word invalid, forcing loading from .py m0 = ord(test_pyc[0]) m0 ^= 0x04 # flip an arbitrary bit badmagic_pyc = chr(m0) + test_pyc[1:] files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badmagic_pyc)} self.doTest(".py", files, TESTMOD)
Example #7
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testBadMTime(self): t3 = ord(test_pyc[7]) t3 ^= 0x02 # flip the second bit -- not the first as that one # isn't stored in the .py's mtime in the zip archive. badtime_pyc = test_pyc[:7] + chr(t3) + test_pyc[8:] files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badtime_pyc)} self.doTest(".py", files, TESTMOD)
Example #8
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testImport_WithStuff(self): # try importing from a zipfile which contains additional # stuff at the beginning of the file files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD, stuff="Some Stuff"*31)
Example #9
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testGetSource(self): files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD, call=self.assertModuleSource)
Example #10
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testGetCompiledSource(self): pyc = make_pyc(compile(test_src, "<???>", "exec"), NOW) files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, pyc)} self.doTest(pyc_ext, files, TESTMOD, call=self.assertModuleSource)
Example #11
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def runDoctest(self, callback): files = {TESTMOD + ".py": (NOW, test_src), "xyz.txt": (NOW, ">>> log.append(True)\n")} self.doTest(".py", files, TESTMOD, call=callback)
Example #12
Source File: test_zipimport.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def testAFakeZlib(self): # # This could cause a stack overflow before: importing zlib.py # from a compressed archive would cause zlib to be imported # which would find zlib.py in the archive, which would... etc. # # This test *must* be executed first: it must be the first one # to trigger zipimport to import zlib (zipimport caches the # zlib.decompress function object, after which the problem being # tested here wouldn't be a problem anymore... # (Hence the 'A' in the test method name: to make it the first # item in a list sorted by name, like unittest.makeSuite() does.) # # This test fails on platforms on which the zlib module is # statically linked, but the problem it tests for can't # occur in that case (builtin modules are always found first), # so we'll simply skip it then. Bug #765456. # if "zlib" in sys.builtin_module_names: return if "zlib" in sys.modules: del sys.modules["zlib"] files = {"zlib.py": (NOW, test_src)} try: self.doTest(".py", files, "zlib") except ImportError: if self.compression != ZIP_DEFLATED: self.fail("expected test to not raise ImportError") else: if self.compression != ZIP_STORED: self.fail("expected test to raise ImportError")
Example #13
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testBadMagic2(self): # make pyc magic word invalid, causing an ImportError badmagic_pyc = bytearray(test_pyc) badmagic_pyc[0] ^= 0x04 # flip an arbitrary bit files = {TESTMOD + pyc_ext: (NOW, badmagic_pyc)} try: self.doTest(".py", files, TESTMOD) except ImportError: pass else: self.fail("expected ImportError; import from bad pyc")
Example #14
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testEmptyPy(self): files = {TESTMOD + ".py": (NOW, "")} self.doTest(None, files, TESTMOD)
Example #15
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testUncheckedHashBasedPyc(self): source = b"state = 'old'" source_hash = importlib.util.source_hash(source) bytecode = importlib._bootstrap_external._code_to_hash_pyc( compile(source, "???", "exec"), source_hash, False, # unchecked ) files = {TESTMOD + ".py": (NOW, "state = 'new'"), TESTMOD + ".pyc": (NOW - 20, bytecode)} def check(mod): self.assertEqual(mod.state, 'old') self.doTest(None, files, TESTMOD, call=check)
Example #16
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testBadMTime(self): badtime_pyc = bytearray(test_pyc) # flip the second bit -- not the first as that one isn't stored in the # .py's mtime in the zip archive. badtime_pyc[11] ^= 0x02 files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badtime_pyc)} self.doTest(".py", files, TESTMOD)
Example #17
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testPy(self): files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD)
Example #18
Source File: test_zipimport.py From android_universal with MIT License | 5 votes |
def testAFakeZlib(self): # # This could cause a stack overflow before: importing zlib.py # from a compressed archive would cause zlib to be imported # which would find zlib.py in the archive, which would... etc. # # This test *must* be executed first: it must be the first one # to trigger zipimport to import zlib (zipimport caches the # zlib.decompress function object, after which the problem being # tested here wouldn't be a problem anymore... # (Hence the 'A' in the test method name: to make it the first # item in a list sorted by name, like unittest.makeSuite() does.) # # This test fails on platforms on which the zlib module is # statically linked, but the problem it tests for can't # occur in that case (builtin modules are always found first), # so we'll simply skip it then. Bug #765456. # if "zlib" in sys.builtin_module_names: self.skipTest('zlib is a builtin module') if "zlib" in sys.modules: del sys.modules["zlib"] files = {"zlib.py": (NOW, test_src)} try: self.doTest(".py", files, "zlib") except ImportError: if self.compression != ZIP_DEFLATED: self.fail("expected test to not raise ImportError") else: if self.compression != ZIP_STORED: self.fail("expected test to raise ImportError")
Example #19
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def runDoctest(self, callback): files = {TESTMOD + ".py": (NOW, test_src), "xyz.txt": (NOW, ">>> log.append(True)\n")} self.doTest(".py", files, TESTMOD, call=callback)
Example #20
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testGetCompiledSource(self): pyc = make_pyc(compile(test_src, "<???>", "exec"), NOW) files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, pyc)} self.doTest(pyc_ext, files, TESTMOD, call=self.assertModuleSource)
Example #21
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testGetSource(self): files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD, call=self.assertModuleSource)
Example #22
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testImport_WithStuff(self): # try importing from a zipfile which contains additional # stuff at the beginning of the file files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD, stuff="Some Stuff"*31)
Example #23
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testBadMTime(self): t3 = ord(test_pyc[7]) t3 ^= 0x02 # flip the second bit -- not the first as that one # isn't stored in the .py's mtime in the zip archive. badtime_pyc = test_pyc[:7] + chr(t3) + test_pyc[8:] files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badtime_pyc)} self.doTest(".py", files, TESTMOD)
Example #24
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testBadMagic(self): # make pyc magic word invalid, forcing loading from .py m0 = ord(test_pyc[0]) m0 ^= 0x04 # flip an arbitrary bit badmagic_pyc = chr(m0) + test_pyc[1:] files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, badmagic_pyc)} self.doTest(".py", files, TESTMOD)
Example #25
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testEmptyPy(self): files = {TESTMOD + ".py": (NOW, "")} self.doTest(None, files, TESTMOD)
Example #26
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testBoth(self): files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, test_pyc)} self.doTest(pyc_ext, files, TESTMOD)
Example #27
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testPy(self): files = {TESTMOD + ".py": (NOW, test_src)} self.doTest(".py", files, TESTMOD)
Example #28
Source File: test_zipimport.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def testAFakeZlib(self): # # This could cause a stack overflow before: importing zlib.py # from a compressed archive would cause zlib to be imported # which would find zlib.py in the archive, which would... etc. # # This test *must* be executed first: it must be the first one # to trigger zipimport to import zlib (zipimport caches the # zlib.decompress function object, after which the problem being # tested here wouldn't be a problem anymore... # (Hence the 'A' in the test method name: to make it the first # item in a list sorted by name, like unittest.makeSuite() does.) # # This test fails on platforms on which the zlib module is # statically linked, but the problem it tests for can't # occur in that case (builtin modules are always found first), # so we'll simply skip it then. Bug #765456. # if "zlib" in sys.builtin_module_names: return if "zlib" in sys.modules: del sys.modules["zlib"] files = {"zlib.py": (NOW, test_src)} try: self.doTest(".py", files, "zlib") except ImportError: if self.compression != ZIP_DEFLATED: self.fail("expected test to not raise ImportError") else: if self.compression != ZIP_STORED: self.fail("expected test to raise ImportError")
Example #29
Source File: test_zipimport.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def runDoctest(self, callback): files = {TESTMOD + ".py": (NOW, test_src), "xyz.txt": (NOW, ">>> log.append(True)\n")} self.doTest(".py", files, TESTMOD, call=callback)
Example #30
Source File: test_zipimport.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testGetCompiledSource(self): pyc = make_pyc(compile(test_src, "<???>", "exec"), NOW) files = {TESTMOD + ".py": (NOW, test_src), TESTMOD + pyc_ext: (NOW, pyc)} self.doTest(pyc_ext, files, TESTMOD, call=self.assertModuleSource)