Changeset 3436 for pkpgcounter/trunk/pkpgpdls/spl1.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/spl1.py
r3410 r3436 8 8 # the Free Software Foundation, either version 3 of the License, or 9 9 # (at your option) any later version. 10 # 10 # 11 11 # This program is distributed in the hope that it will be useful, 12 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 # GNU General Public License for more details. 15 # 15 # 16 16 # You should have received a copy of the GNU General Public License 17 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 34 34 """A parser for SPL1 documents.""" 35 35 format = "SPL1 (aka GDI)" 36 def isValid(self) : 36 def isValid(self) : 37 37 """Returns True if data is SPL1, else False.""" 38 38 if ((self.firstblock[:128].find("\033%-12345X") != -1) and \ … … 41 41 (self.firstblock.find("LANGUAGE = SMART") != -1))) : 42 42 return True 43 else : 43 else : 44 44 return False 45 45 46 46 def littleEndian(self) : 47 47 """Toggles to little endianness.""" … … 51 51 # self.logdebug("Little Endian") 52 52 return 0 53 53 54 54 def bigEndian(self) : 55 55 """Toggles to big endianness.""" … … 59 59 # self.logdebug("Big Endian") 60 60 return 0 61 62 def escape(self, nextpos) : 61 62 def escape(self, nextpos) : 63 63 """Handles the ESC code.""" 64 64 self.isbitmap = False … … 67 67 if minfile[pos : pos+8] == r"%-12345X" : 68 68 endpos = pos + 9 69 elif minfile[pos-1] in ESCAPECHARS : 69 elif minfile[pos-1] in ESCAPECHARS : 70 70 endpos = pos 71 else : 71 else : 72 72 return 0 73 73 endmark = (chr(0x1b), chr(0x00)) … … 79 79 quotes += 1 80 80 endpos += 1 81 82 # Store this in a per page mapping. 81 82 # Store this in a per page mapping. 83 83 # NB : First time will be at page 0 (i.e. **before** page 1) ! 84 84 stuff = self.escapedStuff.setdefault(self.pagecount, []) … … 90 90 self.logdebug("Escaped datas : [%s]" % repr(datas)) 91 91 return endpos - pos + 1 92 92 93 93 def getJobSize(self) : 94 94 """Counts pages in an SPL1 document. 95 95 96 96 Algorithm by Jerome Alet. 97 97 """ … … 110 110 if tag in ESCAPECHARS : 111 111 pos += self.escape(pos+1) 112 else : 112 else : 113 113 if not self.isbitmap : 114 114 raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized. Parsing aborted. Please report the problem to %s" % version.__authoremail__ … … 116 116 seqnum) = unpack(">IH", minfile[pos:pos+6]) 117 117 # self.logdebug("Offset : %i Sequence Number : %i" % (offset, seqnum)) 118 if not seqnum : 118 if not seqnum : 119 119 # Sequence number resets to 0 for each new page. 120 120 self.pagecount += 1 121 121 pos += 4 + offset 122 except struct.error, msg : 122 except struct.error, msg : 123 123 raise pdlparser.PDLParserError, "Unfortunately SPL1 is incompletely recognized (%s). Parsing aborted. Please report the problem to %s" % (msg, version.__authoremail__) 124 except IndexError : # EOF ? 124 except IndexError : # EOF ? 125 125 pass 126 126 finally :