def extract(self, name):
"""
Get the object corresponding to name, or None.
For use with imputil ArchiveImporter, object is a python code object.
'name' is the name as specified in an 'import name'.
'import a.b' will become:
extract('a') (return None because 'a' is not a code object)
extract('a.__init__') (return a code object)
extract('a.b') (return a code object)
Default implementation:
self.toc is a dict
self.toc[name] is pos
self.lib has the code object marshal-ed at pos
"""
ispkg, pos = self.toc.get(name, (0, None))
if pos is None:
return None
with self.lib:
self.lib.seek(self.start + pos)
# use marshal.loads() sind load() arg must be a file object
obj = marshal.loads(self.lib.read())
return ispkg, obj
########################################################################
# Informational methods
评论列表
文章目录