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

Improved code robustness.

Files:
1 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