Index: pykota/trunk/pykota/accounters/pjl.py
===================================================================
--- pykota/trunk/pykota/accounters/pjl.py (revision 3411)
+++ pykota/trunk/pykota/accounters/pjl.py (revision 3413)
@@ -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/>.
@@ -21,6 +21,6 @@
 #
 
-"""This module defines the necessary classes and methods to retrieve 
-a printer's internal page counter over a TCP connection.""" 
+"""This module defines the necessary classes and methods to retrieve
+a printer's internal page counter over a TCP connection."""
 
 import sys
@@ -36,7 +36,7 @@
 
 # Old method : PJLMESSAGE = "\033%-12345X@PJL USTATUSOFF\r\n@PJL INFO STATUS\r\n@PJL INFO PAGECOUNT\r\n\033%-12345X"
-# Here's a new method, which seems to work fine on my HP2300N, while the 
+# Here's a new method, which seems to work fine on my HP2300N, while the
 # previous one didn't.
-# TODO : We could also experiment with USTATUS JOB=ON and we would know for sure 
+# TODO : We could also experiment with USTATUS JOB=ON and we would know for sure
 # when the job is finished, without having to poll the printer repeatedly.
 PJLMESSAGE = "\033%-12345X@PJL USTATUS DEVICE=ON\r\n@PJL INFO STATUS\r\n@PJL INFO PAGECOUNT\r\n@PJL USTATUS DEVICE=OFF\033%-12345X"
@@ -52,5 +52,5 @@
                     "40000" : "Sleep Mode",             # Standby
                   }
-                  
+
 class Handler :
     """A class for PJL print accounting."""
@@ -69,10 +69,10 @@
         self.readthread = None
         self.quitEvent = threading.Event()
-        
-    def __del__(self) :    
+
+    def __del__(self) :
         """Ensures the network connection is closed at object deletion time."""
         self.close()
-        
-    def open(self) :    
+
+    def open(self) :
         """Opens the network connection."""
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -93,6 +93,6 @@
             self.parent.filter.logdebug("Connected to printer %s:%s" % (self.printerHostname, self.port))
             return True
-        
-    def close(self) :    
+
+    def close(self) :
         """Closes the network connection."""
         if not self.closed :
@@ -107,6 +107,6 @@
             self.queue = None
             self.closed = True
-            
-    def readloop(self) :        
+
+    def readloop(self) :
         """Reading loop thread."""
         self.parent.filter.logdebug("Reading thread started.")
@@ -115,9 +115,9 @@
             try :
                 answer = self.sock.recv(1)
-            except socket.timeout :    
+            except socket.timeout :
                 pass
             except socket.error, (dummy, msg) :
                 self.parent.filter.printInfo(_("Problem while receiving PJL answer from %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn")
-            else :    
+            else :
                 if answer :
                     readbuffer.append(answer)
@@ -125,9 +125,9 @@
                         self.queue.put("".join(readbuffer))
                         readbuffer = []
-        if readbuffer :             
-            self.queue.put("".join(readbuffer))            
+        if readbuffer :
+            self.queue.put("".join(readbuffer))
         self.parent.filter.logdebug("Reading thread ended.")
-            
-    def retrievePJLValues(self) :    
+
+    def retrievePJLValues(self) :
         """Retrieves a printer's internal page counter and status via PJL."""
         while not self.open() :
@@ -141,5 +141,5 @@
             except socket.error, msg :
                 self.parent.filter.printInfo(_("Problem while sending PJL query to %s:%s : %s") % (self.printerHostname, self.port, str(msg)), "warn")
-            else :    
+            else :
                 self.parent.filter.logdebug("Query sent to %s : %s" % (self.printerHostname, repr(PJLMESSAGE)))
                 actualpagecount = self.printerStatus = None
@@ -147,26 +147,26 @@
                     try :
                         answer = self.queue.get(True, 5)
-                    except Queue.Empty :    
+                    except Queue.Empty :
                         self.parent.filter.logdebug("Timeout when reading printer's answer from %s:%s" % (self.printerHostname, self.port))
-                    else :    
+                    else :
                         readnext = False
                         self.parent.filter.logdebug("PJL answer : %s" % repr(answer))
-                        for line in [l.strip() for l in answer.split()] : 
+                        for line in [l.strip() for l in answer.split()] :
                             if line.startswith("CODE=") :
                                 self.printerStatus = line.split("=")[1]
                                 self.parent.filter.logdebug("Found status : %s" % self.printerStatus)
-                            elif line.startswith("PAGECOUNT=") :    
+                            elif line.startswith("PAGECOUNT=") :
                                 try :
                                     actualpagecount = int(line.split('=')[1].strip())
-                                except ValueError :    
+                                except ValueError :
                                     self.parent.filter.logdebug("Received incorrect datas : [%s]" % line.strip())
                                 else :
                                     self.parent.filter.logdebug("Found pages counter : %s" % actualpagecount)
-                            elif line.startswith("PAGECOUNT") :    
+                            elif line.startswith("PAGECOUNT") :
                                 readnext = True # page counter is on next line
-                            elif readnext :    
+                            elif readnext :
                                 try :
                                     actualpagecount = int(line.strip())
-                                except ValueError :    
+                                except ValueError :
                                     self.parent.filter.logdebug("Received incorrect datas : [%s]" % line.strip())
                                 else :
@@ -174,7 +174,7 @@
                                     readnext = False
                 self.printerInternalPageCounter = max(actualpagecount, self.printerInternalPageCounter)
-        finally :        
+        finally :
             self.close()
-        
+
     def waitPrinting(self) :
         """Waits for printer status being 'printing'."""
@@ -183,5 +183,5 @@
         if not noprintingmaxdelay :
             self.parent.filter.logdebug("Will wait indefinitely until printer %s is in 'printing' state." % self.parent.filter.PrinterName)
-        else :    
+        else :
             self.parent.filter.logdebug("Will wait until printer %s is in 'printing' state or %i seconds have elapsed." % (self.parent.filter.PrinterName, noprintingmaxdelay))
         previousValue = self.parent.getLastPageCounter()
@@ -192,9 +192,9 @@
             if self.printerStatus in ('10023', '10003') :
                 break
-            if self.printerInternalPageCounter is not None :    
+            if self.printerInternalPageCounter is not None :
                 if firstvalue is None :
                     # first time we retrieved a page counter, save it
                     firstvalue = self.printerInternalPageCounter
-                else :     
+                else :
                     # second time (or later)
                     if firstvalue < self.printerInternalPageCounter :
@@ -213,5 +213,5 @@
                                 # the printer rejected it for some reason.
                                 self.parent.filter.printInfo("Printer %s probably won't print this job !!!" % self.parent.filter.PrinterName, "warn")
-                            else :     
+                            else :
                                 # Here the job has already been entirely printed, and
                                 # the printer has already passed from 'idle' to 'printing' to 'idle' again.
@@ -220,5 +220,5 @@
             self.parent.filter.logdebug(_("Waiting for printer %s to be printing...") % self.parent.filter.PrinterName)
             time.sleep(statusstabilizationdelay)
-        
+
     def waitIdle(self) :
         """Waits for printer status being 'idle'."""
@@ -233,14 +233,14 @@
                    and (os.environ.get("PYKOTAPHASE") == "BEFORE") :
                     self.parent.filter.logdebug("No need to wait for the printer to be idle, it is the case already.")
-                    return 
+                    return
                 idle_num += 1
                 if idle_num >= statusstabilizationloops :
                     # printer status is stable, we can exit
                     break
-            else :    
+            else :
                 idle_num = 0
             self.parent.filter.logdebug(_("Waiting for printer %s's idle status to stabilize...") % self.parent.filter.PrinterName)
             time.sleep(statusstabilizationdelay)
-    
+
     def retrieveInternalPageCounter(self) :
         """Returns the page counter from the printer via internal PJL handling."""
@@ -251,11 +251,11 @@
                self.parent.filter.JobSizeBytes :
                 self.waitPrinting()
-            self.waitIdle()    
-        except :    
+            self.waitIdle()
+        except :
             self.parent.filter.printInfo(_("PJL querying stage interrupted. Using latest value seen for internal page counter (%s) on printer %s.") % (self.printerInternalPageCounter, self.parent.filter.PrinterName), "warn")
             raise
-        else :    
+        else :
             return self.printerInternalPageCounter
-            
+
 def main(hostname) :
     """Tries PJL accounting for a printer host."""
@@ -266,15 +266,15 @@
             self.PrinterName = "FakePrintQueue"
             self.JobSizeBytes = 1
-            
+
         def printInfo(self, msg, level="info") :
             """Prints informational message."""
             sys.stderr.write("%s : %s\n" % (level.upper(), msg))
             sys.stderr.flush()
-            
-        def logdebug(self, msg) :    
+
+        def logdebug(self, msg) :
             """Prints debug message."""
             self.printInfo(msg, "debug")
-            
-    class FakeAccounter :        
+
+    class FakeAccounter :
         """Fakes an accounter for testing purposes."""
         def __init__(self, hostname) :
@@ -283,21 +283,21 @@
             self.filter = FakeFilter()
             self.protocolHandler = Handler(self, hostname)
-            
-        def getLastPageCounter(self) :    
+
+        def getLastPageCounter(self) :
             """Fakes the return of a page counter."""
             return 0
-        
+
     acc = FakeAccounter(hostname)
     return acc.protocolHandler.retrieveInternalPageCounter()
-    
-if __name__ == "__main__" :            
-    if len(sys.argv) != 2 :    
+
+if __name__ == "__main__" :
+    if len(sys.argv) != 2 :
         sys.stderr.write("Usage :  python  %s  printer_ip_address\n" % sys.argv[0])
-    else :    
+    else :
         def _(msg) :
             """Fake gettext method."""
             return msg
-            
+
         pagecounter = main(sys.argv[1])
         print "Internal page counter's value is : %s" % pagecounter
-        
+
