Changeset 3436 for pkpgcounter/trunk/pkpgpdls/cfax.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/cfax.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/>. … … 29 29 """A parser for Structured Fax documents.""" 30 30 format = "Structured Fax" 31 def isValid(self) : 31 def isValid(self) : 32 32 """Returns True if data is Structured Fax, else False.""" 33 33 if self.firstblock.startswith("Sfff") : 34 34 return True 35 else : 35 else : 36 36 return False 37 37 38 38 def getJobSize(self) : 39 39 """Counts pages in a Structured Fax document. 40 40 41 41 Algorithm by Jerome Alet. 42 42 43 43 The documentation used for this was : 44 44 45 45 http://delphi.pjh2.de/articles/graphic/sff_format.php 46 46 """ … … 57 57 offsetlastpage, 58 58 offsetdocumentend) = unpack("<4sBBHHHII", docheader) 59 self.infile.seek(offsetfirstpage - len(docheader), 1) 59 self.infile.seek(offsetfirstpage - len(docheader), 1) 60 60 while True : 61 61 headerid = self.infile.read(1) 62 62 if not headerid : 63 63 break 64 headerid = ord(headerid) 64 headerid = ord(headerid) 65 65 if 1 <= headerid <= 216 : # Normal record header 66 66 self.infile.seek(headerid, 1) … … 69 69 if not additionalbyte : 70 70 break 71 additionalbyte = ord(additionalbyte) 71 additionalbyte = ord(additionalbyte) 72 72 if 1 <= additionalbyte <= 255 : 73 73 # Skip additional user information (reserved) 74 74 self.infile.seek(additionalbyte, 1) 75 elif not headerid : 75 elif not headerid : 76 76 # Record with more than 216 MH-coded bytes 77 77 recordlen = self.infile.read(2) 78 78 if not recordlen : 79 79 break 80 recordlen = unpack("<H", recordlen)[0] 80 recordlen = unpack("<H", recordlen)[0] 81 81 self.infile.seek(recordlen, 1) 82 82 elif headerid == 254 : # Page header 83 83 pageheader = self.infile.read(17) 84 if not pageheader : 84 if not pageheader : 85 85 break 86 86 headerlen = ord(pageheader[0]) … … 95 95 offsetpreviouspage, 96 96 offsetnextpage) = unpack("<4BHHII", pageheader[1:]) 97 pagecount += 1 97 pagecount += 1 98 98 if (offsetnextpage == 1) or (vres == 255) : 99 99 break # End Of Document 100 self.infile.seek(offsetnextpage, 1) 101 except struct.error : 100 self.infile.seek(offsetnextpage, 1) 101 except struct.error : 102 102 raise pdlparser.PDLParserError, "Invalid Structured Fax datas" 103 return max(docpagecount, pagecount) 103 return max(docpagecount, pagecount)