Index: pkpgcounter/trunk/pkpgpdls/pcl345.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pcl345.py (revision 305)
+++ pkpgcounter/trunk/pkpgpdls/pcl345.py (revision 307)
@@ -148,163 +148,166 @@
         pos = 0
         try :
-            while 1 :
-                if hasirmarker and (minfile[pos:pos+2] == irmarker) :
-                    codop = minfile[pos+2:pos+4]
-                    # self.logdebug("Marker at 0x%08x     (%s)" % (pos, wasirmarker))
-                    length = unpack(">H", minfile[pos+8:pos+10])[0]
-                    pos += 20
-                    if codop != irmarker2 :
-                        pos += length
-                    wasirmarker = 1    
-                else :        
-                    wasirmarker = 0
-                    char = minfile[pos] ; pos += 1
-                    if char == "\014" :    
-                        pagecount += 1
-                    elif char == "\033" :    
-                        starb = ampl = 0
-                        if minfile[pos : pos+8] == r"%-12345X" :
-                            endpos = pos + 9
-                            quotes = 0
-                            while (minfile[endpos] not in endmark) and \
-                                  ((minfile[endpos] < asciilimit) or (quotes % 2)) :
-                                if minfile[endpos] == '"' :
-                                    quotes += 1
-                                endpos += 1
-                            self.setPageDict(pages, pagecount, "escaped", minfile[pos : endpos])
-                            pos += (endpos - pos)
-                        else :
-                            #
-                            #     <ESC>*b###y#m###v###w... -> PCL3 raster graphics
-                            #     <ESC>*b###W -> Start of a raster data row/block
-                            #     <ESC>*b###V -> Start of a raster data plane
-                            #     <ESC>*c###W -> Start of a user defined pattern
-                            #     <ESC>*i###W -> Start of a viewing illuminant block
-                            #     <ESC>*l###W -> Start of a color lookup table
-                            #     <ESC>*m###W -> Start of a download dither matrix block
-                            #     <ESC>*v###W -> Start of a configure image data block
-                            #     <ESC>*r1A -> Start Gfx 
-                            #     <ESC>(s###W -> Start of a characters description block
-                            #     <ESC>)s###W -> Start of a fonts description block
-                            #     <ESC>(f###W -> Start of a symbol set block
-                            #     <ESC>&b###W -> Start of configuration data block
-                            #     <ESC>&l###X -> Number of copies for current page
-                            #     <ESC>&n###W -> Starts an alphanumeric string ID block
-                            #     <ESC>&p###X -> Start of a non printable characters block
-                            #     <ESC>&a2G -> Back side when duplex mode as generated by rastertohp
-                            #     <ESC>*g###W -> Needed for planes in PCL3 output
-                            #     <ESC>&l###H (or only 0 ?) -> Eject if NumPlanes > 1, as generated by rastertohp. Also defines mediasource
-                            #     <ESC>&l###A -> mediasize
-                            #     <ESC>&l###O -> orientation
-                            #     <ESC>&l###M -> mediatype
-                            #     <ESC>*t###R -> gfx resolution
-                            #
-                            tagstart = minfile[pos] ; pos += 1
-                            if tagstart in "E9=YZ" : # one byte PCL tag
-                                if tagstart == "E" :
-                                    resets += 1
-                                continue             # skip to next tag
-                            tag = tagstart + minfile[pos] ; pos += 1
-                            if tag == "*b" : 
-                                starb = 1
-                                tagend = "VW"
-                            elif tag == "&l" :    
-                                ampl = 1
-                                tagend = "XHAOM"
-                            else :    
-                                try :
-                                    tagend = tagsends[tag]
-                                except KeyError :    
-                                    continue # Unsupported PCL tag
-                            # Now read the numeric argument
-                            size = 0
-                            while 1 :
-                                char = minfile[pos] ; pos += 1
-                                if not char.isdigit() :
-                                    break
-                                size = (size * 10) + int(char)    
-                            if char in tagend :    
-                                if tag == "&l" :
-                                    if char == "X" : 
-                                        self.setPageDict(pages, pagecount, "copies", size)
-                                    elif char == "H" :
+            try :
+                while 1 :
+                    if hasirmarker and (minfile[pos:pos+2] == irmarker) :
+                        codop = minfile[pos+2:pos+4]
+                        # self.logdebug("Marker at 0x%08x     (%s)" % (pos, wasirmarker))
+                        length = unpack(">H", minfile[pos+8:pos+10])[0]
+                        pos += 20
+                        if codop != irmarker2 :
+                            pos += length
+                        wasirmarker = 1    
+                    else :        
+                        wasirmarker = 0
+                        char = minfile[pos] ; pos += 1
+                        if char == "\014" :    
+                            pagecount += 1
+                        elif char == "\033" :    
+                            starb = ampl = 0
+                            if minfile[pos : pos+8] == r"%-12345X" :
+                                endpos = pos + 9
+                                quotes = 0
+                                while (minfile[endpos] not in endmark) and \
+                                      ((minfile[endpos] < asciilimit) or (quotes % 2)) :
+                                    if minfile[endpos] == '"' :
+                                        quotes += 1
+                                    endpos += 1
+                                self.setPageDict(pages, pagecount, "escaped", minfile[pos : endpos])
+                                pos += (endpos - pos)
+                            else :
+                                #
+                                #     <ESC>*b###y#m###v###w... -> PCL3 raster graphics
+                                #     <ESC>*b###W -> Start of a raster data row/block
+                                #     <ESC>*b###V -> Start of a raster data plane
+                                #     <ESC>*c###W -> Start of a user defined pattern
+                                #     <ESC>*i###W -> Start of a viewing illuminant block
+                                #     <ESC>*l###W -> Start of a color lookup table
+                                #     <ESC>*m###W -> Start of a download dither matrix block
+                                #     <ESC>*v###W -> Start of a configure image data block
+                                #     <ESC>*r1A -> Start Gfx 
+                                #     <ESC>(s###W -> Start of a characters description block
+                                #     <ESC>)s###W -> Start of a fonts description block
+                                #     <ESC>(f###W -> Start of a symbol set block
+                                #     <ESC>&b###W -> Start of configuration data block
+                                #     <ESC>&l###X -> Number of copies for current page
+                                #     <ESC>&n###W -> Starts an alphanumeric string ID block
+                                #     <ESC>&p###X -> Start of a non printable characters block
+                                #     <ESC>&a2G -> Back side when duplex mode as generated by rastertohp
+                                #     <ESC>*g###W -> Needed for planes in PCL3 output
+                                #     <ESC>&l###H (or only 0 ?) -> Eject if NumPlanes > 1, as generated by rastertohp. Also defines mediasource
+                                #     <ESC>&l###A -> mediasize
+                                #     <ESC>&l###O -> orientation
+                                #     <ESC>&l###M -> mediatype
+                                #     <ESC>*t###R -> gfx resolution
+                                #
+                                tagstart = minfile[pos] ; pos += 1
+                                if tagstart in "E9=YZ" : # one byte PCL tag
+                                    if tagstart == "E" :
+                                        resets += 1
+                                    continue             # skip to next tag
+                                tag = tagstart + minfile[pos] ; pos += 1
+                                if tag == "*b" : 
+                                    starb = 1
+                                    tagend = "VW"
+                                elif tag == "&l" :    
+                                    ampl = 1
+                                    tagend = "XHAOM"
+                                else :    
+                                    try :
+                                        tagend = tagsends[tag]
+                                    except KeyError :    
+                                        continue # Unsupported PCL tag
+                                # Now read the numeric argument
+                                size = 0
+                                while 1 :
+                                    char = minfile[pos] ; pos += 1
+                                    if not char.isdigit() :
+                                        break
+                                    size = (size * 10) + int(char)    
+                                if char in tagend :    
+                                    if tag == "&l" :
+                                        if char == "X" : 
+                                            self.setPageDict(pages, pagecount, "copies", size)
+                                        elif char == "H" :
+                                            self.setPageDict(pages, pagecount, "mediasource", self.mediasources.get(size, str(size)))
+                                            mediasourcecount += 1
+                                            ejects += 1 
+                                        elif char == "A" :
+                                            self.setPageDict(pages, pagecount, "mediasize", self.mediasizes.get(size, str(size)))
+                                            mediasizecount += 1
+                                        elif char == "O" :
+                                            self.setPageDict(pages, pagecount, "orientation", self.orientations.get(size, str(size)))
+                                            orientationcount += 1
+                                        elif char == "M" :
+                                            self.setPageDict(pages, pagecount, "mediatype", self.mediatypes.get(size, str(size)))
+                                            mediatypecount += 1
+                                    elif tag == "*r" :
+                                        # Special tests for PCL3
+                                        if (char == "s") and size :
+                                            while 1 :
+                                                char = minfile[pos] ; pos += 1
+                                                if char == "A" :
+                                                    break
+                                        elif (char == "b") and (minfile[pos] == "C") and not size :
+                                            ispcl3 = 1 # Certainely a PCL3 file
+                                        startgfx += (char == "A") and (minfile[pos - 2] in ("0", "1", "2", "3")) # Start Gfx
+                                        endgfx += (not size) and (char in ("C", "B")) # End Gfx
+                                    elif tag == "*t" :    
+                                        escstart += 1
+                                    elif (tag == "&a") and (size == 2) :
+                                        # We are on the backside, so mark current page as duplex
+                                        self.setPageDict(pages, pagecount, "duplex", 1)
+                                        backsides += 1      # Back side in duplex mode
+                                    else :    
+                                        # we just ignore the block.
+                                        if tag == "&n" : 
+                                            # we have to take care of the operation id byte
+                                            # which is before the string itself
+                                            size += 1
+                                        pos += size    
+                        else :                            
+                            if starb :
+                                # special handling of PCL3 in which 
+                                # *b introduces combined ESCape sequences
+                                size = 0
+                                while 1 :
+                                    char = minfile[pos] ; pos += 1
+                                    if not char.isdigit() :
+                                        break
+                                    size = (size * 10) + int(char)    
+                                if char in ("w", "v") :    
+                                    ispcl3 = 1  # certainely a PCL3 document
+                                    pos += size - 1
+                                elif char in ("y", "m") :    
+                                    ispcl3 = 1  # certainely a PCL3 document
+                                    pos -= 1    # fix position : we were ahead
+                            elif ampl :        
+                                # special handling of PCL3 in which 
+                                # &l introduces combined ESCape sequences
+                                size = 0
+                                while 1 :
+                                    char = minfile[pos] ; pos += 1
+                                    if not char.isdigit() :
+                                        break
+                                    size = (size * 10) + int(char)    
+                                if char in ("a", "o", "h", "m") :    
+                                    ispcl3 = 1  # certainely a PCL3 document
+                                    pos -= 1    # fix position : we were ahead
+                                    if char == "h" :
                                         self.setPageDict(pages, pagecount, "mediasource", self.mediasources.get(size, str(size)))
                                         mediasourcecount += 1
-                                        ejects += 1 
-                                    elif char == "A" :
+                                    elif char == "a" :
                                         self.setPageDict(pages, pagecount, "mediasize", self.mediasizes.get(size, str(size)))
                                         mediasizecount += 1
-                                    elif char == "O" :
+                                    elif char == "o" :
                                         self.setPageDict(pages, pagecount, "orientation", self.orientations.get(size, str(size)))
                                         orientationcount += 1
-                                    elif char == "M" :
+                                    elif char == "m" :
                                         self.setPageDict(pages, pagecount, "mediatype", self.mediatypes.get(size, str(size)))
                                         mediatypecount += 1
-                                elif tag == "*r" :
-                                    # Special tests for PCL3
-                                    if (char == "s") and size :
-                                        while 1 :
-                                            char = minfile[pos] ; pos += 1
-                                            if char == "A" :
-                                                break
-                                    elif (char == "b") and (minfile[pos] == "C") and not size :
-                                        ispcl3 = 1 # Certainely a PCL3 file
-                                    startgfx += (char == "A") and (minfile[pos - 2] in ("0", "1", "2", "3")) # Start Gfx
-                                    endgfx += (not size) and (char in ("C", "B")) # End Gfx
-                                elif tag == "*t" :    
-                                    escstart += 1
-                                elif (tag == "&a") and (size == 2) :
-                                    # We are on the backside, so mark current page as duplex
-                                    self.setPageDict(pages, pagecount, "duplex", 1)
-                                    backsides += 1      # Back side in duplex mode
-                                else :    
-                                    # we just ignore the block.
-                                    if tag == "&n" : 
-                                        # we have to take care of the operation id byte
-                                        # which is before the string itself
-                                        size += 1
-                                    pos += size    
-                    else :                            
-                        if starb :
-                            # special handling of PCL3 in which 
-                            # *b introduces combined ESCape sequences
-                            size = 0
-                            while 1 :
-                                char = minfile[pos] ; pos += 1
-                                if not char.isdigit() :
-                                    break
-                                size = (size * 10) + int(char)    
-                            if char in ("w", "v") :    
-                                ispcl3 = 1  # certainely a PCL3 document
-                                pos += size - 1
-                            elif char in ("y", "m") :    
-                                ispcl3 = 1  # certainely a PCL3 document
-                                pos -= 1    # fix position : we were ahead
-                        elif ampl :        
-                            # special handling of PCL3 in which 
-                            # &l introduces combined ESCape sequences
-                            size = 0
-                            while 1 :
-                                char = minfile[pos] ; pos += 1
-                                if not char.isdigit() :
-                                    break
-                                size = (size * 10) + int(char)    
-                            if char in ("a", "o", "h", "m") :    
-                                ispcl3 = 1  # certainely a PCL3 document
-                                pos -= 1    # fix position : we were ahead
-                                if char == "h" :
-                                    self.setPageDict(pages, pagecount, "mediasource", self.mediasources.get(size, str(size)))
-                                    mediasourcecount += 1
-                                elif char == "a" :
-                                    self.setPageDict(pages, pagecount, "mediasize", self.mediasizes.get(size, str(size)))
-                                    mediasizecount += 1
-                                elif char == "o" :
-                                    self.setPageDict(pages, pagecount, "orientation", self.orientations.get(size, str(size)))
-                                    orientationcount += 1
-                                elif char == "m" :
-                                    self.setPageDict(pages, pagecount, "mediatype", self.mediatypes.get(size, str(size)))
-                                    mediatypecount += 1
-        except IndexError : # EOF ?
-            minfile.close() # reached EOF
+            except IndexError : # EOF ?
+                pass
+        finally :
+            minfile.close()
                             
         # if pagecount is still 0, we will use the number
Index: pkpgcounter/trunk/pkpgpdls/pclxl.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pclxl.py (revision 302)
+++ pkpgcounter/trunk/pkpgpdls/pclxl.py (revision 307)
@@ -289,5 +289,5 @@
     def reservedForFutureUse(self) :
         """Outputs something when a reserved byte is encountered."""
-        self.logdebug("Byte at %s is out of the PCLXL Protocol Class 2.0 Specification" % self.pos)
+        self.logdebug("Byte at %x is out of the PCLXL Protocol Class 2.0 Specification" % self.pos)
         return 0    
         
@@ -295,5 +295,5 @@
         """Passthrough mode, as detailed in PCLXL Feature Reference Protocol Class 3.0 Supplement."""
         # TODO : do something here to skip the block.
-        self.logdebug("PassThrough marker detected at %s" % self.pos)
+        self.logdebug("PassThrough marker detected at %x" % self.pos)
         return 0
         
@@ -529,19 +529,25 @@
         self.pagecount = 0
         self.escapedStuff = {}
-        self.pos = pos = 0
+        self.pos = pos = oldpos = 0
         try :
-            while 1 :
-                char = minfile[pos]
-                pos += 1
-                length = tags[ord(char)]
-                if not length :
-                    continue
-                if callable(length) :    
-                    self.pos = pos
-                    length = length()
-                    pos = self.pos
-                pos += length    
-        except IndexError : # EOF ?
-            self.minfile.close() # reached EOF
+            try :
+                while 1 :
+                    try :
+                        char = minfile[pos]
+                    except OverflowError :    
+                        pos = oldpos + 1
+                    pos += 1
+                    length = tags[ord(char)]
+                    if length :
+                        if callable(length) :    
+                            self.pos = pos
+                            length = length()
+                            pos = self.pos
+                        oldpos = pos    
+                        pos += length    
+            except IndexError : # EOF ?            
+                pass
+        finally :
+            self.minfile.close()
             
         # now handle number of copies for each page (may differ).
Index: pkpgcounter/trunk/pkpgpdls/version.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/version.py (revision 305)
+++ pkpgcounter/trunk/pkpgpdls/version.py (revision 307)
@@ -20,5 +20,5 @@
 #
 
-__version__ = "1.75"
+__version__ = "1.76beta"
 
 __doc__ = """pkpgcounter : a generic Page Description Languages parser."""
