Index: pykota/trunk/pykota/accounters/snmp.py
===================================================================
--- pykota/trunk/pykota/accounters/snmp.py (revision 3411)
+++ pykota/trunk/pykota/accounters/snmp.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/>.
@@ -36,5 +36,5 @@
 try :
     from pysnmp.entity.rfc3413.oneliner import cmdgen
-except ImportError :    
+except ImportError :
     hasV4 = False
     try :
@@ -50,5 +50,5 @@
 from pykota import constants
 
-#                      
+#
 # Documentation taken from RFC 3805 (Printer MIB v2) and RFC 2790 (Host Resource MIB)
 #
@@ -67,5 +67,5 @@
                        4 : 'testing',
                        5 : 'down',
-                     }  
+                     }
 hrPrinterDetectedErrorStateOID = "1.3.6.1.2.1.25.3.5.1.2.1" # SNMPv2-SMI::mib-2.25.3.5.1.2.1
 printerDetectedErrorStateValues = [ { 128 : 'Low Paper',
@@ -87,6 +87,6 @@
                                         1 : 'Not Assigned in RFC3805',
                                     },
-                                  ]  
-                                  
+                                  ]
+
 # The default error mask to use when checking error conditions.
 defaultErrorMask = 0x4fcc # [ 'No Paper',
@@ -100,6 +100,6 @@
                           #   'Input Tray Empty',
                           # ]
-                          
-# WARNING : some printers don't support this one :                  
+
+# WARNING : some printers don't support this one :
 prtConsoleDisplayBufferTextOID = "1.3.6.1.2.1.43.16.5.1.2.1.1" # SNMPv2-SMI::mib-2.43.16.5.1.2.1.1
 class BaseHandler :
@@ -111,10 +111,10 @@
         try :
             self.community = self.parent.arguments.split(":")[1].strip()
-        except IndexError :    
+        except IndexError :
             self.community = "public"
         self.port = 161
         self.initValues()
-        
-    def initValues(self) :    
+
+    def initValues(self) :
         """Initializes SNMP values."""
         self.printerInternalPageCounter = None
@@ -123,10 +123,10 @@
         self.printerDetectedErrorState = None
         self.timebefore = time.time()   # resets timer also in case of error
-        
-    def retrieveSNMPValues(self) :    
+
+    def retrieveSNMPValues(self) :
         """Retrieves a printer's internal page counter and status via SNMP."""
         raise RuntimeError, "You have to overload this method."
-        
-    def extractErrorStates(self, value) :    
+
+    def extractErrorStates(self, value) :
         """Returns a list of textual error states from a binary value."""
         states = []
@@ -137,7 +137,7 @@
                 if byte & k :
                     states.append(v)
-        return states            
-        
-    def checkIfError(self, errorstates) :    
+        return states
+
+    def checkIfError(self, errorstates) :
         """Checks if any error state is fatal or not."""
         if errorstates is None :
@@ -146,5 +146,5 @@
             try :
                 errormask = self.parent.filter.config.getPrinterSNMPErrorMask(self.parent.filter.PrinterName)
-            except AttributeError : # debug mode    
+            except AttributeError : # debug mode
                 errormask = defaultErrorMask
             if errormask is None :
@@ -161,6 +161,6 @@
                     return True
             self.parent.filter.logdebug("No error condition matching mask 0x%04x" % errormask)
-            return False    
-        
+            return False
+
     def waitPrinting(self) :
         """Waits for printer status being 'printing'."""
@@ -169,5 +169,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()
@@ -178,9 +178,9 @@
             if statusAsString in ('printing', 'warmup') :
                 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 :
@@ -205,12 +205,12 @@
                                 # 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.
                                 self.parent.filter.printInfo("Printer %s has probably already printed this job !!!" % self.parent.filter.PrinterName, "warn")
                             break
-            self.parent.filter.logdebug(_("Waiting for printer %s to be printing...") % self.parent.filter.PrinterName)    
+            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'."""
@@ -228,19 +228,19 @@
                           (dstatusAsString == 'running'))) :
                 idle_flag = 1       # Standby / Powersave is considered idle
-            if idle_flag :    
+            if idle_flag :
                 if (self.printerInternalPageCounter is not None) \
                    and self.skipinitialwait \
                    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)    
+            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 SNMP handling."""
@@ -251,11 +251,11 @@
                self.parent.filter.JobSizeBytes :
                 self.waitPrinting()
-            self.waitIdle()    
-        except :    
+            self.waitIdle()
+        except :
             self.parent.filter.printInfo(_("SNMP querying stage interrupted. Using latest value seen for internal page counter (%s) on printer %s.") % (self.printerInternalPageCounter, self.parent.filter.PrinterName), "warn")
             raise
         return self.printerInternalPageCounter
-            
-if hasV4 :            
+
+if hasV4 :
     class Handler(BaseHandler) :
         """A class for pysnmp v4.x"""
@@ -270,17 +270,17 @@
                                                   tuple([int(i) for i in hrDeviceStatusOID.split('.')]), \
                                                   tuple([int(i) for i in hrPrinterDetectedErrorStateOID.split('.')]))
-            except socket.gaierror, msg :                                      
+            except socket.gaierror, msg :
                 errorIndication = repr(msg)
-            except :                                      
+            except :
                 errorIndication = "Unknown SNMP/Network error. Check your wires."
-            if errorIndication :                                                  
+            if errorIndication :
                 self.parent.filter.printInfo("SNMP Error : %s" % errorIndication, "error")
                 self.initValues()
-            elif errorStatus :    
+            elif errorStatus :
                 self.parent.filter.printInfo("SNMP Error : %s at %s" % (errorStatus.prettyPrint(), \
                                                                         varBinds[int(errorIndex)-1]), \
                                              "error")
                 self.initValues()
-            else :                                 
+            else :
                 self.printerInternalPageCounter = max(self.printerInternalPageCounter, int(varBinds[0][1].prettyPrint() or "0"))
                 self.printerStatus = int(varBinds[1][1].prettyPrint())
@@ -295,5 +295,5 @@
     class Handler(BaseHandler) :
         """A class for pysnmp v3.4.x"""
-        def retrieveSNMPValues(self) :    
+        def retrieveSNMPValues(self) :
             """Retrieves a printer's internal page counter and status via SNMP."""
             ver = alpha.protoVersions[alpha.protoVersionId1]
@@ -310,9 +310,9 @@
                                    (self.printerHostname, self.port), \
                                    (self.handleAnswer, req))
-            except (SnmpOverUdpError, select.error), msg :    
+            except (SnmpOverUdpError, select.error), msg :
                 self.parent.filter.printInfo(_("Network error while doing SNMP queries on printer %s : %s") % (self.printerHostname, msg), "warn")
                 self.initValues()
             tsp.close()
-        
+
         def handleAnswer(self, wholeMsg, notusedhere, req):
             """Decodes and handles the SNMP answer."""
@@ -321,5 +321,5 @@
             try :
                 rsp.berDecode(wholeMsg)
-            except TypeMismatchError, msg :    
+            except TypeMismatchError, msg :
                 self.parent.filter.printInfo(_("SNMP message decoding error for printer %s : %s") % (self.printerHostname, msg), "warn")
                 self.initValues()
@@ -333,5 +333,5 @@
                         for varBind in rsp.apiAlphaGetPdu().apiAlphaGetVarBindList():
                             self.values.append(varBind.apiAlphaGetOidVal()[1].rawAsn1Value)
-                        try :    
+                        try :
                             # keep maximum value seen for printer's internal page counter
                             self.printerInternalPageCounter = max(self.printerInternalPageCounter, self.values[0])
@@ -344,10 +344,10 @@
                                     deviceStatusValues.get(self.deviceStatus), \
                                     self.printerDetectedErrorState))
-                        except IndexError :    
+                        except IndexError :
                             self.parent.filter.logdebug("SNMP answer is incomplete : %s" % str(self.values))
                             pass
-                        else :    
+                        else :
                             return 1
-                    
+
 def main(hostname) :
     """Tries SNMP accounting for a printer host."""
@@ -358,15 +358,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) :
@@ -375,19 +375,19 @@
             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()            
+
+    acc = fakeAccounter()
     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) :
             return msg
-            
+
         pagecounter = main(sys.argv[1])
         print "Internal page counter's value is : %s" % pagecounter
