Changeset 489

Show
Ignore:
Timestamp:
11/17/07 16:21:11 (16 years ago)
Author:
jerome
Message:

Improved code robustness.

Location:
pkpgcounter/trunk/pkpgpdls
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/dvi.py

    r463 r489  
    6060        postchar = chr(0xf8) 
    6161        try : 
    62             while minfile[pos] == eofchar : 
    63                 pos -= 1 
    64             idbyte = minfile[pos]     
    65             if idbyte != minfile[1] : 
    66                 raise IndexError, "Invalid DVI file." 
    67             pos = unpack(">I", minfile[pos - 4:pos])[0] 
    68             if minfile[pos] != postchar : 
    69                 raise IndexError, "Invalid DVI file." 
    70             pagecount = unpack(">H", minfile[pos + 27: pos + 29])[0] 
    71         except IndexError : # EOF ? 
    72             pass 
    73         minfile.close() # reached EOF 
     62            try : 
     63                while minfile[pos] == eofchar : 
     64                    pos -= 1 
     65                idbyte = minfile[pos]     
     66                if idbyte != minfile[1] : 
     67                    raise IndexError, "Invalid DVI file." 
     68                pos = unpack(">I", minfile[pos - 4:pos])[0] 
     69                if minfile[pos] != postchar : 
     70                    raise IndexError, "Invalid DVI file." 
     71                pagecount = unpack(">H", minfile[pos + 27: pos + 29])[0] 
     72            except IndexError : # EOF ? 
     73                pass 
     74        finally :         
     75            minfile.close() # reached EOF 
    7476        return pagecount 
    7577         
  • pkpgcounter/trunk/pkpgpdls/hbp.py

    r480 r489  
    6161        pos = 0 
    6262        try : 
    63             while True : 
    64                 if (minfile[pos] == "@") \ 
    65                    and (minfile[pos:pos+fflen] == formfeed) : 
    66                     pagecount += 1 
    67                     pos += fflen 
    68                 else :         
    69                     pos += 1 
    70         except IndexError : # EOF ? 
    71             pass 
    72         minfile.close() # reached EOF 
     63            try : 
     64                while True : 
     65                    if (minfile[pos] == "@") \ 
     66                       and (minfile[pos:pos+fflen] == formfeed) : 
     67                        pagecount += 1 
     68                        pos += fflen 
     69                    else :         
     70                        pos += 1 
     71            except IndexError : # EOF ? 
     72                pass 
     73        finally :         
     74            minfile.close() # reached EOF 
    7375        return pagecount 
    7476         
  • pkpgcounter/trunk/pkpgpdls/tiff.py

    r463 r489  
    6666            raise pdlparser.PDLParserError, "Unknown file endianness." 
    6767        pos = 4     
    68         try :     
    69             nextifdoffset = unpack(integerbyteorder, minfile[pos : pos + 4])[0] 
    70             while nextifdoffset : 
    71                 direntrycount = unpack(shortbyteorder, minfile[nextifdoffset : nextifdoffset + 2])[0] 
    72                 pos = nextifdoffset + 2 + (direntrycount * 12) 
     68        try : 
     69            try :     
    7370                nextifdoffset = unpack(integerbyteorder, minfile[pos : pos + 4])[0] 
    74                 pagecount += 1 
    75         except IndexError :             
    76             pass 
    77         minfile.close() 
     71                while nextifdoffset : 
     72                    direntrycount = unpack(shortbyteorder, minfile[nextifdoffset : nextifdoffset + 2])[0] 
     73                    pos = nextifdoffset + 2 + (direntrycount * 12) 
     74                    nextifdoffset = unpack(integerbyteorder, minfile[pos : pos + 4])[0] 
     75                    pagecount += 1 
     76            except IndexError :             
     77                pass 
     78        finally :         
     79            minfile.close() 
    7880        return pagecount 
    7981