@@ -0,0 +1,2291 @@
+#%0A# A class which knows how to both write and parse 'Quetzal' files,%0A# which is the standard save-file format for all well-behaved%0A# Z-machine implementatinos.%0A#%0A# The format is documented at:%0A#    http://ifarchive.giga.or.at/if-archive/infocom/%5C%0A#           interpreters/specification/savefile_14.txt%0A#%0A# For the license of this file, please consult the LICENSE file in the%0A# root directory of this distribution.%0A#%0A%0A# Woohoo!  Python has a module to parse IFF files, which is a generic%0A# interchange format.  A Quetzal file is in fact a type of IFF file.%0Aimport chunk%0A%0A# The general format of Queztal is that of a %22FORM%22 IFF file, which is%0A# a container class for 'chunks'.%0A#%0A#   %22FORM%22, 4 bytes showing container length, 4-byte ID %22IFZS%22,%0A#        4-byte chunkname, 4-byte length, length bytes of data%0A#        4-byte chunkname, 4-byte length, length bytes of data%0A#        4-byte chunkname, 4-byte length, length bytes of data%0A#        ...%0A%0A%0Aclass QuetzalError(Exception):%0A  %22General exception for Quetzal classes.%22%0A  pass%0A%0Aclass QuetzalUnrecognizedFileFormat(QuetzalError):%0A  %22Not a valid Quetzal file.%22%0A%0A%0Aclass QuetzalParser(object):%0A%0A  def __init__(self, filename, zmachine=None):%0A    %22%22%22Parse Quetzal save-file FILENAME, handling each of the known%0A    Quetzal chunk types as they are discovered.  Each chunk type%0A    handler is responsible for initializing some portion of%0A    ZMACHINE.%22%22%22%0A%0A    self._file = open(filename)%0A%0A    # The python 'chunk' module is pretty dumb;  it doesn't understand%0A    # the FORM chunk and the way it contains nested chunks.%0A    # Therefore, first we validate the FORM type is %22IFZS%22, then we%0A    # deliberately seek 12 bytes into the file so the module can start%0A    # sucking out sequential chunks.%0A%0A    header = self._file.read(4)%0A    if header != %22FORM%22:%0A      raise QuetzalUnrecognizedFileFormat%0A%0A    bytestring = self._file.read(4)%0A    self._total_length = 3 ### how to convert '%5Cx00%5Cx00%5Cx02%5Cx08' to decimal?%0A%0A    type = self._file.read(4)%0A    if type != %22IFZS%22:%0A      raise QuetzalUnrecognizedFileFormat%0A%0A    try:%0A      while 1:%0A        c = chunk.Chunk(self._file)%0A        print %22Found chunk with ID%22, c.getname()%0A        print %22   whose length is%22, c.getsize()%0A        c.skip()%0A    except EOFError:%0A      pass%0A%0A    print %22All done parsing.%22%0A    %0A

Add simple quetzal parsing, doesn't do anything yet.