Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/config.py

    r3411 r3413  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2929 
    3030from pykota.utils import unicodeToDatabase 
    31 from pykota.errors import PyKotaConfigError     
     31from pykota.errors import PyKotaConfigError 
    3232 
    3333class PyKotaConfig : 
     
    4343        if not os.path.isfile(self.adminfilename) : 
    4444            raise PyKotaConfigError, _("Configuration file %s not found.") % self.adminfilename 
    45         if os.access(self.adminfilename, os.R_OK) :     
     45        if os.access(self.adminfilename, os.R_OK) : 
    4646            self.isAdmin = 1 
    4747        self.config = ConfigParser.ConfigParser() 
     
    5353        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 
    5454            self.config_charset = "UTF-8" 
    55              
    56     def isTrue(self, option) :         
     55 
     56    def isTrue(self, option) : 
    5757        """Returns True if option is set to true, else False.""" 
    5858        if (option is not None) and (option.strip().upper() in ['Y', 'YES', '1', 'ON', 'T', 'TRUE']) : 
    5959            return True 
    60         else :     
     60        else : 
    6161            return False 
    62                          
    63     def isFalse(self, option) :         
     62 
     63    def isFalse(self, option) : 
    6464        """Returns True if option is set to false, else False.""" 
    6565        if (option is not None) and (option.strip().upper() in ['N', 'NO', '0', 'OFF', 'F', 'FALSE']) : 
    6666            return True 
    67         else :     
     67        else : 
    6868            return False 
    69                          
    70     def getPrinterNames(self) :     
     69 
     70    def getPrinterNames(self) : 
    7171        """Returns the list of configured printers, i.e. all sections names minus 'global'.""" 
    7272        return [pname for pname in self.config.sections() if pname != "global"] 
    73          
    74     def getGlobalOption(self, option, ignore=False) :     
     73 
     74    def getGlobalOption(self, option, ignore=False) : 
    7575        """Returns an option from the global section, or raises a PyKotaConfigError if ignore is not set, else returns None.""" 
    7676        try : 
    7777            return self.config.get("global", option, raw=1).decode(self.config_charset) 
    78         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     78        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 
    7979            if ignore : 
    8080                return None 
    8181            else : 
    8282                raise PyKotaConfigError, _("Option %s not found in section global of %s") % (option, self.filename) 
    83                  
    84     def getPrinterOption(self, printername, option) :     
     83 
     84    def getPrinterOption(self, printername, option) : 
    8585        """Returns an option from the printer section, or the global section, or raises a PyKotaConfigError.""" 
    8686        globaloption = self.getGlobalOption(option, ignore=True) 
    8787        try : 
    8888            return self.config.get(printername, option, raw=1).decode(self.config_charset) 
    89         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     89        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 
    9090            if globaloption is not None : 
    9191                return globaloption 
    9292            else : 
    9393                raise PyKotaConfigError, _("Option %s not found in section %s of %s") % (option, printername, self.filename) 
    94          
    95     def getStorageBackend(self) :     
    96         """Returns the storage backend information as a Python mapping."""         
     94 
     95    def getStorageBackend(self) : 
     96        """Returns the storage backend information as a Python mapping.""" 
    9797        backendinfo = {} 
    9898        backend = self.getGlobalOption("storagebackend").lower() 
     
    102102            backendinfo["storagename"] = self.getGlobalOption("storagename") 
    103103            for option in ["storageserver", "storageuser", "storageuserpw"] : 
    104                 backendinfo[option] = None           
     104                backendinfo[option] = None 
    105105        else : 
    106106            issqlite = False 
     
    108108                backendinfo[option] = self.getGlobalOption(option) 
    109109            backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=True)  # password is optional 
    110              
     110 
    111111        backendinfo["storageadmin"] = None 
    112112        backendinfo["storageadminpw"] = None 
     
    117117                try : 
    118118                    backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1).decode(self.config_charset) 
    119                 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     119                except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 
    120120                    if not issqlite : 
    121121                        raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", self.adminfilename) 
    122122                try : 
    123123                    backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1).decode(self.config_charset) 
    124                 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     124                except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) : 
    125125                    pass # Password is optional 
    126                 # Now try to overwrite the storagebackend, storageserver  
     126                # Now try to overwrite the storagebackend, storageserver 
    127127                # and storagename. This allows admins to use the master LDAP 
    128128                # server directly and users to use the replicas transparently. 
     
    140140                    pass 
    141141        return backendinfo 
    142          
    143     def getLDAPInfo(self) :     
    144         """Returns some hints for the LDAP backend."""         
     142 
     143    def getLDAPInfo(self) : 
     144        """Returns some hints for the LDAP backend.""" 
    145145        ldapinfo = {} 
    146146        for option in [ "userbase", "userrdn", \ 
     
    157157            if ldapinfo[field].lower().startswith('attach(') : 
    158158                ldapinfo[field] = ldapinfo[field][7:-1] 
    159                  
    160         # should we use TLS, by default (if unset) value is NO         
     159 
     160        # should we use TLS, by default (if unset) value is NO 
    161161        ldapinfo["ldaptls"] = self.isTrue(self.getGlobalOption("ldaptls", ignore=True)) 
    162162        ldapinfo["cacert"] = self.getGlobalOption("cacert", ignore=True) 
    163163        if ldapinfo["cacert"] : 
    164164            ldapinfo["cacert"] = ldapinfo["cacert"].strip().encode(sys.getfilesystemencoding(), "replace") 
    165         if ldapinfo["ldaptls"] :     
     165        if ldapinfo["ldaptls"] : 
    166166            if not os.access(ldapinfo["cacert"] or "", os.R_OK) : 
    167167                raise PyKotaConfigError, _("Option ldaptls is set, but certificate %s is not readable.") % repr(ldapinfo["cacert"]) 
    168168        return ldapinfo 
    169          
    170     def getLoggingBackend(self) :     
     169 
     170    def getLoggingBackend(self) : 
    171171        """Returns the logging backend information.""" 
    172         validloggers = [ "stderr", "system" ]  
     172        validloggers = [ "stderr", "system" ] 
    173173        try : 
    174174            logger = self.getGlobalOption("logger").lower() 
    175         except PyKotaConfigError :     
     175        except PyKotaConfigError : 
    176176            logger = "system" 
    177         if logger not in validloggers :              
     177        if logger not in validloggers : 
    178178            raise PyKotaConfigError, _("Option logger only supports values in %s") % str(validloggers) 
    179         return logger     
    180          
     179        return logger 
     180 
    181181    def getLogoURL(self) : 
    182182        """Returns the URL to use for the logo in the CGI scripts.""" 
    183183        url = self.getGlobalOption("logourl", ignore=True) or \ 
    184184                   "http://www.pykota.com/pykota.png" 
    185         return url.strip()            
    186          
     185        return url.strip() 
     186 
    187187    def getLogoLink(self) : 
    188188        """Returns the URL to go to when the user clicks on the logo in the CGI scripts.""" 
    189189        url = self.getGlobalOption("logolink", ignore=True) or \ 
    190190                   "http://www.pykota.com/" 
    191         return url.strip()            
    192      
    193     def getPreAccounterBackend(self, printername) :     
     191        return url.strip() 
     192 
     193    def getPreAccounterBackend(self, printername) : 
    194194        """Returns the preaccounter backend to use for a given printer.""" 
    195         validaccounters = [ "software", "ink" ]      
     195        validaccounters = [ "software", "ink" ] 
    196196        try : 
    197197            fullaccounter = self.getPrinterOption(printername, "preaccounter").strip() 
    198         except PyKotaConfigError :     
     198        except PyKotaConfigError : 
    199199            return ("software", "") 
    200         else :     
     200        else : 
    201201            flower = fullaccounter.lower() 
    202202            for vac in validaccounters : 
    203                 if flower.startswith(vac) :     
     203                if flower.startswith(vac) : 
    204204                    try : 
    205205                        (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] 
    206                     except ValueError :     
     206                    except ValueError : 
    207207                        raise PyKotaConfigError, _("Invalid preaccounter %s for printer %s") % (fullaccounter, printername) 
    208208                    if args.endswith(')') : 
    209209                        args = args[:-1].strip() 
    210                     if (vac == "ink") and not args :     
     210                    if (vac == "ink") and not args : 
    211211                        raise PyKotaConfigError, _("Invalid preaccounter %s for printer %s") % (fullaccounter, printername) 
    212212                    return (vac, args) 
    213213            raise PyKotaConfigError, _("Option preaccounter in section %s only supports values in %s") % (printername, str(validaccounters)) 
    214          
    215     def getAccounterBackend(self, printername) :     
     214 
     215    def getAccounterBackend(self, printername) : 
    216216        """Returns the accounter backend to use for a given printer.""" 
    217         validaccounters = [ "hardware", "software", "ink" ]      
     217        validaccounters = [ "hardware", "software", "ink" ] 
    218218        try : 
    219219            fullaccounter = self.getPrinterOption(printername, "accounter").strip() 
    220         except PyKotaConfigError :     
     220        except PyKotaConfigError : 
    221221            return ("software", "") 
    222         else :     
     222        else : 
    223223            flower = fullaccounter.lower() 
    224224            for vac in validaccounters : 
    225                 if flower.startswith(vac) :     
     225                if flower.startswith(vac) : 
    226226                    try : 
    227227                        (accounter, args) = [x.strip() for x in fullaccounter.split('(', 1)] 
    228                     except ValueError :     
     228                    except ValueError : 
    229229                        raise PyKotaConfigError, _("Invalid accounter %s for printer %s") % (fullaccounter, printername) 
    230230                    if args.endswith(')') : 
     
    234234                    return (vac, args) 
    235235            raise PyKotaConfigError, _("Option accounter in section %s only supports values in %s") % (printername, str(validaccounters)) 
    236          
    237     def getPreHook(self, printername) :     
     236 
     237    def getPreHook(self, printername) : 
    238238        """Returns the prehook command line to launch, or None if unset.""" 
    239239        try : 
    240240            return self.getPrinterOption(printername, "prehook").strip() 
    241         except PyKotaConfigError :     
     241        except PyKotaConfigError : 
    242242            return      # No command to launch in the pre-hook 
    243              
    244     def getPostHook(self, printername) :     
     243 
     244    def getPostHook(self, printername) : 
    245245        """Returns the posthook command line to launch, or None if unset.""" 
    246246        try : 
    247247            return self.getPrinterOption(printername, "posthook").strip() 
    248         except PyKotaConfigError :     
     248        except PyKotaConfigError : 
    249249            return      # No command to launch in the post-hook 
    250              
    251     def getStripTitle(self, printername) :     
     250 
     251    def getStripTitle(self, printername) : 
    252252        """Returns the striptitle directive's content, or None if unset.""" 
    253253        try : 
    254254            return self.getPrinterOption(printername, "striptitle").strip() 
    255         except PyKotaConfigError :     
     255        except PyKotaConfigError : 
    256256            return      # No prefix to strip off 
    257              
    258     def getAskConfirmation(self, printername) :         
     257 
     258    def getAskConfirmation(self, printername) : 
    259259        """Returns the askconfirmation directive's content, or None if unset.""" 
    260260        try : 
    261261            return self.getPrinterOption(printername, "askconfirmation").strip() 
    262         except PyKotaConfigError :     
     262        except PyKotaConfigError : 
    263263            return      # No overwriting will be done 
    264              
    265     def getOverwriteJobTicket(self, printername) :         
     264 
     265    def getOverwriteJobTicket(self, printername) : 
    266266        """Returns the overwrite_jobticket directive's content, or None if unset.""" 
    267267        try : 
    268268            return self.getPrinterOption(printername, "overwrite_jobticket").strip() 
    269         except PyKotaConfigError :     
     269        except PyKotaConfigError : 
    270270            return      # No overwriting will be done 
    271          
    272     def getUnknownBillingCode(self, printername) :         
     271 
     272    def getUnknownBillingCode(self, printername) : 
    273273        """Returns the unknown_billingcode directive's content, or the default value if unset.""" 
    274274        validvalues = [ "CREATE", "DENY" ] 
    275275        try : 
    276276            fullvalue = self.getPrinterOption(printername, "unknown_billingcode") 
    277         except PyKotaConfigError :     
     277        except PyKotaConfigError : 
    278278            return ("CREATE", None) 
    279         else :     
     279        else : 
    280280            try : 
    281281                value = [x.strip() for x in fullvalue.split('(', 1)] 
    282             except ValueError :     
     282            except ValueError : 
    283283                raise PyKotaConfigError, _("Invalid unknown_billingcode directive %s for printer %s") % (fullvalue, printername) 
    284             if len(value) == 1 :     
     284            if len(value) == 1 : 
    285285                value.append("") 
    286             (value, args) = value     
     286            (value, args) = value 
    287287            if args.endswith(')') : 
    288288                args = args[:-1] 
    289             value = value.upper()     
     289            value = value.upper() 
    290290            if (value == "DENY") and not args : 
    291291                return ("DENY", None) 
     
    293293                raise PyKotaConfigError, _("Directive unknown_billingcode in section %s only supports values in %s") % (printername, str(validvalues)) 
    294294            return (value, args) 
    295          
    296     def getPrinterEnforcement(self, printername) :     
     295 
     296    def getPrinterEnforcement(self, printername) : 
    297297        """Returns if quota enforcement should be strict or laxist for the current printer.""" 
    298         validenforcements = [ "STRICT", "LAXIST" ]      
     298        validenforcements = [ "STRICT", "LAXIST" ] 
    299299        try : 
    300300            enforcement = self.getPrinterOption(printername, "enforcement") 
    301         except PyKotaConfigError :     
     301        except PyKotaConfigError : 
    302302            return "LAXIST" 
    303         else :     
     303        else : 
    304304            enforcement = enforcement.upper() 
    305305            if enforcement not in validenforcements : 
    306306                raise PyKotaConfigError, _("Option enforcement in section %s only supports values in %s") % (printername, str(validenforcements)) 
    307             return enforcement     
    308              
    309     def getPrinterOnBackendError(self, printername) :     
     307            return enforcement 
     308 
     309    def getPrinterOnBackendError(self, printername) : 
    310310        """Returns what must be done whenever the real CUPS backend fails.""" 
    311         validactions = [ "CHARGE", "NOCHARGE" ]      
     311        validactions = [ "CHARGE", "NOCHARGE" ] 
    312312        try : 
    313313            action = self.getPrinterOption(printername, "onbackenderror") 
    314         except PyKotaConfigError :     
     314        except PyKotaConfigError : 
    315315            return ["NOCHARGE"] 
    316         else :     
     316        else : 
    317317            action = action.upper().split(",") 
    318318            error = False 
     
    322322                        try : 
    323323                            (num, delay) = [int(p) for p in act[6:].split(":", 2)] 
    324                         except ValueError :     
     324                        except ValueError : 
    325325                            error = True 
    326                     else :         
     326                    else : 
    327327                        error = True 
    328328            if error : 
    329329                raise PyKotaConfigError, _("Option onbackenderror in section %s only supports values 'charge', 'nocharge', and 'retry:num:delay'") % printername 
    330             return action   
    331              
    332     def getPrinterOnAccounterError(self, printername) :     
     330            return action 
     331 
     332    def getPrinterOnAccounterError(self, printername) : 
    333333        """Returns what must be done whenever the accounter fails.""" 
    334         validactions = [ "CONTINUE", "STOP" ]      
     334        validactions = [ "CONTINUE", "STOP" ] 
    335335        try : 
    336336            action = self.getPrinterOption(printername, "onaccountererror") 
    337         except PyKotaConfigError :     
     337        except PyKotaConfigError : 
    338338            return "STOP" 
    339         else :     
     339        else : 
    340340            action = action.upper() 
    341341            if action not in validactions : 
    342342                raise PyKotaConfigError, _("Option onaccountererror in section %s only supports values in %s") % (printername, str(validactions)) 
    343             return action   
    344              
    345     def getPrinterPolicy(self, printername) :     
     343            return action 
     344 
     345    def getPrinterPolicy(self, printername) : 
    346346        """Returns the default policy for the current printer.""" 
    347         validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ]      
     347        validpolicies = [ "ALLOW", "DENY", "EXTERNAL" ] 
    348348        try : 
    349349            fullpolicy = self.getPrinterOption(printername, "policy") 
    350         except PyKotaConfigError :     
     350        except PyKotaConfigError : 
    351351            return ("DENY", None) 
    352         else :     
     352        else : 
    353353            try : 
    354354                policy = [x.strip() for x in fullpolicy.split('(', 1)] 
    355             except ValueError :     
     355            except ValueError : 
    356356                raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) 
    357             if len(policy) == 1 :     
     357            if len(policy) == 1 : 
    358358                policy.append("") 
    359             (policy, args) = policy     
     359            (policy, args) = policy 
    360360            if args.endswith(')') : 
    361361                args = args[:-1] 
    362             policy = policy.upper()     
     362            policy = policy.upper() 
    363363            if (policy == "EXTERNAL") and not args : 
    364364                raise PyKotaConfigError, _("Invalid policy %s for printer %s") % (fullpolicy, printername) 
     
    366366                raise PyKotaConfigError, _("Option policy in section %s only supports values in %s") % (printername, str(validpolicies)) 
    367367            return (policy, args) 
    368          
    369     def getCrashRecipient(self) :     
     368 
     369    def getCrashRecipient(self) : 
    370370        """Returns the email address of the software crash messages recipient.""" 
    371371        try : 
    372372            return self.getGlobalOption("crashrecipient") 
    373         except :     
     373        except : 
    374374            return 
    375              
    376     def getSMTPServer(self) :     
     375 
     376    def getSMTPServer(self) : 
    377377        """Returns the SMTP server to use to send messages to users.""" 
    378378        try : 
    379379            return self.getGlobalOption("smtpserver") 
    380         except PyKotaConfigError :     
     380        except PyKotaConfigError : 
    381381            return "localhost" 
    382          
    383     def getMailDomain(self) :     
     382 
     383    def getMailDomain(self) : 
    384384        """Returns the mail domain to use to send messages to users.""" 
    385385        try : 
    386386            return self.getGlobalOption("maildomain") 
    387         except PyKotaConfigError :     
    388             return  
    389          
    390     def getAdminMail(self, printername) :     
     387        except PyKotaConfigError : 
     388            return 
     389 
     390    def getAdminMail(self, printername) : 
    391391        """Returns the Email address of the Print Quota Administrator.""" 
    392392        try : 
    393393            return self.getPrinterOption(printername, "adminmail") 
    394         except PyKotaConfigError :     
     394        except PyKotaConfigError : 
    395395            return "root@localhost" 
    396          
    397     def getAdmin(self, printername) :     
     396 
     397    def getAdmin(self, printername) : 
    398398        """Returns the full name of the Print Quota Administrator.""" 
    399399        try : 
    400400            return self.getPrinterOption(printername, "admin") 
    401         except PyKotaConfigError :     
     401        except PyKotaConfigError : 
    402402            return "root" 
    403          
    404     def getMailTo(self, printername) :     
     403 
     404    def getMailTo(self, printername) : 
    405405        """Returns the recipient of email messages.""" 
    406406        validmailtos = [ "EXTERNAL", "NOBODY", "NONE", "NOONE", "BITBUCKET", "DEVNULL", "BOTH", "USER", "ADMIN" ] 
    407407        try : 
    408408            fullmailto = self.getPrinterOption(printername, "mailto") 
    409         except PyKotaConfigError :     
     409        except PyKotaConfigError : 
    410410            return ("BOTH", None) 
    411         else :     
     411        else : 
    412412            try : 
    413413                mailto = [x.strip() for x in fullmailto.split('(', 1)] 
    414             except ValueError :     
     414            except ValueError : 
    415415                raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) 
    416             if len(mailto) == 1 :     
     416            if len(mailto) == 1 : 
    417417                mailto.append("") 
    418             (mailto, args) = mailto     
     418            (mailto, args) = mailto 
    419419            if args.endswith(')') : 
    420420                args = args[:-1] 
    421             mailto = mailto.upper()     
     421            mailto = mailto.upper() 
    422422            if (mailto == "EXTERNAL") and not args : 
    423423                raise PyKotaConfigError, _("Invalid option mailto %s for printer %s") % (fullmailto, printername) 
     
    425425                raise PyKotaConfigError, _("Option mailto in section %s only supports values in %s") % (printername, str(validmailtos)) 
    426426            return (mailto, args) 
    427          
    428     def getMaxDenyBanners(self, printername) :     
     427 
     428    def getMaxDenyBanners(self, printername) : 
    429429        """Returns the maximum number of deny banners to be printed for a particular user on a particular printer.""" 
    430430        try : 
    431431            maxdb = self.getPrinterOption(printername, "maxdenybanners") 
    432         except PyKotaConfigError :     
     432        except PyKotaConfigError : 
    433433            return 0 # default value is to forbid printing a deny banner. 
    434434        try : 
     
    436436            if value < 0 : 
    437437                raise ValueError 
    438         except (TypeError, ValueError) :     
     438        except (TypeError, ValueError) : 
    439439            raise PyKotaConfigError, _("Invalid maximal deny banners counter %s") % maxdb 
    440         else :     
     440        else : 
    441441            return value 
    442442 
     
    447447        except PyKotaConfigError : 
    448448            return True 
    449               
    450     def getGraceDelay(self, printername) :     
     449 
     450    def getGraceDelay(self, printername) : 
    451451        """Returns the grace delay in days.""" 
    452452        try : 
    453453            gd = self.getPrinterOption(printername, "gracedelay") 
    454         except PyKotaConfigError :     
     454        except PyKotaConfigError : 
    455455            gd = 7      # default value of 7 days 
    456456        try : 
    457457            return int(gd) 
    458         except (TypeError, ValueError) :     
     458        except (TypeError, ValueError) : 
    459459            raise PyKotaConfigError, _("Invalid grace delay %s") % gd 
    460              
    461     def getPoorMan(self) :     
     460 
     461    def getPoorMan(self) : 
    462462        """Returns the poor man's threshold.""" 
    463463        try : 
    464464            pm = self.getGlobalOption("poorman") 
    465         except PyKotaConfigError :     
     465        except PyKotaConfigError : 
    466466            pm = 1.0    # default value of 1 unit 
    467467        try : 
    468468            return float(pm) 
    469         except (TypeError, ValueError) :     
     469        except (TypeError, ValueError) : 
    470470            raise PyKotaConfigError, _("Invalid poor man's threshold %s") % pm 
    471              
    472     def getBalanceZero(self) :     
     471 
     472    def getBalanceZero(self) : 
    473473        """Returns the value of the zero for balance limitation.""" 
    474474        try : 
    475475            bz = self.getGlobalOption("balancezero") 
    476         except PyKotaConfigError :     
     476        except PyKotaConfigError : 
    477477            bz = 0.0    # default value, zero is 0.0 
    478478        try : 
    479479            return float(bz) 
    480         except (TypeError, ValueError) :     
     480        except (TypeError, ValueError) : 
    481481            raise PyKotaConfigError, _("Invalid balancezero value %s") % bz 
    482              
    483     def getPoorWarn(self) :     
     482 
     483    def getPoorWarn(self) : 
    484484        """Returns the poor man's warning message.""" 
    485485        try : 
    486486            return self.getGlobalOption("poorwarn") 
    487         except PyKotaConfigError :     
     487        except PyKotaConfigError : 
    488488            return _("Your Print Quota account balance is Low.\nSoon you'll not be allowed to print anymore.\nPlease contact the Print Quota Administrator to solve the problem.") 
    489              
    490     def getHardWarn(self, printername) :     
     489 
     490    def getHardWarn(self, printername) : 
    491491        """Returns the hard limit error message.""" 
    492492        try : 
    493493            return self.getPrinterOption(printername, "hardwarn") 
    494         except PyKotaConfigError :     
     494        except PyKotaConfigError : 
    495495            return _("You are not allowed to print anymore because\nyour Print Quota is exceeded on printer %s.") % printername 
    496              
    497     def getSoftWarn(self, printername) :     
     496 
     497    def getSoftWarn(self, printername) : 
    498498        """Returns the soft limit error message.""" 
    499499        try : 
    500500            return self.getPrinterOption(printername, "softwarn") 
    501         except PyKotaConfigError :     
     501        except PyKotaConfigError : 
    502502            return _("You will soon be forbidden to print anymore because\nyour Print Quota is almost reached on printer %s.") % printername 
    503              
    504     def getPrivacy(self) :         
     503 
     504    def getPrivacy(self) : 
    505505        """Returns True if privacy is activated, else False.""" 
    506506        return self.isTrue(self.getGlobalOption("privacy", ignore=True)) 
    507          
    508     def getDebug(self) :           
     507 
     508    def getDebug(self) : 
    509509        """Returns True if debugging is activated, else False.""" 
    510510        return self.isTrue(self.getGlobalOption("debug", ignore=True)) 
    511              
    512     def getCaching(self) :           
     511 
     512    def getCaching(self) : 
    513513        """Returns True if database caching is enabled, else False.""" 
    514514        return self.isTrue(self.getGlobalOption("storagecaching", ignore=True)) 
    515              
    516     def getLDAPCache(self) :           
     515 
     516    def getLDAPCache(self) : 
    517517        """Returns True if low-level LDAP caching is enabled, else False.""" 
    518518        return self.isTrue(self.getGlobalOption("ldapcache", ignore=True)) 
    519              
    520     def getDisableHistory(self) :           
     519 
     520    def getDisableHistory(self) : 
    521521        """Returns True if we want to disable history, else False.""" 
    522522        return self.isTrue(self.getGlobalOption("disablehistory", ignore=True)) 
    523              
    524     def getUserNameToLower(self) :           
     523 
     524    def getUserNameToLower(self) : 
    525525        """Deprecated.""" 
    526526        return self.getGlobalOption("utolower", ignore=True) 
    527          
     527 
    528528    def getUserNameCase(self) : 
    529529        """Returns value for user name case: upper, lower or native""" 
     
    531531        try : 
    532532            value = self.getGlobalOption("usernamecase", ignore=True).strip().lower() 
    533         except AttributeError :     
     533        except AttributeError : 
    534534            value = "native" 
    535535        if value not in validvalues : 
    536536            raise PyKotaConfigError, _("Option usernamecase only supports values in %s") % str(validvalues) 
    537537        return value 
    538          
    539     def getRejectUnknown(self) :           
     538 
     539    def getRejectUnknown(self) : 
    540540        """Returns True if we want to reject the creation of unknown users or groups, else False.""" 
    541541        return self.isTrue(self.getGlobalOption("reject_unknown", ignore=True)) 
    542          
    543     def getPrinterKeepFiles(self, printername) :           
     542 
     543    def getPrinterKeepFiles(self, printername) : 
    544544        """Returns True if files must be kept on disk, else False.""" 
    545         try :  
     545        try : 
    546546            return self.isTrue(self.getPrinterOption(printername, "keepfiles")) 
    547         except PyKotaConfigError :     
     547        except PyKotaConfigError : 
    548548            return False 
    549              
    550     def getPrinterDirectory(self, printername) :           
     549 
     550    def getPrinterDirectory(self, printername) : 
    551551        """Returns the path to our working directory, else a directory suitable for temporary files.""" 
    552         try :  
     552        try : 
    553553            return self.getPrinterOption(printername, "directory").strip() 
    554         except PyKotaConfigError :     
     554        except PyKotaConfigError : 
    555555            return tempfile.gettempdir() 
    556              
    557     def getDenyDuplicates(self, printername) :           
     556 
     557    def getDenyDuplicates(self, printername) : 
    558558        """Returns True or a command if we want to deny duplicate jobs, else False.""" 
    559         try :  
     559        try : 
    560560            denyduplicates = self.getPrinterOption(printername, "denyduplicates") 
    561         except PyKotaConfigError :     
     561        except PyKotaConfigError : 
    562562            return False 
    563         else :     
     563        else : 
    564564            if self.isTrue(denyduplicates) : 
    565565                return True 
    566566            elif self.isFalse(denyduplicates) : 
    567567                return False 
    568             else :     
     568            else : 
    569569                # it's a command to run. 
    570570                return denyduplicates 
    571                  
    572     def getDuplicatesDelay(self, printername) :           
     571 
     572    def getDuplicatesDelay(self, printername) : 
    573573        """Returns the number of seconds after which two identical jobs are not considered a duplicate anymore.""" 
    574         try :  
     574        try : 
    575575            duplicatesdelay = self.getPrinterOption(printername, "duplicatesdelay") 
    576         except PyKotaConfigError :     
     576        except PyKotaConfigError : 
    577577            return 0 
    578         else :     
     578        else : 
    579579            try : 
    580580                return int(duplicatesdelay) 
    581581            except (TypeError, ValueError) : 
    582582                raise PyKotaConfigError, _("Incorrect value %s for the duplicatesdelay directive in section %s") % (str(duplicatesdelay), printername) 
    583          
    584     def getNoPrintingMaxDelay(self, printername) :           
     583 
     584    def getNoPrintingMaxDelay(self, printername) : 
    585585        """Returns the max number of seconds to wait for the printer to be in 'printing' mode.""" 
    586         try :  
     586        try : 
    587587            maxdelay = self.getPrinterOption(printername, "noprintingmaxdelay") 
    588         except PyKotaConfigError :     
     588        except PyKotaConfigError : 
    589589            return None         # tells to use hardcoded value 
    590         else :     
     590        else : 
    591591            try : 
    592592                maxdelay = int(maxdelay) 
     
    595595            except (TypeError, ValueError) : 
    596596                raise PyKotaConfigError, _("Incorrect value %s for the noprintingmaxdelay directive in section %s") % (str(maxdelay), printername) 
    597             else :     
     597            else : 
    598598                return maxdelay 
    599          
    600     def getStatusStabilizationLoops(self, printername) :     
     599 
     600    def getStatusStabilizationLoops(self, printername) : 
    601601        """Returns the number of times the printer must return the 'idle' status to consider it stable.""" 
    602         try :  
     602        try : 
    603603            stab = self.getPrinterOption(printername, "statusstabilizationloops") 
    604         except PyKotaConfigError :     
     604        except PyKotaConfigError : 
    605605            return None         # tells to use hardcoded value 
    606         else :     
     606        else : 
    607607            try : 
    608608                stab = int(stab) 
     
    611611            except (TypeError, ValueError) : 
    612612                raise PyKotaConfigError, _("Incorrect value %s for the statusstabilizationloops directive in section %s") % (str(stab), printername) 
    613             else :     
     613            else : 
    614614                return stab 
    615          
    616     def getStatusStabilizationDelay(self, printername) :     
     615 
     616    def getStatusStabilizationDelay(self, printername) : 
    617617        """Returns the number of seconds to wait between two checks of the printer's status.""" 
    618         try :  
     618        try : 
    619619            stab = self.getPrinterOption(printername, "statusstabilizationdelay") 
    620         except PyKotaConfigError :     
     620        except PyKotaConfigError : 
    621621            return None         # tells to use hardcoded value 
    622         else :     
     622        else : 
    623623            try : 
    624624                stab = float(stab) 
     
    627627            except (TypeError, ValueError) : 
    628628                raise PyKotaConfigError, _("Incorrect value %s for the statusstabilizationdelay directive in section %s") % (str(stab), printername) 
    629             else :     
     629            else : 
    630630                return stab 
    631          
    632     def getPrinterSNMPErrorMask(self, printername) :     
     631 
     632    def getPrinterSNMPErrorMask(self, printername) : 
    633633        """Returns the SNMP error mask for a particular printer, or None if not defined.""" 
    634         try :  
     634        try : 
    635635            errmask = self.getPrinterOption(printername, "snmperrormask").lower() 
    636         except PyKotaConfigError :     
     636        except PyKotaConfigError : 
    637637            return None         # tells to use hardcoded value 
    638         else :     
     638        else : 
    639639            try : 
    640640                if errmask.startswith("0x") : 
    641641                    value = int(errmask, 16) 
    642                 elif errmask.startswith("0") :     
     642                elif errmask.startswith("0") : 
    643643                    value = int(errmask, 8) 
    644                 else :     
     644                else : 
    645645                    value = int(errmask) 
    646646                if 0 <= value < 65536 : 
    647647                    return value 
    648                 else :     
     648                else : 
    649649                    raise ValueError 
    650             except ValueError :     
     650            except ValueError : 
    651651                raise PyKotaConfigError, _("Incorrect value %s for the snmperrormask directive in section %s") % (errmask, printername) 
    652          
    653     def getWinbindSeparator(self) :           
     652 
     653    def getWinbindSeparator(self) : 
    654654        """Returns the winbind separator's value if it is set, else None.""" 
    655655        return self.getGlobalOption("winbind_separator", ignore=True) 
     
    657657    def getAccountBanner(self, printername) : 
    658658        """Returns which banner(s) to account for: NONE, BOTH, STARTING, ENDING.""" 
    659         validvalues = [ "NONE", "BOTH", "STARTING", "ENDING" ]      
     659        validvalues = [ "NONE", "BOTH", "STARTING", "ENDING" ] 
    660660        try : 
    661661            value = self.getPrinterOption(printername, "accountbanner") 
    662         except PyKotaConfigError :     
     662        except PyKotaConfigError : 
    663663            return "BOTH"       # Default value of BOTH 
    664         else :     
     664        else : 
    665665            value = value.strip().upper() 
    666666            if value not in validvalues : 
    667667                raise PyKotaConfigError, _("Option accountbanner in section %s only supports values in %s") % (printername, str(validvalues)) 
    668             return value   
     668            return value 
    669669 
    670670    def getAvoidDuplicateBanners(self, printername) : 
     
    699699        except PyKotaConfigError : 
    700700            return None 
    701              
     701 
    702702    def getTrustJobSize(self, printername) : 
    703703        """Returns the normalized value of the trustjobsize's directive.""" 
     
    706706        except PyKotaConfigError : 
    707707            return (None, "YES") 
    708         else :     
     708        else : 
    709709            if value == "YES" : 
    710710                return (None, "YES") 
    711             try :     
     711            try : 
    712712                (limit, replacement) = [p.strip() for p in value.split(">")[1].split(":")] 
    713713                limit = int(limit) 
    714714                try : 
    715                     replacement = int(replacement)  
    716                 except ValueError :     
     715                    replacement = int(replacement) 
     716                except ValueError : 
    717717                    if replacement != "PRECOMPUTED" : 
    718718                        raise 
     
    723723            except (IndexError, ValueError, TypeError) : 
    724724                raise PyKotaConfigError, _("Option trustjobsize for printer %s is incorrect") % printername 
    725             return (limit, replacement)     
    726              
     725            return (limit, replacement) 
     726 
    727727    def getPrinterCoefficients(self, printername) : 
    728728        """Returns a mapping of coefficients for a particular printer.""" 
     
    743743                try : 
    744744                    branches[k] = float(value) 
    745                 except ValueError :     
     745                except ValueError : 
    746746                    raise PyKotaConfigError, "Invalid coefficient %s (%s) for printer %s" % (k, value, printername) 
    747                  
     747 
    748748        for (k, v) in sectionbranches : 
    749749            k = k.split('_', 1)[1] 
     
    752752                try : 
    753753                    branches[k] = float(value) # overwrite any global option or set a new value 
    754                 except ValueError :     
     754                except ValueError : 
    755755                    raise PyKotaConfigError, "Invalid coefficient %s (%s) for printer %s" % (k, value, printername) 
    756756            else : 
    757757                del branches[k] # empty value disables a global option 
    758758        return branches 
    759          
     759 
    760760    def getPrinterSkipInitialWait(self, printername) : 
    761761        """Returns True if we want to skip the initial waiting loop, else False."""