Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions
importlib._bootstrap._LoaderBasics Class Reference
Inheritance diagram for importlib._bootstrap._LoaderBasics:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def is_package

Private Member Functions

def _bytes_from_bytecode
def _load_module

Detailed Description

Base class of common code needed by both SourceLoader and
_SourcelessFileLoader.

Definition at line 294 of file _bootstrap.py.


Member Function Documentation

def importlib._bootstrap._LoaderBasics._bytes_from_bytecode (   self,
  fullname,
  data,
  source_mtime 
) [private]
Return the marshalled bytes from bytecode, verifying the magic
number and timestamp along the way.

If source_mtime is None then skip the timestamp check.

Definition at line 305 of file _bootstrap.py.

00305 
00306     def _bytes_from_bytecode(self, fullname, data, source_mtime):
00307         """Return the marshalled bytes from bytecode, verifying the magic
00308         number and timestamp along the way.
00309 
00310         If source_mtime is None then skip the timestamp check.
00311 
00312         """
00313         magic = data[:4]
00314         raw_timestamp = data[4:8]
00315         if len(magic) != 4 or magic != imp.get_magic():
00316             raise ImportError("bad magic number in {}".format(fullname))
00317         elif len(raw_timestamp) != 4:
00318             raise EOFError("bad timestamp in {}".format(fullname))
00319         elif source_mtime is not None:
00320             if marshal._r_long(raw_timestamp) != source_mtime:
00321                 raise ImportError("bytecode is stale for {}".format(fullname))
00322         # Can't return the code object as errors from marshal loading need to
00323         # propagate even when source is available.
00324         return data[8:]

Here is the caller graph for this function:

def importlib._bootstrap._LoaderBasics._load_module (   self,
  module,
  sourceless = False 
) [private]
Helper for load_module able to handle either source or sourceless
loading.

Definition at line 326 of file _bootstrap.py.

00326 
00327     def _load_module(self, module, *, sourceless=False):
00328         """Helper for load_module able to handle either source or sourceless
00329         loading."""
00330         name = module.__name__
00331         code_object = self.get_code(name)
00332         module.__file__ = self.get_filename(name)
00333         if not sourceless:
00334             module.__cached__ = imp.cache_from_source(module.__file__)
00335         else:
00336             module.__cached__ = module.__file__
00337         module.__package__ = name
00338         if self.is_package(name):
00339             module.__path__ = [module.__file__.rsplit(path_sep, 1)[0]]
00340         else:
00341             module.__package__ = module.__package__.rpartition('.')[0]
00342         module.__loader__ = self
00343         exec(code_object, module.__dict__)
00344         return module
00345 

Here is the call graph for this function:

Here is the caller graph for this function:

def importlib._bootstrap._LoaderBasics.is_package (   self,
  fullname 
)
Concrete implementation of InspectLoader.is_package by checking if
the path returned by get_filename has a filename of '__init__.py'.

Reimplemented in importlib.test.source.test_abc_loader.PyPycLoaderMock, importlib.abc.PyLoader, and importlib.test.source.test_abc_loader.PyLoaderMock.

Definition at line 299 of file _bootstrap.py.

00299 
00300     def is_package(self, fullname):
00301         """Concrete implementation of InspectLoader.is_package by checking if
00302         the path returned by get_filename has a filename of '__init__.py'."""
00303         filename = self.get_filename(fullname).rpartition(path_sep)[2]
00304         return filename.rsplit('.', 1)[0] == '__init__'

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: