Show
Ignore:
Timestamp:
11/30/07 23:48:48 (17 years ago)
Author:
jerome
Message:

Fixed a problem which was due to a too small test suite for SPL1
file format.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/spl1.py

    r522 r533  
    2323"""This modules implements a page counter for SPL1 documents.""" 
    2424 
    25 import sys 
    2625import os 
    2726import mmap 
    28 from struct import unpack 
     27import struct 
    2928 
    3029import pdlparser 
     
    5150        self.unpackShort = self.unpackType[2] 
    5251        self.unpackLong = self.unpackType[4] 
     52        # self.logdebug("Little Endian") 
    5353        return 0 
    5454         
     
    5858        self.unpackShort = self.unpackType[2] 
    5959        self.unpackLong = self.unpackType[4] 
     60        # self.logdebug("Big Endian") 
    6061        return 0 
    6162     
     
    8788        if datas.endswith("$PJL BITMAP START\r\n") : 
    8889            self.isbitmap = True 
     90            # self.logdebug("New bitmap") 
    8991        self.logdebug("Escaped datas : [%s]" % repr(datas)) 
    9092        return endpos - pos + 1 
     
    100102        self.escapedStuff = {}   # For escaped datas, mostly PJL commands 
    101103        self.bigEndian() 
    102         codesop = chr(0x06) + chr(0x00) + chr(0x00) + chr(0x80) + chr(0x13) + chr(0x40) 
    103104        self.isbitmap = False 
    104105        pos = 0 
     106        unpack = struct.unpack 
    105107        try : 
    106108            try : 
     
    112114                        if not self.isbitmap : 
    113115                            raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized. Parsing aborted. Please report the problem to %s" % version.__authoremail__ 
    114                         offset = unpack(self.unpackLong, minfile[pos:pos+4])[0] 
    115                         sequencenum = unpack(self.unpackShort, minfile[pos+4:pos+6])[0] 
    116                         if minfile[pos+6:pos+12] != codesop : 
    117                             raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized. Parsing aborted. Please report the problem to %s" % version.__authoremail__ 
    118                         if not sequencenum : 
     116                        (offset, 
     117                         seqnum) = unpack(">IH", minfile[pos:pos+6]) 
     118                        # self.logdebug("Offset : %i      Sequence Number : %i" % (offset, seqnum)) 
     119                        if not seqnum :  
     120                            # Sequence number resets to 0 for each new page. 
    119121                            self.pagecount += 1 
    120122                        pos += 4 + offset 
     123            except struct.error, msg :      
     124                raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized (%s). Parsing aborted. Please report the problem to %s" % (msg, version.__authoremail__) 
    121125            except IndexError : # EOF ?             
    122126                pass