Panda3D
Public Member Functions | Public Attributes | Static Public Attributes

ZlibArchive Class Reference

def build(self, path, lTOC): """Create an archive file of name 'path'. More...

Inheritance diagram for ZlibArchive:
Archive

List of all members.

Public Member Functions

def __init__
def checkmagic
 Sub-methods of __init__ - override as needed #############.
def contents
 Informational methods.
def extract
 Core method - Override as needed #########.
def get_code
 This is what is called by FuncImporter ####### Since an Archive is flat, we ignore parent and modname.
def loadtoc

Public Attributes

 lib
 path
 pymagic
 start
 toc

Static Public Attributes

int HDRLEN = 12
int LEVEL = 9
string MAGIC = 'PYZ\0'
 os = None
int TOCPOS = 8
dictionary TOCTMPLT = {}
int TRLLEN = 0

Detailed Description

def build(self, path, lTOC): """Create an archive file of name 'path'.

lTOC is a 'logical TOC' - a list of (name, path, ...) where name is the internal name, eg 'a' and path is a file to get the object from, eg './a.pyc'. """ self.path = path self.lib = open(path, 'wb') #reserve space for the header if self.HDRLEN: self.lib.write('\0'*self.HDRLEN)

#create an empty toc

if type(self.TOCTMPLT) == type({}): self.toc = {} else: # assume callable self.toc = self.TOCTMPLT()

for tocentry in lTOC: self.add(tocentry) # the guts of the archive

tocpos = self.lib.tell() self.save_toc(tocpos) if self.TRLLEN: self.save_trailer(tocpos) if self.HDRLEN: self.update_headers(tocpos) self.lib.close()

####### manages keeping the internal TOC and the guts in sync ####### def add(self, entry): """Override this to influence the mechanics of the Archive. Assumes entry is a seq beginning with (nm, pth, ...) where nm is the key by which we'll be asked for the object. pth is the name of where we find the object. Overrides of get_obj_from can make use of further elements in entry. """ if self.os is None: import os self.os = os nm = entry[0] pth = entry[1] ispkg = self.os.path.splitext(self.os.path.basename(pth))[0] == '__init__' self.toc[nm] = (ispkg, self.lib.tell()) f = open(entry[1], 'rb') f.seek(8) #skip magic and timestamp self.lib.write(f.read())

def save_toc(self, tocpos): """Default - toc is a dict Gets marshaled to self.lib """ marshal.dump(self.toc, self.lib)

def save_trailer(self, tocpos): """Default - not used""" pass

def update_headers(self, tocpos): """Default - MAGIC + Python's magic + tocpos""" self.lib.seek(self.start) self.lib.write(self.MAGIC) self.lib.write(self.pymagic) self.lib.write(struct.pack('=i', tocpos))

ZlibArchive - an archive with compressed entries


Constructor & Destructor Documentation

def __init__ (   self,
  path = None,
  offset = 0 
)

Reimplemented from Archive.


Member Function Documentation

def checkmagic (   self) [inherited]

Sub-methods of __init__ - override as needed #############.

Overridable.
Check to see if the file object self.lib actually has a file
we understand.

Reimplemented in CArchive.

def contents (   self) [inherited]

Informational methods.

Return a list of the contents
   Default implementation assumes self.toc is a dict like object.
   Not required by ArchiveImporter.

Reimplemented in CArchive.

def extract (   self,
  name 
)

Core method - Override as needed #########.

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

Reimplemented from Archive.

def get_code (   self,
  parent,
  modname,
  fqname 
) [inherited]

This is what is called by FuncImporter ####### Since an Archive is flat, we ignore parent and modname.

def loadtoc (   self) [inherited]
Overridable.
Default: After magic comes an int (4 byte native) giving the
position of the TOC within self.lib.
Default: The TOC is a marshal-able string.

Reimplemented in CArchive.


Member Data Documentation

int HDRLEN = 12 [static]

Reimplemented from Archive.

int LEVEL = 9 [static]
lib [inherited]
string MAGIC = 'PYZ\0' [static]

Reimplemented from Archive.

os = None [static, inherited]
path [inherited]
pymagic [inherited]
start [inherited]
toc [inherited]

Reimplemented in CArchive.

int TOCPOS = 8 [static]

Reimplemented from Archive.

dictionary TOCTMPLT = {} [static]

Reimplemented from Archive.

int TRLLEN = 0 [static]

Reimplemented from Archive.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties