Changeset 2652

Show
Ignore:
Timestamp:
02/08/06 13:24:06 (19 years ago)
Author:
jerome
Message:

The code should be ready to accept non-ascii usernames, groupnames, and
printernames. Unfortunately the LDAP schema currently doesn't accept non-ascii
characters in these fields.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2622 r2652  
    287287        raise PyKotaStorageError, message 
    288288             
    289     def filterNames(self, records, attribute) :         
     289    def filterNames(self, records, attribute, patterns=None) : 
    290290        """Returns a list of 'attribute' from a list of records. 
    291291         
     
    297297            if attrval is None : 
    298298                self.tool.printInfo("Object %s has no %s attribute !" % (dn, attribute), "error") 
    299             else :     
    300                 result.append(attrval) 
     299            else : 
     300                if patterns : 
     301                    if (not isinstance(patterns, type([]))) and (not isinstance(patterns, type(()))) : 
     302                        patterns = [ patterns ] 
     303                    patterns = [self.userCharsetToDatabase(p) for p in patterns] 
     304                    if self.tool.matchString(attrval, patterns) :    
     305                        result.append(attrval) 
     306                else :     
     307                    result.append(attrval) 
    301308        return result         
    302309                 
    303310    def getAllBillingCodes(self, billingcode=None) :     
    304311        """Extracts all billing codes or only the billing codes matching the optional parameter.""" 
    305         billingcodes = [] 
    306312        ldapfilter = "objectClass=pykotaBilling" 
    307         if billingcode : 
    308             ldapfilter = "(&(%s)(pykotaBillingCode=%s))" % (ldapfilter, self.userCharsetToDatabase(billingcode)) 
    309313        result = self.doSearch(ldapfilter, ["pykotaBillingCode"], base=self.info["billingcodebase"]) 
    310314        if result : 
    311             billingcodes = [self.databaseToUserCharset(bc) for bc in self.filterNames(result, "pykotaBillingCode")] 
    312         return billingcodes 
     315            return [self.databaseToUserCharset(bc) for bc in self.filterNames(result, "pykotaBillingCode", billingcode)] 
     316        else :     
     317            return [] 
    313318         
    314319    def getAllPrintersNames(self, printername=None) :     
    315320        """Extracts all printer names or only the printers' names matching the optional parameter.""" 
    316         printernames = [] 
    317321        ldapfilter = "objectClass=pykotaPrinter" 
    318         if printername : 
    319             ldapfilter = "(&(%s)(pykotaPrinterName=%s))" % (ldapfilter, printername) 
    320322        result = self.doSearch(ldapfilter, ["pykotaPrinterName"], base=self.info["printerbase"]) 
    321323        if result : 
    322             printernames = self.filterNames(result, "pykotaPrinterName") 
    323         return printernames 
     324            return self.filterNames(result, "pykotaPrinterName", printername) 
     325        else :     
     326            return [] 
    324327         
    325328    def getAllUsersNames(self, username=None) :     
    326329        """Extracts all user names or only the users' names matching the optional parameter.""" 
    327         usernames = [] 
    328330        ldapfilter = "objectClass=pykotaAccount" 
    329         if username : 
    330             ldapfilter = "(&(%s)(pykotaUserName=%s))" % (ldapfilter, username) 
    331331        result = self.doSearch(ldapfilter, ["pykotaUserName"], base=self.info["userbase"]) 
    332332        if result : 
    333             usernames = self.filterNames(result, "pykotaUserName") 
    334         return usernames 
     333            return self.filterNames(result, "pykotaUserName", username) 
     334        else :     
     335            return [] 
    335336         
    336337    def getAllGroupsNames(self, groupname=None) :     
    337338        """Extracts all group names or only the groups' names matching the optional parameter.""" 
    338         groupnames = [] 
    339339        ldapfilter = "objectClass=pykotaGroup" 
    340         if groupname : 
    341             ldapfilter = "(&(%s)(pykotaGroupName=%s))" % (ldapfilter, groupname) 
    342340        result = self.doSearch(ldapfilter, ["pykotaGroupName"], base=self.info["groupbase"]) 
    343341        if result : 
    344             groupnames = self.filterNames(result, "pykotaGroupName") 
    345         return groupnames 
     342            return self.filterNames(result, "pykotaGroupName", groupname) 
     343        else :     
     344            return [] 
    346345         
    347346    def getUserNbJobsFromHistory(self, user) : 
    348347        """Returns the number of jobs the user has in history.""" 
    349         result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % user.Name, None, base=self.info["jobbase"]) 
     348        result = self.doSearch("(&(pykotaUserName=%s)(objectClass=pykotaJob))" % self.userCharsetToDatabase(user.Name), None, base=self.info["jobbase"]) 
    350349        return len(result) 
    351350         
     
    353352        """Extracts user information given its name.""" 
    354353        user = StorageUser(self, username) 
     354        username = self.userCharsetToDatabase(username) 
    355355        result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(%s=%s)))" % (username, self.info["userrdn"], username), ["pykotaUserName", "pykotaLimitBy", self.info["usermail"], "pykotaOverCharge"], base=self.info["userbase"]) 
    356356        if result : 
    357357            fields = result[0][1] 
    358358            user.ident = result[0][0] 
    359             user.Name = fields.get("pykotaUserName", [username])[0]  
     359            user.Name = fields.get("pykotaUserName", [self.databaseToUserCharset(username)])[0]  
    360360            user.Email = fields.get(self.info["usermail"], [None])[0] 
    361361            user.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 
     
    398398        """Extracts group information given its name.""" 
    399399        group = StorageGroup(self, groupname) 
     400        groupname = self.userCharsetToDatabase(groupname) 
    400401        result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (groupname, self.info["grouprdn"], groupname), ["pykotaGroupName", "pykotaLimitBy"], base=self.info["groupbase"]) 
    401402        if result : 
    402403            fields = result[0][1] 
    403404            group.ident = result[0][0] 
    404             group.Name = fields.get("pykotaGroupName", [groupname])[0]  
     405            group.Name = fields.get("pykotaGroupName", [self.databaseToUserCharset(groupname)])[0]  
    405406            group.LimitBy = fields.get("pykotaLimitBy", ["quota"])[0] 
    406407            group.AccountBalance = 0.0 
     
    416417        """Extracts printer information given its name : returns first matching printer.""" 
    417418        printer = StoragePrinter(self, printername) 
     419        printername = self.userCharsetToDatabase(printername) 
    418420        result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(%s=%s)))" \ 
    419421                      % (printername, self.info["printerrdn"], printername), \ 
     
    425427            fields = result[0][1]       # take only first matching printer, ignore the rest 
    426428            printer.ident = result[0][0] 
    427             printer.Name = fields.get("pykotaPrinterName", [printername])[0]  
     429            printer.Name = fields.get("pykotaPrinterName", [self.databaseToUserCharset(printername)])[0]  
    428430            printer.PricePerJob = float(fields.get("pykotaPricePerJob", [0.0])[0]) 
    429431            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0]) 
     
    447449            else :     
    448450                base = self.info["userquotabase"] 
    449             result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % (user.Name, printer.Name), ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 
     451            result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s)(pykotaPrinterName=%s))" % \ 
     452                                      (self.userCharsetToDatabase(user.Name), self.userCharsetToDatabase(printer.Name)), \ 
     453                                      ["pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], \ 
     454                                      base=base) 
    450455            if result : 
    451456                fields = result[0][1] 
     
    483488            else :     
    484489                base = self.info["groupquotabase"] 
    485             result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % (group.Name, printer.Name), ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], base=base) 
     490            result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s)(pykotaPrinterName=%s))" % \ 
     491                                      (self.userCharsetToDatabase(group.Name), self.userCharsetToDatabase(printer.Name)), \ 
     492                                      ["pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit"], \ 
     493                                      base=base) 
    486494            if result : 
    487495                fields = result[0][1] 
     
    507515                grouppquota.PageCounter = 0 
    508516                grouppquota.LifePageCounter = 0 
    509                 usernamesfilter = "".join(["(pykotaUserName=%s)" % member.Name for member in self.getGroupMembers(group)]) 
     517                usernamesfilter = "".join(["(pykotaUserName=%s)" % self.userCharsetToDatabase(member.Name) for member in self.getGroupMembers(group)]) 
    510518                if usernamesfilter : 
    511519                    usernamesfilter = "(|%s)" % usernamesfilter 
     
    514522                else : 
    515523                    base = self.info["userquotabase"] 
    516                 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)%s)" % (printer.Name, usernamesfilter), ["pykotaPageCounter", "pykotaLifePageCounter"], base=base) 
     524                result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)%s)" % \ 
     525                                          (self.userCharsetToDatabase(printer.Name), usernamesfilter), \ 
     526                                          ["pykotaPageCounter", "pykotaLifePageCounter"], base=base) 
    517527                if result : 
    518528                    for userpquota in result :     
     
    525535        """Extracts a printer's last job information.""" 
    526536        lastjob = StorageLastJob(self, printer) 
    527         result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % (printer.Name, self.info["printerrdn"], printer.Name), ["pykotaLastJobIdent"], base=self.info["lastjobbase"]) 
     537        pname = self.userCharsetToDatabase(printer.Name) 
     538        result = self.doSearch("(&(objectClass=pykotaLastjob)(|(pykotaPrinterName=%s)(%s=%s)))" % \ 
     539                                  (pname, self.info["printerrdn"], pname), \ 
     540                                  ["pykotaLastJobIdent"], \ 
     541                                  base=self.info["lastjobbase"]) 
    528542        if result : 
    529543            lastjob.lastjobident = result[0][0] 
     
    557571                lastjob.ident = result[0][0] 
    558572                lastjob.JobId = fields.get("pykotaJobId")[0] 
    559                 lastjob.UserName = fields.get("pykotaUserName")[0] 
     573                lastjob.UserName = self.databaseToUserCharset(fields.get("pykotaUserName")[0]) 
    560574                lastjob.PrinterPageCounter = int(fields.get("pykotaPrinterPageCounter", [0])[0]) 
    561575                try : 
     
    596610        """Returns the group's members list.""" 
    597611        groupmembers = [] 
    598         result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % (group.Name, self.info["grouprdn"], group.Name), [self.info["groupmembers"]], base=self.info["groupbase"]) 
     612        gname = self.userCharsetToDatabase(group.Name) 
     613        result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(%s=%s)))" % \ 
     614                                  (gname, self.info["grouprdn"], gname), \ 
     615                                  [self.info["groupmembers"]], \ 
     616                                  base=self.info["groupbase"]) 
    599617        if result : 
    600618            for username in result[0][1].get(self.info["groupmembers"], []) : 
    601                 groupmembers.append(self.getUser(username)) 
     619                groupmembers.append(self.getUser(self.databaseToUserCharset(username))) 
    602620        return groupmembers         
    603621         
     
    605623        """Returns the user's groups list.""" 
    606624        groups = [] 
    607         result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % (self.info["groupmembers"], user.Name), [self.info["grouprdn"], "pykotaGroupName", "pykotaLimitBy"], base=self.info["groupbase"]) 
     625        uname = self.userCharsetToDatabase(user.Name) 
     626        result = self.doSearch("(&(objectClass=pykotaGroup)(%s=%s))" % \ 
     627                                  (self.info["groupmembers"], uname), \ 
     628                                  [self.info["grouprdn"], "pykotaGroupName", "pykotaLimitBy"], \ 
     629                                  base=self.info["groupbase"]) 
    608630        if result : 
    609631            for (groupid, fields) in result : 
    610                 groupname = (fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0] 
     632                groupname = self.databaseToUserCharset((fields.get("pykotaGroupName", [None]) or fields.get(self.info["grouprdn"], [None]))[0]) 
    611633                group = self.getFromCache("GROUPS", groupname) 
    612634                if group is None : 
     
    632654        """Get all the printer groups this printer is a member of.""" 
    633655        pgroups = [] 
    634         result = self.doSearch("(&(objectClass=pykotaPrinter)(uniqueMember=%s))" % printer.ident, ["pykotaPrinterName"], base=self.info["printerbase"]) 
     656        result = self.doSearch("(&(objectClass=pykotaPrinter)(uniqueMember=%s))" % \ 
     657                                  printer.ident, \ 
     658                                  ["pykotaPrinterName"], \ 
     659                                  base=self.info["printerbase"]) 
    635660        if result : 
    636661            for (printerid, fields) in result : 
    637662                if printerid != printer.ident : # In case of integrity violation. 
    638                     parentprinter = self.getPrinter(fields.get("pykotaPrinterName")[0]) 
     663                    parentprinter = self.getPrinter(self.databaseToUserCharset(fields.get("pykotaPrinterName")[0])) 
    639664                    if parentprinter.Exists : 
    640665                        pgroups.append(parentprinter) 
     
    645670        printers = [] 
    646671        # see comment at the same place in pgstorage.py 
    647         result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % "".join(["(pykotaPrinterName=%s)(%s=%s)" % (pname, self.info["printerrdn"], pname) for pname in printerpattern.split(",")]), ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "pykotaMaxJobSize", "pykotaPassThrough", "uniqueMember", "description"], base=self.info["printerbase"]) 
     672        printerpattern = [self.userCharsetToDatabase(p) for p in printerpattern.split(",")] 
     673        result = self.doSearch("(&(objectClass=pykotaPrinter)(|%s))" % \ 
     674                                  "".join(["(pykotaPrinterName=%s)(%s=%s)" % (pname, self.info["printerrdn"], pname) for pname in printerpattern]), \ 
     675                                  ["pykotaPrinterName", "pykotaPricePerPage", "pykotaPricePerJob", "pykotaMaxJobSize", "pykotaPassThrough", "uniqueMember", "description"], \ 
     676                                  base=self.info["printerbase"]) 
    648677        if result : 
    649678            for (printerid, fields) in result : 
    650                 printername = fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0] 
     679                printername = self.databaseToUserCharset(fields.get("pykotaPrinterName", [""])[0] or fields.get(self.info["printerrdn"], [""])[0]) 
    651680                printer = StoragePrinter(self, printername) 
    652681                printer.ident = printerid 
     
    669698        """Returns the list of users who uses a given printer, along with their quotas.""" 
    670699        usersandquotas = [] 
     700        pname = self.userCharsetToDatabase(printer.Name) 
     701        names = [self.userCharsetToDatabase(n) for n in names] 
    671702        if self.info["userquotabase"].lower() == "user" : 
    672703           base = self.info["userbase"] 
    673704        else : 
    674705           base = self.info["userquotabase"] 
    675         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaUserName=%s)" % uname for uname in names])), ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], base=base) 
     706        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s)(|%s))" % \ 
     707                                  (pname, "".join(["(pykotaUserName=%s)" % uname for uname in names])), \ 
     708                                  ["pykotaUserName", "pykotaPageCounter", "pykotaLifePageCounter", "pykotaSoftLimit", "pykotaHardLimit", "pykotaDateLimit", "pykotaWarnCount"], \ 
     709                                  base=base) 
    676710        if result : 
    677711            for (userquotaid, fields) in result : 
    678                 user = self.getUser(fields.get("pykotaUserName")[0]) 
     712                user = self.getUser(self.databaseToUserCharset(fields.get("pykotaUserName")[0])) 
    679713                userpquota = StorageUserPQuota(self, user, printer) 
    680714                userpquota.ident = userquotaid 
     
    709743        """Returns the list of groups which uses a given printer, along with their quotas.""" 
    710744        groupsandquotas = [] 
     745        pname = self.userCharsetToDatabase(printer.Name) 
     746        names = [self.userCharsetToDatabase(n) for n in names] 
    711747        if self.info["groupquotabase"].lower() == "group" : 
    712748           base = self.info["groupbase"] 
    713749        else : 
    714750           base = self.info["groupquotabase"] 
    715         result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s)(|%s))" % (printer.Name, "".join(["(pykotaGroupName=%s)" % gname for gname in names])), ["pykotaGroupName"], base=base) 
     751        result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s)(|%s))" % \ 
     752                                  (pname, "".join(["(pykotaGroupName=%s)" % gname for gname in names])), \ 
     753                                  ["pykotaGroupName"], \ 
     754                                  base=base) 
    716755        if result : 
    717756            for (groupquotaid, fields) in result : 
    718                 group = self.getGroup(fields.get("pykotaGroupName")[0]) 
     757                group = self.getGroup(self.databaseToUserCharset(fields.get("pykotaGroupName")[0])) 
    719758                grouppquota = self.getGroupPQuota(group, printer) 
    720759                groupsandquotas.append((group, grouppquota)) 
     
    724763    def addPrinter(self, printername) :         
    725764        """Adds a printer to the quota storage, returns it.""" 
     765        printername = self.userCharsetToDatabase(printername) 
    726766        fields = { self.info["printerrdn"] : printername, 
    727767                   "objectClass" : ["pykotaObject", "pykotaPrinter"], 
     
    739779    def addUser(self, user) :         
    740780        """Adds a user to the quota storage, returns it.""" 
     781        uname = self.userCharsetToDatabase(user.Name) 
    741782        newfields = { 
    742                        "pykotaUserName" : user.Name, 
     783                       "pykotaUserName" : uname, 
    743784                       "pykotaLimitBy" : (user.LimitBy or "quota"), 
    744785                       "pykotaOverCharge" : str(user.OverCharge), 
     
    753794            except ValueError : 
    754795                (where, action) = (self.info["newuser"].strip(), "fail") 
    755             result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (where, self.info["userrdn"], user.Name), None, base=self.info["userbase"]) 
     796            result = self.doSearch("(&(objectClass=%s)(%s=%s))" % \ 
     797                                      (where, self.info["userrdn"], uname), \ 
     798                                      None, \ 
     799                                      base=self.info["userbase"]) 
    756800            if result : 
    757801                (dn, fields) = result[0] 
     
    772816        if mustadd : 
    773817            if self.info["userbase"] == self.info["balancebase"] :             
    774                 fields = { self.info["userrdn"] : user.Name, 
     818                fields = { self.info["userrdn"] : uname, 
    775819                           "objectClass" : ["pykotaObject", "pykotaAccount", "pykotaAccountBalance"], 
    776                            "cn" : user.Name, 
     820                           "cn" : uname, 
    777821                           "pykotaBalance" : str(user.AccountBalance or 0.0), 
    778822                           "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0),  
    779823                         }  
    780824            else :              
    781                 fields = { self.info["userrdn"] : user.Name, 
     825                fields = { self.info["userrdn"] : uname, 
    782826                           "objectClass" : ["pykotaObject", "pykotaAccount"], 
    783                            "cn" : user.Name, 
     827                           "cn" : uname, 
    784828                         }  
    785829            fields.update(newfields)          
    786             dn = "%s=%s,%s" % (self.info["userrdn"], user.Name, self.info["userbase"]) 
     830            dn = "%s=%s,%s" % (self.info["userrdn"], uname, self.info["userbase"]) 
    787831            self.doAdd(dn, fields) 
    788832            if self.info["userbase"] != self.info["balancebase"] :             
    789                 fields = { self.info["balancerdn"] : user.Name, 
     833                fields = { self.info["balancerdn"] : uname, 
    790834                           "objectClass" : ["pykotaObject", "pykotaAccountBalance"], 
    791                            "cn" : user.Name, 
     835                           "cn" : uname, 
    792836                           "pykotaBalance" : str(user.AccountBalance or 0.0), 
    793837                           "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0),   
    794838                         }  
    795                 dn = "%s=%s,%s" % (self.info["balancerdn"], user.Name, self.info["balancebase"]) 
     839                dn = "%s=%s,%s" % (self.info["balancerdn"], uname, self.info["balancebase"]) 
    796840                self.doAdd(dn, fields) 
    797841             
     
    800844    def addGroup(self, group) :         
    801845        """Adds a group to the quota storage, returns it.""" 
     846        gname = self.userCharsetToDatabase(group.Name) 
    802847        newfields = {  
    803                       "pykotaGroupName" : group.Name, 
     848                      "pykotaGroupName" : gname, 
    804849                      "pykotaLimitBy" : (group.LimitBy or "quota"), 
    805850                    }  
     
    810855            except ValueError : 
    811856                (where, action) = (self.info["newgroup"].strip(), "fail") 
    812             result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (where, self.info["grouprdn"], group.Name), None, base=self.info["groupbase"]) 
     857            result = self.doSearch("(&(objectClass=%s)(%s=%s))" % \ 
     858                                      (where, self.info["grouprdn"], gname), \ 
     859                                      None, \ 
     860                                      base=self.info["groupbase"]) 
    813861            if result : 
    814862                (dn, fields) = result[0] 
     
    826874                 
    827875        if mustadd : 
    828             fields = { self.info["grouprdn"] : group.Name, 
     876            fields = { self.info["grouprdn"] : gname, 
    829877                       "objectClass" : ["pykotaObject", "pykotaGroup"], 
    830                        "cn" : group.Name, 
     878                       "cn" : gname, 
    831879                     }  
    832880            fields.update(newfields)          
    833             dn = "%s=%s,%s" % (self.info["grouprdn"], group.Name, self.info["groupbase"]) 
     881            dn = "%s=%s,%s" % (self.info["grouprdn"], gname, self.info["groupbase"]) 
    834882            self.doAdd(dn, fields) 
    835883        return self.getGroup(group.Name) 
     
    843891                if not fields.has_key(self.info["groupmembers"]) : 
    844892                    fields[self.info["groupmembers"]] = [] 
    845                 fields[self.info["groupmembers"]].append(user.Name) 
     893                fields[self.info["groupmembers"]].append(self.userCharsetToDatabase(user.Name)) 
    846894                self.doModify(group.ident, fields) 
    847895                group.Members.append(user) 
     
    850898        """Initializes a user print quota on a printer.""" 
    851899        uuid = self.genUUID() 
     900        uname = self.userCharsetToDatabase(user.Name) 
     901        pname = self.userCharsetToDatabase(printer.Name) 
    852902        fields = { "cn" : uuid, 
    853903                   "objectClass" : ["pykotaObject", "pykotaUserPQuota"], 
    854                    "pykotaUserName" : user.Name, 
    855                    "pykotaPrinterName" : printer.Name, 
     904                   "pykotaUserName" : uname, 
     905                   "pykotaPrinterName" : pname, 
    856906                   "pykotaDateLimit" : "None", 
    857907                   "pykotaPageCounter" : "0", 
     
    869919        """Initializes a group print quota on a printer.""" 
    870920        uuid = self.genUUID() 
     921        gname = self.userCharsetToDatabase(group.Name) 
     922        pname = self.userCharsetToDatabase(printer.Name) 
    871923        fields = { "cn" : uuid, 
    872924                   "objectClass" : ["pykotaObject", "pykotaGroupPQuota"], 
    873                    "pykotaGroupName" : group.Name, 
    874                    "pykotaPrinterName" : printer.Name, 
     925                   "pykotaGroupName" : gname, 
     926                   "pykotaPrinterName" : pname, 
    875927                   "pykotaDateLimit" : "None", 
    876928                 }  
     
    10021054    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None, jobmd5sum=None, jobpages=None, jobbilling=None, precomputedsize=None, precomputedprice=None) : 
    10031055        """Adds a job in a printer's history.""" 
     1056        uname = self.userCharsetToDatabase(user.Name) 
     1057        pname = self.userCharsetToDatabase(printer.Name) 
    10041058        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    10051059            uuid = self.genUUID() 
     
    10141068                   "objectClass" : ["pykotaObject", "pykotaJob"], 
    10151069                   "cn" : uuid, 
    1016                    "pykotaUserName" : user.Name, 
    1017                    "pykotaPrinterName" : printer.Name, 
     1070                   "pykotaUserName" : uname, 
     1071                   "pykotaPrinterName" : pname, 
    10181072                   "pykotaJobId" : jobid, 
    10191073                   "pykotaPrinterPageCounter" : str(pagecounter), 
     
    10511105                       "objectClass" : ["pykotaObject", "pykotaLastJob"], 
    10521106                       "cn" : lastjuuid, 
    1053                        "pykotaPrinterName" : printer.Name, 
     1107                       "pykotaPrinterName" : pname, 
    10541108                       "pykotaLastJobIdent" : uuid, 
    10551109                     }   
     
    11151169        where = [] 
    11161170        if user is not None : 
    1117             where.append("(pykotaUserName=%s)" % user.Name) 
     1171            where.append("(pykotaUserName=%s)" % self.userCharsetToDatabase(user.Name)) 
    11181172        if printer is not None : 
    1119             where.append("(pykotaPrinterName=%s)" % printer.Name) 
     1173            where.append("(pykotaPrinterName=%s)" % self.userCharsetToDatabase(printer.Name)) 
    11201174        if hostname is not None : 
    11211175            where.append("(pykotaHostName=%s)" % hostname) 
     
    11881242                   ((end is None) and (job.JobDate >= start)) or \ 
    11891243                   ((job.JobDate >= start) and (job.JobDate <= end)) : 
    1190                     job.UserName = fields.get("pykotaUserName")[0] 
    1191                     job.PrinterName = fields.get("pykotaPrinterName")[0] 
     1244                    job.UserName = self.databaseToUserCharset(fields.get("pykotaUserName")[0]) 
     1245                    job.PrinterName = self.databaseToUserCharset(fields.get("pykotaPrinterName")[0]) 
    11921246                    job.Exists = 1 
    11931247                    jobs.append(job) 
     
    11991253    def deleteUser(self, user) :     
    12001254        """Completely deletes an user from the Quota Storage.""" 
     1255        uname = self.userCharsetToDatabase(user.Name) 
    12011256        todelete = []     
    1202         result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % user.Name, base=self.info["jobbase"]) 
     1257        result = self.doSearch("(&(objectClass=pykotaJob)(pykotaUserName=%s))" % uname, base=self.info["jobbase"]) 
    12031258        for (ident, fields) in result : 
    12041259            todelete.append(ident) 
     
    12071262        else : 
    12081263            base = self.info["userquotabase"] 
    1209         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s))" % user.Name, ["pykotaPrinterName", "pykotaUserName"], base=base) 
     1264        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaUserName=%s))" % uname, \ 
     1265                                  ["pykotaPrinterName", "pykotaUserName"], \ 
     1266                                  base=base) 
    12101267        for (ident, fields) in result : 
    12111268            # ensure the user print quota entry will be deleted 
     
    12141271            # if last job of current printer was printed by the user 
    12151272            # to delete, we also need to delete the printer's last job entry. 
    1216             printername = fields["pykotaPrinterName"][0] 
    1217             printer = self.getPrinter(printername) 
     1273            printer = self.getPrinter(self.databaseToUserCharset(fields["pykotaPrinterName"][0])) 
    12181274            if printer.LastJob.UserName == user.Name : 
    12191275                todelete.append(printer.LastJob.lastjobident) 
     
    12411297            else :     
    12421298                self.doDelete(user.ident) 
    1243         result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % user.Name, ["pykotaUserName"], base=self.info["balancebase"]) 
     1299        result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % \ 
     1300                                   uname, \ 
     1301                                   ["pykotaUserName"], \ 
     1302                                   base=self.info["balancebase"]) 
    12441303        for (ident, fields) in result : 
    12451304            self.doDelete(ident) 
     
    12471306    def deleteGroup(self, group) :     
    12481307        """Completely deletes a group from the Quota Storage.""" 
     1308        gname = self.userCharsetToDatabase(group.Name) 
    12491309        if self.info["groupquotabase"].lower() == "group" : 
    12501310            base = self.info["groupbase"] 
    12511311        else : 
    12521312            base = self.info["groupquotabase"] 
    1253         result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s))" % group.Name, ["pykotaGroupName"], base=base) 
     1313        result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaGroupName=%s))" % \ 
     1314                                  gname, \ 
     1315                                  ["pykotaGroupName"], \ 
     1316                                  base=base) 
    12541317        for (ident, fields) in result : 
    12551318            self.doDelete(ident) 
     
    12761339    def deletePrinter(self, printer) :     
    12771340        """Completely deletes a printer from the Quota Storage.""" 
    1278         result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaPrinterName=%s))" % printer.Name, base=self.info["lastjobbase"]) 
     1341        pname = self.userCharsetToDatabase(printer.Name) 
     1342        result = self.doSearch("(&(objectClass=pykotaLastJob)(pykotaPrinterName=%s))" % pname, base=self.info["lastjobbase"]) 
    12791343        for (ident, fields) in result : 
    12801344            self.doDelete(ident) 
    1281         result = self.doSearch("(&(objectClass=pykotaJob)(pykotaPrinterName=%s))" % printer.Name, base=self.info["jobbase"]) 
     1345        result = self.doSearch("(&(objectClass=pykotaJob)(pykotaPrinterName=%s))" % pname, base=self.info["jobbase"]) 
    12821346        for (ident, fields) in result : 
    12831347            self.doDelete(ident) 
     
    12861350        else : 
    12871351            base = self.info["groupquotabase"] 
    1288         result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printer.Name, base=base) 
     1352        result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % pname, base=base) 
    12891353        for (ident, fields) in result : 
    12901354            self.doDelete(ident) 
     
    12931357        else : 
    12941358            base = self.info["userquotabase"] 
    1295         result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printer.Name, base=base) 
     1359        result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % pname, base=base) 
    12961360        for (ident, fields) in result : 
    12971361            self.doDelete(ident) 
     
    14431507        code = StorageBillingCode(self, label) 
    14441508        ulabel = self.userCharsetToDatabase(label) 
    1445         result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % ulabel, ["pykotaBillingCode", "pykotaBalance", "pykotaPageCounter", "description"], base=self.info["billingcodebase"]) 
     1509        result = self.doSearch("(&(objectClass=pykotaBilling)(pykotaBillingCode=%s))" % \ 
     1510                                  ulabel, \ 
     1511                                  ["pykotaBillingCode", "pykotaBalance", "pykotaPageCounter", "description"], \ 
     1512                                  base=self.info["billingcodebase"]) 
    14461513        if result : 
    14471514            fields = result[0][1]       # take only first matching code, ignore the rest 
     
    14781545        """Returns the list of all billing codes which match a certain pattern.""" 
    14791546        codes = [] 
    1480         result = self.doSearch("(&(objectClass=pykotaBilling)(|%s))" % "".join(["(pykotaBillingCode=%s)" % self.userCharsetToDatabase(bcode) for bcode in billingcodepattern.split(",")]), \ 
     1547        billingcodepattern = [self.userCharsetToDatabase(b) for b in billingcodepattern.split(",")] 
     1548        result = self.doSearch("(&(objectClass=pykotaBilling)(|%s))" % \ 
     1549                                "".join(["(pykotaBillingCode=%s)" % bcode for bcode in billingcodepattern]), \ 
    14811550                                ["pykotaBillingCode", "description", "pykotaPageCounter", "pykotaBalance"], \ 
    14821551                                base=self.info["billingcodebase"])