[328] | 1 | #! /usr/bin/env python |
---|
| 2 | # -*- coding: ISO-8859-15 -*- |
---|
| 3 | # |
---|
| 4 | # pkpgcounter : a generic Page Description Language parser |
---|
| 5 | # |
---|
[443] | 6 | # (c) 2003, 2004, 2005, 2006, 2007 Jerome Alet <alet@librelogiciel.com> |
---|
[463] | 7 | # This program is free software: you can redistribute it and/or modify |
---|
[328] | 8 | # it under the terms of the GNU General Public License as published by |
---|
[463] | 9 | # the Free Software Foundation, either version 3 of the License, or |
---|
[328] | 10 | # (at your option) any later version. |
---|
[463] | 11 | # |
---|
[328] | 12 | # This program is distributed in the hope that it will be useful, |
---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | # GNU General Public License for more details. |
---|
| 16 | # |
---|
| 17 | # You should have received a copy of the GNU General Public License |
---|
[463] | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
[328] | 19 | # |
---|
| 20 | # $Id$ |
---|
| 21 | # |
---|
| 22 | |
---|
[482] | 23 | """This modules implements a page counter for HP LIDIL format.""" |
---|
[357] | 24 | |
---|
[328] | 25 | import sys |
---|
| 26 | import os |
---|
| 27 | import mmap |
---|
| 28 | from struct import unpack |
---|
| 29 | |
---|
| 30 | import pdlparser |
---|
| 31 | |
---|
| 32 | class Parser(pdlparser.PDLParser) : |
---|
[482] | 33 | """A parser for HP LIDIL documents.""" |
---|
[328] | 34 | def isValid(self) : |
---|
[482] | 35 | """Returns True if data is LIDIL, else False.""" |
---|
| 36 | # Beginning Of File marker is a Sync packet, followed with |
---|
| 37 | # a Sync Complete packet followed with a Reset packet. |
---|
| 38 | # We just look at the start of the Sync packet for simplicity's sake. |
---|
| 39 | BOFMarker = "$\x01\x00\x00\x07" |
---|
| 40 | # End Of File marker is a Sync Complete packet followed |
---|
| 41 | # with a Reset packet. We ignore the preceding Sync packet |
---|
| 42 | # for simplicity's sake. |
---|
| 43 | EOFMarker = "$\x00\x10\x00\x08\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$$\x00\x10\x00\x06\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff$" |
---|
| 44 | if self.firstblock.startswith(BOFMarker) \ |
---|
| 45 | and self.lastblock.endswith(EOFMarker) : |
---|
| 46 | self.logdebug("DEBUG: Input file is in the Hewlett-Packard LIDIL format.") |
---|
[387] | 47 | return True |
---|
[328] | 48 | else : |
---|
[387] | 49 | return False |
---|
[328] | 50 | |
---|
| 51 | def getJobSize(self) : |
---|
[482] | 52 | """Computes the number of pages in a HP LIDIL document.""" |
---|
| 53 | return 0 |
---|
| 54 | |
---|
[328] | 55 | if __name__ == "__main__" : |
---|
[415] | 56 | pdlparser.test(Parser) |
---|