Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
importlib.test.source.test_file_loader.BadBytecodeTest Class Reference
Inheritance diagram for importlib.test.source.test_file_loader.BadBytecodeTest:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def import_
def manipulate_bytecode

Private Member Functions

def _test_empty_file
def _test_partial_magic
def _test_magic_only
def _test_partial_timestamp
def _test_no_marshal
def _test_non_code_marshal
def _test_bad_marshal
def _test_bad_magic

Detailed Description

Definition at line 132 of file test_file_loader.py.


Member Function Documentation

def importlib.test.source.test_file_loader.BadBytecodeTest._test_bad_magic (   self,
  test,
  del_source = False 
) [private]

Definition at line 220 of file test_file_loader.py.

00220 
00221     def _test_bad_magic(self, test, *, del_source=False):
00222         with source_util.create_modules('_temp') as mapping:
00223             bc_path = self.manipulate_bytecode('_temp', mapping,
00224                                     lambda bc: b'\x00\x00\x00\x00' + bc[4:])
00225             test('_temp', mapping, bc_path)
00226 

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_bad_marshal (   self,
  del_source = False 
) [private]

Definition at line 211 of file test_file_loader.py.

00211 
00212     def _test_bad_marshal(self, *, del_source=False):
00213         with source_util.create_modules('_temp') as mapping:
00214             bytecode_path = self.manipulate_bytecode('_temp', mapping,
00215                                                 lambda bc: bc[:8] + b'<test>',
00216                                                 del_source=del_source)
00217             file_path = mapping['_temp'] if not del_source else bytecode_path
00218             with self.assertRaises(EOFError):
00219                 self.import_(file_path, '_temp')

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_empty_file (   self,
  test,
  del_source = False 
) [private]

Definition at line 162 of file test_file_loader.py.

00162 
00163     def _test_empty_file(self, test, *, del_source=False):
00164         with source_util.create_modules('_temp') as mapping:
00165             bc_path = self.manipulate_bytecode('_temp', mapping,
00166                                                 lambda bc: b'',
00167                                                 del_source=del_source)
00168             test('_temp', mapping, bc_path)

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_magic_only (   self,
  test,
  del_source = False 
) [private]

Definition at line 179 of file test_file_loader.py.

00179 
00180     def _test_magic_only(self, test, *, del_source=False):
00181         with source_util.create_modules('_temp') as mapping:
00182             bc_path = self.manipulate_bytecode('_temp', mapping,
00183                                                 lambda bc: bc[:4],
00184                                                 del_source=del_source)
00185             test('_temp', mapping, bc_path)

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_no_marshal (   self,
  del_source = False 
) [private]

Definition at line 193 of file test_file_loader.py.

00193 
00194     def _test_no_marshal(self, *, del_source=False):
00195         with source_util.create_modules('_temp') as mapping:
00196             bc_path = self.manipulate_bytecode('_temp', mapping,
00197                                                 lambda bc: bc[:8],
00198                                                 del_source=del_source)
00199             file_path = mapping['_temp'] if not del_source else bc_path
00200             with self.assertRaises(EOFError):
00201                 self.import_(file_path, '_temp')

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_non_code_marshal (   self,
  del_source = False 
) [private]

Definition at line 202 of file test_file_loader.py.

00202 
00203     def _test_non_code_marshal(self, *, del_source=False):
00204         with source_util.create_modules('_temp') as mapping:
00205             bytecode_path = self.manipulate_bytecode('_temp', mapping,
00206                                     lambda bc: bc[:8] + marshal.dumps(b'abcd'),
00207                                     del_source=del_source)
00208             file_path = mapping['_temp'] if not del_source else bytecode_path
00209             with self.assertRaises(ImportError):
00210                 self.import_(file_path, '_temp')

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_partial_magic (   self,
  test,
  del_source = False 
) [private]

Definition at line 170 of file test_file_loader.py.

00170 
00171     def _test_partial_magic(self, test, *, del_source=False):
00172         # When their are less than 4 bytes to a .pyc, regenerate it if
00173         # possible, else raise ImportError.
00174         with source_util.create_modules('_temp') as mapping:
00175             bc_path = self.manipulate_bytecode('_temp', mapping,
00176                                                 lambda bc: bc[:3],
00177                                                 del_source=del_source)
00178             test('_temp', mapping, bc_path)

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest._test_partial_timestamp (   self,
  test,
  del_source = False 
) [private]

Definition at line 186 of file test_file_loader.py.

00186 
00187     def _test_partial_timestamp(self, test, *, del_source=False):
00188         with source_util.create_modules('_temp') as mapping:
00189             bc_path = self.manipulate_bytecode('_temp', mapping,
00190                                                 lambda bc: bc[:7],
00191                                                 del_source=del_source)
00192             test('_temp', mapping, bc_path)

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest.import_ (   self,
  file,
  module_name 
)

Definition at line 134 of file test_file_loader.py.

00134 
00135     def import_(self, file, module_name):
00136         loader = self.loader(module_name, file)
00137         module = loader.load_module(module_name)
00138         self.assertTrue(module_name in sys.modules)

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib.test.source.test_file_loader.BadBytecodeTest.manipulate_bytecode (   self,
  name,
  mapping,
  manipulator,
  del_source = False 
)
Manipulate the bytecode of a module by passing it into a callable
that returns what to use as the new bytecode.

Definition at line 140 of file test_file_loader.py.

00140 
00141                             del_source=False):
00142         """Manipulate the bytecode of a module by passing it into a callable
00143         that returns what to use as the new bytecode."""
00144         try:
00145             del sys.modules['_temp']
00146         except KeyError:
00147             pass
00148         py_compile.compile(mapping[name])
00149         if not del_source:
00150             bytecode_path = imp.cache_from_source(mapping[name])
00151         else:
00152             os.unlink(mapping[name])
00153             bytecode_path = make_legacy_pyc(mapping[name])
00154         if manipulator:
00155             with open(bytecode_path, 'rb') as file:
00156                 bc = file.read()
00157                 new_bc = manipulator(bc)
00158             with open(bytecode_path, 'wb') as file:
00159                 if new_bc is not None:
00160                     file.write(new_bc)
00161         return bytecode_path

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: