Index: pkpgcounter/trunk/pkpgpdls/pcl345.py
===================================================================
--- pkpgcounter/trunk/pkpgpdls/pcl345.py (revision 3410)
+++ pkpgcounter/trunk/pkpgpdls/pcl345.py (revision 3436)
@@ -8,10 +8,10 @@
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-# 
+#
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
@@ -38,5 +38,5 @@
 class Parser(pdlparser.PDLParser) :
     """A parser for PCL3, PCL4, PCL5 documents."""
-    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -', 
+    totiffcommands = [ 'pcl6 -sDEVICE=pdfwrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -',
                        'pcl6 -sDEVICE=pswrite -r"%(dpi)i" -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -sOutputFile=- "%(infname)s" | gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(outfname)s" -',
                      ]
@@ -48,5 +48,5 @@
                     2 : "Letter",
                     3 : "Legal",
-                    6 : "Ledger", 
+                    6 : "Ledger",
                     25 : "A5",
                     26 : "A4",
@@ -62,6 +62,6 @@
                     100 : "B5Envelope",
                     101 : "Custom",
-                 }   
-                 
+                 }
+
     mediasources = { # ESC&l####H
                      0 : "Default",
@@ -75,5 +75,5 @@
                      8 : "Tray1",
                    }
-                   
+
     orientations = { # ESC&l####O
                      0 : "Portrait",
@@ -82,5 +82,5 @@
                      3 : "ReverseLandscape",
                    }
-                   
+
     mediatypes = { # ESC&l####M
                      0 : "Plain",
@@ -90,6 +90,6 @@
                      4 : "Transparent",
                    }
-        
-    def isValid(self) :    
+
+    def isValid(self) :
         """Returns True if data is PCL3/4/5, else False."""
         try :
@@ -97,7 +97,7 @@
             while self.firstblock[pos] == chr(0) :
                 pos += 1
-        except IndexError :        
+        except IndexError :
             return False
-        else :    
+        else :
             firstblock = self.firstblock[pos:]
             if firstblock.startswith("\033E\033") or \
@@ -111,26 +111,26 @@
                (firstblock.startswith(chr(0xcd)+chr(0xca)) and (firstblock.find("\033E\033") != -1)) :
                 return True
-            else :    
+            else :
                 return False
-        
+
     def setPageDict(self, attribute, value) :
         """Initializes a page dictionnary."""
         dic = self.pages.setdefault(self.pagecount, { "linescount" : 1,
-                                                      "copies" : 1, 
-                                                      "mediasource" : "Main", 
-                                                      "mediasize" : "Default", 
-                                                      "mediatype" : "Plain", 
-                                                      "orientation" : "Portrait", 
-                                                      "escaped" : "", 
+                                                      "copies" : 1,
+                                                      "mediasource" : "Main",
+                                                      "mediasize" : "Default",
+                                                      "mediatype" : "Plain",
+                                                      "orientation" : "Portrait",
+                                                      "escaped" : "",
                                                       "duplex": 0 })
         dic[attribute] = value
-        
-    def readByte(self) :    
+
+    def readByte(self) :
         """Reads a byte from the input stream."""
         tag = ord(self.minfile[self.pos])
         self.pos += 1
         return tag
-        
-    def endPage(self) :    
+
+    def endPage(self) :
         """Handle the FF marker."""
         #self.logdebug("FORMFEED %i at %08x" % (self.pagecount, self.pos-1))
@@ -138,6 +138,6 @@
             # Increments page count only if we are not inside an HPGL2 block
             self.pagecount += 1
-        
-    def escPercent(self) :    
+
+    def escPercent(self) :
         """Handles the ESC% sequence."""
         if self.minfile[self.pos : self.pos+7] == r"-12345X" :
@@ -147,5 +147,5 @@
             quotes = 0
             char = chr(self.readByte())
-            while ((char < ASCIILIMIT) or (quotes % 2)) and (char not in (FORMFEED, ESCAPE, NUL)) :  
+            while ((char < ASCIILIMIT) or (quotes % 2)) and (char not in (FORMFEED, ESCAPE, NUL)) :
                 buffer.append(char)
                 if char == '"' :
@@ -155,5 +155,5 @@
             #self.logdebug("ESCAPED : %s" % "".join(buffer))
             self.pos -= 1   # Adjust position
-        else :    
+        else :
             while 1 :
                 (value, end) = self.getInteger()
@@ -162,57 +162,57 @@
                     while self.minfile[self.pos] != ESCAPE :
                         self.pos += 1
-                    self.pos -= 1    
-                    return 
-                elif end == 'A' :    
+                    self.pos -= 1
+                    return
+                elif end == 'A' :
                     self.exitHPGL2()
                     return
-                elif end is None :    
+                elif end is None :
                     return
-        
-    def enterHPGL2(self) :    
+
+    def enterHPGL2(self) :
         """Enters HPGL2 mode."""
         #self.logdebug("ENTERHPGL2 %08x" % self.pos)
         self.hpgl2 = True
-        
-    def exitHPGL2(self) :    
+
+    def exitHPGL2(self) :
         """Exits HPGL2 mode."""
         #self.logdebug("EXITHPGL2 %08x" % self.pos)
         self.hpgl2 = False
-        
-    def handleTag(self, tagtable) :    
+
+    def handleTag(self, tagtable) :
         """Handles tags."""
         tagtable[self.readByte()]()
-        
-    def escape(self) :    
+
+    def escape(self) :
         """Handles the ESC character."""
         #self.logdebug("ESCAPE")
         self.handleTag(self.esctags)
-        
-    def escAmp(self) :    
+
+    def escAmp(self) :
         """Handles the ESC& sequence."""
         #self.logdebug("AMP")
         self.handleTag(self.escamptags)
-        
-    def escStar(self) :    
+
+    def escStar(self) :
         """Handles the ESC* sequence."""
         #self.logdebug("STAR")
         self.handleTag(self.escstartags)
-        
-    def escLeftPar(self) :    
+
+    def escLeftPar(self) :
         """Handles the ESC( sequence."""
         #self.logdebug("LEFTPAR")
         self.handleTag(self.escleftpartags)
-        
-    def escRightPar(self) :    
+
+    def escRightPar(self) :
         """Handles the ESC( sequence."""
         #self.logdebug("RIGHTPAR")
         self.handleTag(self.escrightpartags)
-        
-    def escE(self) :    
+
+    def escE(self) :
         """Handles the ESCE sequence."""
         #self.logdebug("RESET")
         self.resets += 1
-        
-    def escAmpl(self) :    
+
+    def escAmpl(self) :
         """Handles the ESC&l sequence."""
         while 1 :
@@ -244,5 +244,5 @@
                 self.setPageDict("copies", value)
                 #self.logdebug("COPIES %i" % value)
-            elif end == 'F' :    
+            elif end == 'F' :
                 self.linesperpagevalues.append(value)
                 self.linesperpage = value
@@ -250,6 +250,6 @@
             #else :
             #    self.logdebug("Unexpected end <%s> and value <%s>" % (end, value))
-                
-    def escAmpa(self) :    
+
+    def escAmpa(self) :
         """Handles the ESC&a sequence."""
         while 1 :
@@ -257,10 +257,10 @@
             if value is None :
                 return
-            if end == 'G' :    
+            if end == 'G' :
                 #self.logdebug("BACKSIDES %i" % value)
                 self.backsides.append(value)
                 self.setPageDict("duplex", value)
-                
-    def escAmpp(self) :    
+
+    def escAmpp(self) :
         """Handles the ESC&p sequence."""
         while 1 :
@@ -268,9 +268,9 @@
             if value is None :
                 return
-            if end == 'X' :    
+            if end == 'X' :
                 self.pos += value
                 #self.logdebug("SKIPTO %08x" % self.pos)
-                
-    def escStarb(self) :    
+
+    def escStarb(self) :
         """Handles the ESC*b sequence."""
         while 1 :
@@ -278,9 +278,9 @@
             if (end is None) and (value is None) :
                 return
-            if end in ('V', 'W', 'v', 'w') :    
+            if end in ('V', 'W', 'v', 'w') :
                 self.pos += (value or 0)
                 #self.logdebug("SKIPTO %08x" % self.pos)
-                
-    def escStarr(self) :    
+
+    def escStarr(self) :
         """Handles the ESC*r sequence."""
         while 1 :
@@ -289,9 +289,9 @@
                 if end is None :
                     return
-                elif end in ('B', 'C') :        
+                elif end in ('B', 'C') :
                     #self.logdebug("EndGFX")
                     if self.startgfx :
                         self.endgfx.append(1)
-                    else :    
+                    else :
                         #self.logdebug("EndGFX found before StartGFX, ignored.")
                         pass
@@ -299,6 +299,6 @@
                 #self.logdebug("StartGFX %i" % value)
                 self.startgfx.append(value)
-                
-    def escStaroptAmpu(self) :    
+
+    def escStaroptAmpu(self) :
         """Handles the ESC*o ESC*p ESC*t and ESC&u sequences."""
         while 1 :
@@ -306,6 +306,6 @@
             if value is None :
                 return
-        
-    def escSkipSomethingW(self) :    
+
+    def escSkipSomethingW(self) :
         """Handles the ESC???###W sequences."""
         while 1 :
@@ -313,22 +313,22 @@
             if value is None :
                 return
-            if end == 'W' :    
+            if end == 'W' :
                 self.pos += value
                 #self.logdebug("SKIPTO %08x" % self.pos)
-                
-    def newLine(self) :            
+
+    def newLine(self) :
         """Handles new lines markers."""
         if not self.hpgl2 :
             dic = self.pages.get(self.pagecount, None)
             if dic is None :
-                self.setPageDict("linescount", 1)                              
+                self.setPageDict("linescount", 1)
                 dic = self.pages.get(self.pagecount)
-            nblines = dic["linescount"]    
-            self.setPageDict("linescount", nblines + 1)                              
+            nblines = dic["linescount"]
+            self.setPageDict("linescount", nblines + 1)
             if (self.linesperpage is not None) \
                and (dic["linescount"] > self.linesperpage) :
                 self.pagecount += 1
-        
-    def getInteger(self) :    
+
+    def getInteger(self) :
         """Returns an integer value and the end character."""
         sign = 1
@@ -346,13 +346,13 @@
                 else :
                     return (value, char)
-            else :    
-                value = ((value or 0) * 10) + int(char)    
-        
-    def skipByte(self) :    
+            else :
+                value = ((value or 0) * 10) + int(char)
+
+    def skipByte(self) :
         """Skips a byte."""
         #self.logdebug("SKIPBYTE %08x ===> %02x" % (self.pos, ord(self.minfile[self.pos])))
         self.pos += 1
-        
-    def handleImageRunner(self) :    
+
+    def handleImageRunner(self) :
         """Handles Canon ImageRunner tags."""
         tag = self.readByte()
@@ -367,22 +367,22 @@
         else :
             self.pos -= 1 # Adjust position
-                
-    def getJobSize(self) :     
+
+    def getJobSize(self) :
         """Count pages in a PCL5 document.
-         
+
            Should also work for PCL3 and PCL4 documents.
-           
+
            Algorithm from pclcount
-           (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin 
+           (c) 2003, by Eduardo Gielamo Oliveira & Rodolfo Broco Manin
            published under the terms of the GNU General Public Licence v2.
-          
+
            Backported from C to Python by Jerome Alet, then enhanced
            with more PCL tags detected. I think all the necessary PCL tags
            are recognized to correctly handle PCL5 files wrt their number
            of pages. The documentation used for this was :
-         
+
            HP PCL/PJL Reference Set
            PCL5 Printer Language Technical Quick Reference Guide
-           http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf 
+           http://h20000.www2.hp.com/bc/docs/support/SupportManual/bpl13205/bpl13205.pdf
         """
         infileno = self.infile.fileno()
@@ -405,5 +405,5 @@
         self.imagerunnermarker2 = chr(0x10) + chr(0x02)
         self.isimagerunner = (minfile[:2] == self.imagerunnermarker1)
-        
+
         tags = [ lambda : None] * 256
         tags[ord(LINEFEED)] = self.newLine
@@ -412,5 +412,5 @@
         tags[ord(ASCIILIMIT)] = self.skipByte
         tags[ord(self.imagerunnermarker1[0])] = self.handleImageRunner
-        
+
         self.esctags = [ lambda : None ] * 256
         self.esctags[ord('%')] = self.escPercent
@@ -420,5 +420,5 @@
         self.esctags[ord(')')] = self.escRightPar
         self.esctags[ord('E')] = self.escE
-        
+
         self.escamptags = [lambda : None ] * 256
         self.escamptags[ord('a')] = self.escAmpa
@@ -428,5 +428,5 @@
         self.escamptags[ord('n')] = self.escSkipSomethingW
         self.escamptags[ord('u')] = self.escStaroptAmpu
-        
+
         self.escstartags = [ lambda : None ] * 256
         self.escstartags[ord('b')] = self.escStarb
@@ -441,12 +441,12 @@
         self.escstartags[ord('m')] = self.escSkipSomethingW
         self.escstartags[ord('v')] = self.escSkipSomethingW
-        
+
         self.escleftpartags = [ lambda : None ] * 256
         self.escleftpartags[ord('s')] = self.escSkipSomethingW
         self.escleftpartags[ord('f')] = self.escSkipSomethingW
-        
+
         self.escrightpartags = [ lambda : None ] * 256
         self.escrightpartags[ord('s')] = self.escSkipSomethingW
-        
+
         self.pos = 0
         try :
@@ -454,9 +454,9 @@
                 while 1 :
                     tags[self.readByte()]()
-            except IndexError : # EOF ?            
+            except IndexError : # EOF ?
                 pass
         finally :
             self.minfile.close()
-        
+
         self.logdebug("Pagecount : \t\t\t%i" % self.pagecount)
         self.logdebug("Resets : \t\t\t%i" % self.resets)
@@ -482,9 +482,9 @@
         self.logdebug("NbBackSides : \t\t\t%i" % nbbacksides)
         self.logdebug("IsImageRunner : \t\t\t%s" % self.isimagerunner)
-        
+
         if self.isimagerunner :
             self.logdebug("Adjusting PageCount : +1")
             self.pagecount += 1      # ImageRunner adjustment
-        elif self.linesperpage is not None :    
+        elif self.linesperpage is not None :
             self.logdebug("Adjusting PageCount : +1")
             self.pagecount += 1      # Adjusts for incomplete last page
@@ -507,12 +507,12 @@
             self.logdebug("Adjusting PageCount : -1")
             self.pagecount -= 1
-                    
+
         self.pagecount = self.pagecount or nbmediasourcesdefault or nbmediasizes or nborientations or self.resets
-        
+
         if not self.pagecount :
             if self.resets == len(self.startgfx) :
-                self.pagecount = self.resets 
-        
-        defaultpjlcopies = 1    
+                self.pagecount = self.resets
+
+        defaultpjlcopies = 1
         defaultduplexmode = "Simplex"
         defaultpapersize = ""
@@ -539,16 +539,16 @@
                     pjlcopies = nbqty
                 else :
-                    if oldpjlcopies == -1 :    
+                    if oldpjlcopies == -1 :
                         pjlcopies = defaultpjlcopies
-                    else :    
-                        pjlcopies = oldpjlcopies    
-                if page["duplex"] :        
+                    else :
+                        pjlcopies = oldpjlcopies
+                if page["duplex"] :
                     duplexmode = "Duplex"
-                else :    
+                else :
                     defaultdm = pjlparser.default_variables.get("DUPLEX", "")
                     if defaultdm :
                         if defaultdm.upper() == "ON" :
                             defaultduplexmode = "Duplex"
-                        else :    
+                        else :
                             defaultduplexmode = "Simplex"
                     envdm = pjlparser.environment_variables.get("DUPLEX", "")
@@ -556,7 +556,7 @@
                         if envdm.upper() == "ON" :
                             duplexmode = "Duplex"
-                        else :    
+                        else :
                             duplexmode = "Simplex"
-                    else :        
+                    else :
                         duplexmode = oldduplexmode or defaultduplexmode
                 defaultps = pjlparser.default_variables.get("PAPER", "")
@@ -566,26 +566,26 @@
                 if envps :
                     papersize = envps
-                else :    
+                else :
                     if not oldpapersize :
                         papersize = defaultpapersize
-                    else :    
+                    else :
                         papersize = oldpapersize
-            else :        
+            else :
                 if oldpjlcopies == -1 :
                     pjlcopies = defaultpjlcopies
-                else :    
+                else :
                     pjlcopies = oldpjlcopies
-                
+
                 duplexmode = (page["duplex"] and "Duplex") or oldduplexmode or defaultduplexmode
-                if not oldpapersize :    
+                if not oldpapersize :
                     papersize = defaultpapersize
-                else :    
+                else :
                     papersize = oldpapersize
                 papersize = oldpapersize or page["mediasize"]
             if page["mediasize"] != "Default" :
                 papersize = page["mediasize"]
-            if not duplexmode :    
+            if not duplexmode :
                 duplexmode = oldduplexmode or defaultduplexmode
-            oldpjlcopies = pjlcopies    
+            oldpjlcopies = pjlcopies
             oldduplexmode = duplexmode
             oldpapersize = papersize
@@ -598,4 +598,4 @@
                                               page["mediasource"], \
                                               duplexmode))
-        
+
         return self.pagecount
