38 | | self.infile = infile |
39 | | |
40 | | def getJobSize(self) : |
41 | | """Counts pages in the document.""" |
| 45 | if firstblock is None : |
| 46 | self.infile.seek(0) |
| 47 | firstblock = self.infile.read(FIRSTBLOCKSIZE) |
| 48 | try : |
| 49 | self.infile.seek(-LASTBLOCKSIZE, 2) |
| 50 | lastblock = self.infile.read(LASTBLOCKSIZE) |
| 51 | except IOError : |
| 52 | lastblock = "" |
| 53 | self.infile.seek(0) |
| 54 | self.firstblock = firstblock |
| 55 | self.lastblock = lastblock |
| 56 | if not self.isValid() : |
| 57 | raise PDLParserError, "Invalid file format !" |
| 58 | try : |
| 59 | import psyco |
| 60 | except ImportError : |
| 61 | sys.stderr.write("WARN: you should install psyco if possible, this would greatly speedup parsing.\n") |
| 62 | pass # Psyco is not installed |
| 63 | else : |
| 64 | # Psyco is installed, tell it to compile |
| 65 | # the CPU intensive methods : PCL and PCLXL |
| 66 | # parsing will greatly benefit from this, |
| 67 | # for PostScript and PDF the difference is |
| 68 | # barely noticeable since they are already |
| 69 | # almost optimal, and much more speedy anyway. |
| 70 | psyco.bind(self.getJobSize) |
| 71 | |
| 72 | def isValid(self) : |
| 73 | """Returns 1 if data is in the expected format, else 0.""" |