67 | | try : |
68 | | try : |
69 | | while 1 : |
70 | | header = minfile[pos:pos+16] |
71 | | if len(header) != 16 : |
72 | | break |
73 | | totalChunkSize = unpack(self.unpackLong, header[:4])[0] |
74 | | chunkType = unpack(self.unpackLong, header[4:8])[0] |
75 | | numberOfItems = unpack(self.unpackLong, header[8:12])[0] |
76 | | reserved = unpack(self.unpackShort, header[12:14])[0] |
77 | | signature = unpack(self.unpackShort, header[14:])[0] |
78 | | pos += totalChunkSize |
79 | | if chunkType == 0 : |
80 | | self.logdebug("startDoc") |
81 | | elif chunkType == 1 : |
82 | | self.logdebug("endDoc") |
83 | | elif chunkType == 2 : |
84 | | self.logdebug("startPage") |
85 | | startpagecount += 1 |
86 | | elif chunkType == 3 : |
87 | | self.logdebug("endPage") |
88 | | endpagecount += 1 |
89 | | |
90 | | #self.logdebug("Chunk size : %s" % totalChunkSize) |
91 | | #self.logdebug("Chunk type : 0x%08x" % chunkType) |
92 | | #self.logdebug("# items : %s" % numberOfItems) |
93 | | #self.logdebug("reserved : 0x%04x" % reserved) |
94 | | #self.logdebug("signature : 0x%04x" % signature) |
95 | | #self.logdebug("\n") |
96 | | except IndexError : # EOF ? |
97 | | pass |
98 | | finally : |
99 | | minfile.close() |
| 57 | while True : |
| 58 | header = self.infile.read(16) |
| 59 | if not header : |
| 60 | break |
| 61 | try : |
| 62 | (totalChunkSize, |
| 63 | chunkType, |
| 64 | numberOfItems, |
| 65 | reserved, |
| 66 | signature) = unpack(self.unpackHeader, header) |
| 67 | except struct.error : |
| 68 | raise pdlparser.PDLParserError, "This file doesn't seem to be valid ZjStream datas." |
| 69 | self.infile.seek(totalChunkSize - len(header), 1) |
| 70 | if chunkType == 2 : |
| 71 | #self.logdebug("startPage") |
| 72 | startpagecount += 1 |
| 73 | elif chunkType == 3 : |
| 74 | #self.logdebug("endPage") |
| 75 | endpagecount += 1 |
| 76 | #elif chunkType == 0 : |
| 77 | # self.logdebug("startDoc") |
| 78 | #elif chunkType == 1 : |
| 79 | # self.logdebug("endDoc") |
| 80 | |
| 81 | #self.logdebug("Chunk size : %s" % totalChunkSize) |
| 82 | #self.logdebug("Chunk type : 0x%08x" % chunkType) |
| 83 | #self.logdebug("# items : %s" % numberOfItems) |
| 84 | #self.logdebug("reserved : 0x%04x" % reserved) |
| 85 | #self.logdebug("signature : 0x%04x" % signature) |
| 86 | #self.logdebug("\n") |
101 | | if startpagecount != endpagecount : |
102 | | sys.stderr.write("ERROR: Incorrect ZjStream datas.\n") |
| 88 | # Number of endpage commands should be sufficient, |
| 89 | # but we never know : someone could try to cheat the printer |
| 90 | # by starting a page but not ending it, and ejecting it manually |
| 91 | # later on. Not sure if the printers would support this, but |
| 92 | # taking the max value works around the problem in any case. |
| 93 | self.logdebug("StartPage : %i EndPage : %i" % (startpagecount, endpagecount)) |