76 | | infileno = self.infile.fileno() |
77 | | minfile = mmap.mmap(infileno, os.fstat(infileno)[6], prot=mmap.PROT_READ, flags=mmap.MAP_SHARED) |
78 | | pos = 0 |
79 | | try : |
80 | | try : |
81 | | while 1 : |
82 | | if minfile[pos] != "$" : # Frame Sync |
83 | | raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas" |
84 | | try : |
85 | | (framesync, |
86 | | cmdlength, |
87 | | dummy, |
88 | | packettype, |
89 | | commandnumber, |
90 | | referencenumber, |
91 | | datalength) = unpack(">BHBBBHH", minfile[pos:pos+10]) |
92 | | except struct.error : |
93 | | raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas" |
94 | | if packettype == PACKET_TYPE_COMMAND : |
95 | | if commandnumber == LDL_LOAD_PAGE : |
96 | | loadpage += 1 |
97 | | elif commandnumber == LDL_EJECT_PAGE : |
98 | | ejectpage += 1 |
99 | | pos += (cmdlength + datalength) |
100 | | except IndexError : # EOF ? |
101 | | pass |
102 | | finally : |
103 | | minfile.close() |
| 75 | while True : |
| 76 | header = self.infile.read(HEADERSIZE) |
| 77 | if not header : |
| 78 | break |
| 79 | if (len(header) != HEADERSIZE) or (header[0] != "$") : |
| 80 | # Invalid header or no Frame Sync byte. |
| 81 | raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." |
| 82 | try : |
| 83 | (framesync, |
| 84 | cmdlength, |
| 85 | dummy, |
| 86 | packettype, |
| 87 | commandnumber, |
| 88 | referencenumber, |
| 89 | datalength) = unpack(">BHBBBHH", header) |
| 90 | except struct.error : |
| 91 | raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." |
| 92 | if packettype == PACKET_TYPE_COMMAND : |
| 93 | if commandnumber == LDL_LOAD_PAGE : |
| 94 | loadpage += 1 |
| 95 | elif commandnumber == LDL_EJECT_PAGE : |
| 96 | ejectpage += 1 |
| 97 | self.infile.seek(cmdlength + datalength - len(header), 1) # relative seek |