Changeset 1761

Show
Ignore:
Timestamp:
10/02/04 07:48:56 (20 years ago)
Author:
jalet
Message:

Should now correctly deal with charsets both when storing into databases and when
retrieving datas. Works with both PostgreSQL and LDAP.

Location:
pykota/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/cgi-bin/printquota.cgi

    r1693 r1761  
    2424# 
    2525# $Log$ 
     26# Revision 1.37  2004/10/02 05:48:56  jalet 
     27# Should now correctly deal with charsets both when storing into databases and when 
     28# retrieving datas. Works with both PostgreSQL and LDAP. 
     29# 
    2630# Revision 1.36  2004/09/02 10:34:09  jalet 
    2731# Fixed problem with mod_auth_ldap Apache module 
     
    195199    langs = [l.strip().split(';')[0] for l in languages.split(",")] 
    196200    return "%s_%s" % (langs[0], langs[0].upper()) 
     201     
     202def getCharsetPreference() : 
     203    """Returns the preferred charset.""" 
     204    charsets = os.environ.get("HTTP_ACCEPT_CHARSET", "no charset defined") 
     205    charsets = [l.strip().split(';')[0] for l in charsets.split(",")] 
     206    return charsets[0] 
    197207 
    198208class PyKotaReportGUI(PyKotaTool) : 
     
    351361if __name__ == "__main__" : 
    352362    os.environ["LC_ALL"] = getLanguagePreference() 
    353     admin = PyKotaReportGUI(lang=os.environ["LC_ALL"]) 
     363    admin = PyKotaReportGUI(lang=os.environ["LC_ALL"], charset=getCharsetPreference()) 
    354364    admin.form = cgi.FieldStorage() 
    355365    admin.guiAction() 
  • pykota/trunk/NEWS

    r1758 r1761  
    2222PyKota NEWS : 
    2323 
     24    - 1.20alpha19 : 
     25     
     26        - The description, filename, title, and options fields 
     27          are now stored as UTF-8 strings in both LDAP and PostgreSQL. 
     28          Proper charset is used during extraction from the database. 
     29           
    2430    - 1.20alpha18 : 
    2531     
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1754 r1761  
    2222# 
    2323# $Log$ 
     24# Revision 1.78  2004/10/02 05:48:56  jalet 
     25# Should now correctly deal with charsets both when storing into databases and when 
     26# retrieving datas. Works with both PostgreSQL and LDAP. 
     27# 
    2428# Revision 1.77  2004/09/28 14:29:00  jalet 
    2529# dumpykota for LDAP backend is almost there. 
     
    576580            printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    577581            printer.uniqueMember = fields.get("uniqueMember", []) 
    578             printer.Description = fields.get("description", [""])[0] 
     582            printer.Description = fields.get("description", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
    579583            printer.Exists = 1 
    580584        return printer     
     
    677681                    lastjob.JobPrice = None 
    678682                lastjob.JobAction = fields.get("pykotaAction", [""])[0] 
    679                 lastjob.JobFileName = fields.get("pykotaFileName", [""])[0] 
    680                 lastjob.JobTitle = fields.get("pykotaTitle", [""])[0] 
     683                lastjob.JobFileName = fields.get("pykotaFileName", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
     684                lastjob.JobTitle = fields.get("pykotaTitle", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
    681685                lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 
    682                 lastjob.JobOptions = fields.get("pykotaOptions", [""])[0] 
     686                lastjob.JobOptions = fields.get("pykotaOptions", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
    683687                lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 
    684688                lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
     
    753757                printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 
    754758                printer.uniqueMember = fields.get("uniqueMember", []) 
    755                 printer.Description = fields.get("description", [""])[0] 
     759                printer.Description = fields.get("description", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
    756760                printer.Exists = 1 
    757761                printers.append(printer) 
     
    965969        """Write the printer's description back into the storage.""" 
    966970        fields = { 
    967                    "description" : str(printer.Description), 
     971                   "description" : str(printer.Description).decode(self.tool.getCharset()).encode("UTF-8"),  
    968972                 } 
    969973        self.doModify(printer.ident, fields) 
     
    10641068                   "pykotaPrinterPageCounter" : str(pagecounter), 
    10651069                   "pykotaAction" : action, 
    1066                    "pykotaFileName" : ((filename is None) and "None") or filename.decode(os.environ.get("CHARSET", "ISO-8859-15")).encode("UTF-8"),  
    1067                    "pykotaTitle" : ((title is None) and "None") or title.decode(os.environ.get("CHARSET", "ISO-8859-15")).encode("UTF-8"),  
     1070                   "pykotaFileName" : ((filename is None) and "None") or filename.decode(self.tool.getCharset()).encode("UTF-8"),  
     1071                   "pykotaTitle" : ((title is None) and "None") or title.decode(self.tool.getCharset()).encode("UTF-8"),  
    10681072                   "pykotaCopies" : str(copies),  
    1069                    "pykotaOptions" : ((options is None) and "None") or options.decode(os.environ.get("CHARSET", "ISO-8859-15")).encode("UTF-8"),  
     1073                   "pykotaOptions" : ((options is None) and "None") or options.decode(self.tool.getCharset()).encode("UTF-8"),  
    10701074                   "pykotaHostName" : str(clienthost),  
    10711075                   "pykotaJobSizeBytes" : str(jobsizebytes), 
     
    11661170                    job.JobPrice = None 
    11671171                job.JobAction = fields.get("pykotaAction", [""])[0] 
    1168                 job.JobFileName = fields.get("pykotaFileName", [""])[0] 
    1169                 job.JobTitle = fields.get("pykotaTitle", [""])[0] 
     1172                job.JobFileName = fields.get("pykotaFileName", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
     1173                job.JobTitle = fields.get("pykotaTitle", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
    11701174                job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 
    1171                 job.JobOptions = fields.get("pykotaOptions", [""])[0] 
     1175                job.JobOptions = fields.get("pykotaOptions", [""])[0].decode("UTF-8").encode(self.tool.getCharset())  
    11721176                job.JobHostName = fields.get("pykotaHostName", [""])[0] 
    11731177                job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] 
  • pykota/trunk/pykota/storages/sql.py

    r1719 r1761  
    2222# 
    2323# $Log$ 
     24# Revision 1.48  2004/10/02 05:48:56  jalet 
     25# Should now correctly deal with charsets both when storing into databases and when 
     26# retrieving datas. Works with both PostgreSQL and LDAP. 
     27# 
    2428# Revision 1.47  2004/09/15 07:26:20  jalet 
    2529# Data dumps are now ordered by entry creation date if applicable. 
     
    187191            printer.PricePerJob = fields.get("priceperjob") or 0.0 
    188192            printer.PricePerPage = fields.get("priceperpage") or 0.0 
    189             printer.Description = fields.get("description") or "" 
     193            printer.Description = (fields.get("description") or "").decode("UTF-8").encode(self.tool.getCharset())  
    190194            printer.Exists = 1 
    191195        return printer     
     
    239243            lastjob.JobPrice = fields.get("jobprice") 
    240244            lastjob.JobAction = fields.get("action") 
    241             lastjob.JobFileName = fields.get("filename") 
    242             lastjob.JobTitle = fields.get("title") 
     245            lastjob.JobFileName = (fields.get("filename") or "").decode("UTF-8").encode(self.tool.getCharset())  
     246            lastjob.JobTitle = (fields.get("title") or "").decode("UTF-8").encode(self.tool.getCharset())  
    243247            lastjob.JobCopies = fields.get("copies") 
    244             lastjob.JobOptions = fields.get("options") 
     248            lastjob.JobOptions = (fields.get("options") or "").decode("UTF-8").encode(self.tool.getCharset())  
    245249            lastjob.JobDate = fields.get("jobdate") 
    246250            lastjob.JobHostName = fields.get("hostname") 
     
    301305                    printer.PricePerJob = record.get("priceperjob") or 0.0 
    302306                    printer.PricePerPage = record.get("priceperpage") or 0.0 
    303                     printer.Description = record.get("description") or "" 
     307                    printer.Description = (record.get("description") or "").decode("UTF-8").encode(self.tool.getCharset())  
    304308                    printer.Exists = 1 
    305309                    printers.append(printer) 
     
    387391    def writePrinterDescription(self, printer) :     
    388392        """Write the printer's description back into the storage.""" 
    389         self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(printer.Description), self.doQuote(printer.ident))) 
     393        description = printer.Description 
     394        if description is not None : 
     395            description = printer.Description.decode(self.tool.getCharset()).encode("UTF-8"),  
     396        self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 
    390397         
    391398    def writeUserLimitBy(self, user, limitby) :     
     
    432439        self.doModify("UPDATE jobhistory SET jobsize=%s, jobprice=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(jobprice), self.doQuote(lastjob.ident))) 
    433440         
    434     def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) :     
     441    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) : 
    435442        """Adds a job in a printer's history.""" 
     443        if filename is not None : 
     444            filename = filename.decode(self.tool.getCharset()).encode("UTF-8") 
     445        if title is not None : 
     446            title = title.decode(self.tool.getCharset()).encode("UTF-8") 
     447        if options is not None : 
     448            options = options.decode(self.tool.getCharset()).encode("UTF-8") 
    436449        if (not self.disablehistory) or (not printer.LastJob.Exists) : 
    437450            if jobsize is not None : 
     
    493506                job.JobPrice = fields.get("jobprice") 
    494507                job.JobAction = fields.get("action") 
    495                 job.JobFileName = fields.get("filename") 
    496                 job.JobTitle = fields.get("title") 
     508                job.JobFileName = (fields.get("filename") or "").decode("UTF-8").encode(self.tool.getCharset())  
     509                job.JobTitle = (fields.get("title") or "").decode("UTF-8").encode(self.tool.getCharset())  
    497510                job.JobCopies = fields.get("copies") 
    498                 job.JobOptions = fields.get("options") 
     511                job.JobOptions = (fields.get("options") or "").decode("UTF-8").encode(self.tool.getCharset())  
    499512                job.JobDate = fields.get("jobdate") 
    500513                job.JobHostName = fields.get("hostname") 
  • pykota/trunk/pykota/tool.py

    r1757 r1761  
    2222# 
    2323# $Log$ 
     24# Revision 1.124  2004/10/02 05:48:56  jalet 
     25# Should now correctly deal with charsets both when storing into databases and when 
     26# retrieving datas. Works with both PostgreSQL and LDAP. 
     27# 
    2428# Revision 1.123  2004/09/29 20:20:52  jalet 
    2529# Added the winbind_separator directive to pykota.conf to allow the admin to 
     
    493497class PyKotaTool :     
    494498    """Base class for all PyKota command line tools.""" 
    495     def __init__(self, lang=None, doc="PyKota %s (c) 2003-2004 %s" % (version.__version__, version.__author__)) : 
     499    def __init__(self, lang=None, charset=None, doc="PyKota %s (c) 2003-2004 %s" % (version.__version__, version.__author__)) : 
    496500        """Initializes the command line tool.""" 
    497501        # locale stuff 
     
    501505        except (locale.Error, IOError) : 
    502506            gettext.NullTranslations().install() 
     507             
     508        # We can force the charset.     
     509        # The CHARSET environment variable is set by CUPS when printing. 
     510        # Else we use the current locale's one. 
     511        # If nothing is set, we use ISO-8859-15 widely used in western Europe. 
     512        self.charset = charset or os.environ.get("CHARSET") or locale.getlocale()[1] or locale.getdefaultlocale()[1] or "ISO-8859-15" 
    503513     
    504514        # pykota specific stuff 
     
    522532        self.softwareJobSize = 0 
    523533        self.softwareJobPrice = 0.0 
     534        self.logdebug("Charset in use : %s" % self.charset) 
     535         
     536    def getCharset(self) :     
     537        """Returns the charset in use.""" 
     538        return self.charset 
    524539         
    525540    def logdebug(self, message) :     
  • pykota/trunk/pykota/version.py

    r1757 r1761  
    2222# 
    2323 
    24 __version__ = "1.20alpha18_unofficial" 
     24__version__ = "1.20alpha19_unofficial" 
    2525 
    2626__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" 
  • pykota/trunk/TODO

    r1760 r1761  
    7979          pkusers --ingroups gr1,gr2,... --outgroups gr3,gr4,... 
    8080           
    81         - Ensures data are stored in a consistent way with Unicode 
    82           under PostgreSQL : I can't reproduce the problem. 
    83          
    8481        - Allow the --ingroups command line option to repykota, to 
    8582          report only users members of the specified groups.