Show
Ignore:
Timestamp:
11/30/07 23:48:03 (17 years ago)
Author:
jerome
Message:

Moved try/except out of the main loop to increase performance.

Files:
1 modified

Legend:

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

    r522 r532  
    7373        unpack = struct.unpack 
    7474        ejectpage = loadpage = 0 
    75         while True : 
    76             header = self.infile.read(HEADERSIZE) 
    77             if not header : 
    78                 break 
    79             if (len(header) != HEADERSIZE) or (header[0] != "$") : 
    80                 # Invalid header or no Frame Sync byte. 
    81                 raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." 
    82             try :     
     75        try : 
     76            while True : 
     77                header = self.infile.read(HEADERSIZE) 
     78                if not header : 
     79                    break 
     80                if (len(header) != HEADERSIZE) or (header[0] != "$") : 
     81                    # Invalid header or no Frame Sync byte. 
     82                    raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." 
    8383                (framesync,      
    8484                 cmdlength, 
     
    8888                 referencenumber, 
    8989                 datalength) = unpack(">BHBBBHH", header) 
    90             except struct.error :     
    91                 raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." 
    92             if packettype == PACKET_TYPE_COMMAND : 
    93                 if commandnumber == LDL_LOAD_PAGE : 
    94                     loadpage += 1 
    95                 elif commandnumber == LDL_EJECT_PAGE : 
    96                     ejectpage += 1 
    97             self.infile.seek(cmdlength + datalength - len(header), 1) # relative seek 
     90                if packettype == PACKET_TYPE_COMMAND : 
     91                    if commandnumber == LDL_LOAD_PAGE : 
     92                        loadpage += 1 
     93                    elif commandnumber == LDL_EJECT_PAGE : 
     94                        ejectpage += 1 
     95                self.infile.seek(cmdlength + datalength - len(header), 1) # relative seek 
     96        except struct.error :     
     97            raise pdlparser.PDLParserError, "This file doesn't seem to be valid Hewlett-Packard LIDIL datas." 
    9898             
    9999        # Number of page eject commands should be sufficient,