Changeset 1790 for pykota/trunk
- Timestamp:
- 10/07/04 23:14:28 (20 years ago)
- Location:
- pykota/trunk
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/bin/dumpykota
r1789 r1790 24 24 # 25 25 # $Log$ 26 # Revision 1.12 2004/10/07 21:14:28 jalet 27 # Hopefully final fix for data encoding to and from the database 28 # 26 29 # Revision 1.11 2004/10/07 14:35:40 jalet 27 30 # Now edpykota refuses to launch if the user is not a PyKota administrator. … … 234 237 x.entry() 235 238 for i in range(len(entry)) : 236 value = entry[i] 237 strvalue = unicode(str(value), self.getCharset()).encode("UTF-8") 238 x.attribute(strvalue, type=type(value).__name__, name=headers[i]) 239 value = str(entry[i]) 240 try : 241 value = unicode(value, self.getCharset()).encode("UTF-8") 242 except UnicodeError : 243 pass 244 x.attribute(value, type=type(value).__name__, name=headers[i]) 239 245 x._pop() 240 246 x._output(self.outfile) -
pykota/trunk/NEWS
r1789 r1790 24 24 - 1.20alpha22 : 25 25 26 - Hopefully final fix for data encoding charset. 27 26 28 - edpykota now refuse to work if the user is not a PyKota admin. 27 29 -
pykota/trunk/pykota/storage.py
r1755 r1790 22 22 # 23 23 # $Log$ 24 # Revision 1.63 2004/10/07 21:14:28 jalet 25 # Hopefully final fix for data encoding to and from the database 26 # 24 27 # Revision 1.62 2004/09/28 17:45:31 jalet 25 28 # Added the --hardreset command line option to edpykota … … 685 688 return gpquotas 686 689 690 def databaseToUserCharset(self, text) : 691 """Converts from database format (UTF-8) to user's charset.""" 692 if text is not None : 693 try : 694 return unicode(text, "UTF-8").encode(self.tool.getCharset()) 695 except UnicodeError : 696 pass 697 return text 698 699 def userCharsetToDatabase(self, text) : 700 """Converts from user's charset to database format (UTF-8).""" 701 if text is not None : 702 try : 703 return unicode(text, self.tool.getCharset()).encode("UTF-8") 704 except UnicodeError : 705 pass 706 return text 707 687 708 def openConnection(pykotatool) : 688 709 """Returns a connection handle to the appropriate Quota Storage Database.""" -
pykota/trunk/pykota/storages/ldapstorage.py
r1777 r1790 22 22 # 23 23 # $Log$ 24 # Revision 1.83 2004/10/07 21:14:28 jalet 25 # Hopefully final fix for data encoding to and from the database 26 # 24 27 # Revision 1.82 2004/10/05 09:59:20 jalet 25 28 # Restore compatibility with Python 2.1 … … 592 595 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 593 596 printer.uniqueMember = fields.get("uniqueMember", []) 594 printer.Description = unicode(fields.get("description", [""])[0], "UTF-8").encode(self.tool.getCharset())597 printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0]) 595 598 printer.Exists = 1 596 599 return printer … … 693 696 lastjob.JobPrice = None 694 697 lastjob.JobAction = fields.get("pykotaAction", [""])[0] 695 lastjob.JobFileName = unicode(fields.get("pykotaFileName", [""])[0], "UTF-8").encode(self.tool.getCharset())696 lastjob.JobTitle = unicode(fields.get("pykotaTitle", [""])[0], "UTF-8").encode(self.tool.getCharset())698 lastjob.JobFileName = self.databaseToUserCharset(fields.get("pykotaFileName", [""])[0]) 699 lastjob.JobTitle = self.databaseToUserCharset(fields.get("pykotaTitle", [""])[0]) 697 700 lastjob.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 698 lastjob.JobOptions = unicode(fields.get("pykotaOptions", [""])[0], "UTF-8").encode(self.tool.getCharset())701 lastjob.JobOptions = self.databaseToUserCharset(fields.get("pykotaOptions", [""])[0]) 699 702 lastjob.JobHostName = fields.get("pykotaHostName", [""])[0] 700 703 lastjob.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] … … 769 772 printer.PricePerPage = float(fields.get("pykotaPricePerPage", [0.0])[0] or 0.0) 770 773 printer.uniqueMember = fields.get("uniqueMember", []) 771 printer.Description = unicode(fields.get("description", [""])[0], "UTF-8").encode(self.tool.getCharset())774 printer.Description = self.databaseToUserCharset(fields.get("description", [""])[0]) 772 775 printer.Exists = 1 773 776 printers.append(printer) … … 981 984 """Write the printer's description back into the storage.""" 982 985 fields = { 983 "description" : unicode(str(printer.Description), self.tool.getCharset()).encode("UTF-8"),986 "description" : self.userCharsetToDatabase(str(printer.Description)), 984 987 } 985 988 self.doModify(printer.ident, fields) … … 1080 1083 "pykotaPrinterPageCounter" : str(pagecounter), 1081 1084 "pykotaAction" : action, 1082 "pykotaFileName" : ((filename is None) and "None") or unicode(filename, self.tool.getCharset()).encode("UTF-8"),1083 "pykotaTitle" : ((title is None) and "None") or unicode(title, self.tool.getCharset()).encode("UTF-8"),1085 "pykotaFileName" : ((filename is None) and "None") or self.userCharsetToDatabase(filename), 1086 "pykotaTitle" : ((title is None) and "None") or self.userCharsetToDatabase(title), 1084 1087 "pykotaCopies" : str(copies), 1085 "pykotaOptions" : ((options is None) and "None") or unicode(options, self.tool.getCharset()).encode("UTF-8"),1088 "pykotaOptions" : ((options is None) and "None") or self.userCharsetToDatabase(options), 1086 1089 "pykotaHostName" : str(clienthost), 1087 1090 "pykotaJobSizeBytes" : str(jobsizebytes), … … 1182 1185 job.JobPrice = None 1183 1186 job.JobAction = fields.get("pykotaAction", [""])[0] 1184 job.JobFileName = unicode(fields.get("pykotaFileName", [""])[0], "UTF-8").encode(self.tool.getCharset())1185 job.JobTitle = unicode(fields.get("pykotaTitle", [""])[0], "UTF-8").encode(self.tool.getCharset())1187 job.JobFileName = self.databaseToUserCharset(fields.get("pykotaFileName", [""])[0]) 1188 job.JobTitle = self.databaseToUserCharset(fields.get("pykotaTitle", [""])[0]) 1186 1189 job.JobCopies = int(fields.get("pykotaCopies", [0])[0]) 1187 job.JobOptions = unicode(fields.get("pykotaOptions", [""])[0], "UTF-8").encode(self.tool.getCharset())1190 job.JobOptions = self.databaseToUserCharset(fields.get("pykotaOptions", [""])[0]) 1188 1191 job.JobHostName = fields.get("pykotaHostName", [""])[0] 1189 1192 job.JobSizeBytes = fields.get("pykotaJobSizeBytes", [0L])[0] -
pykota/trunk/pykota/storages/sql.py
r1787 r1790 22 22 # 23 23 # $Log$ 24 # Revision 1.56 2004/10/07 21:14:28 jalet 25 # Hopefully final fix for data encoding to and from the database 26 # 24 27 # Revision 1.55 2004/10/07 09:37:53 jalet 25 28 # Fixes recently introduced bug wrt users groups (was it three days ago ?) … … 114 117 field = fields[j] 115 118 if type(field) == StringType : 116 try : 117 fields[j] = unicode(field, "UTF-8").encode(self.tool.getCharset()) 118 except UnicodeError : # takes care of old jobs in history not stored as UTF-8 119 pass 119 fields[j] = self.databaseToUserCharset(field) 120 120 entries[i] = tuple(fields) 121 121 return entries … … 224 224 printer.PricePerJob = fields.get("priceperjob") or 0.0 225 225 printer.PricePerPage = fields.get("priceperpage") or 0.0 226 printer.Description = unicode((fields.get("description") or ""), "UTF-8").encode(self.tool.getCharset())226 printer.Description = self.databaseToUserCharset(fields.get("description") or "") 227 227 printer.Exists = 1 228 228 return printer … … 276 276 lastjob.JobPrice = fields.get("jobprice") 277 277 lastjob.JobAction = fields.get("action") 278 lastjob.JobFileName = unicode((fields.get("filename") or ""), "UTF-8").encode(self.tool.getCharset())279 lastjob.JobTitle = unicode((fields.get("title") or ""), "UTF-8").encode(self.tool.getCharset())278 lastjob.JobFileName = self.databaseToUserCharset(fields.get("filename") or "") 279 lastjob.JobTitle = self.databaseToUserCharset(fields.get("title") or "") 280 280 lastjob.JobCopies = fields.get("copies") 281 lastjob.JobOptions = unicode((fields.get("options") or ""), "UTF-8").encode(self.tool.getCharset())281 lastjob.JobOptions = self.databaseToUserCharset(fields.get("options") or "") 282 282 lastjob.JobDate = fields.get("jobdate") 283 283 lastjob.JobHostName = fields.get("hostname") … … 338 338 printer.PricePerJob = record.get("priceperjob") or 0.0 339 339 printer.PricePerPage = record.get("priceperpage") or 0.0 340 printer.Description = unicode((record.get("description") or ""), "UTF-8").encode(self.tool.getCharset())340 printer.Description = self.databaseToUserCharset(record.get("description") or "") 341 341 printer.Exists = 1 342 342 printers.append(printer) … … 424 424 def writePrinterDescription(self, printer) : 425 425 """Write the printer's description back into the storage.""" 426 description = printer.Description 427 if description is not None : 428 description = unicode(printer.Description, self.tool.getCharset()).encode("UTF-8"), 426 description = self.userCharsetToDatabase(printer.Description) 429 427 self.doModify("UPDATE printers SET description=%s WHERE id=%s" % (self.doQuote(description), self.doQuote(printer.ident))) 430 428 … … 474 472 def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None, jobprice=None, filename=None, title=None, copies=None, options=None, clienthost=None, jobsizebytes=None) : 475 473 """Adds a job in a printer's history.""" 476 if filename is not None : 477 filename = unicode(filename, self.tool.getCharset()).encode("UTF-8") 478 if title is not None : 479 title = unicode(title, self.tool.getCharset()).encode("UTF-8") 480 if options is not None : 481 options = unicode(options, self.tool.getCharset()).encode("UTF-8") 474 filename = self.userCharsetToDatabase(filename) 475 title = self.userCharsetToDatabase(title) 476 options = self.userCharsetToDatabase(options) 482 477 if (not self.disablehistory) or (not printer.LastJob.Exists) : 483 478 if jobsize is not None : … … 539 534 job.JobPrice = fields.get("jobprice") 540 535 job.JobAction = fields.get("action") 541 job.JobFileName = unicode((fields.get("filename") or ""), "UTF-8").encode(self.tool.getCharset())542 job.JobTitle = unicode((fields.get("title") or ""), "UTF-8").encode(self.tool.getCharset())536 job.JobFileName = self.databaseToUserCharset(fields.get("filename") or "") 537 job.JobTitle = self.databaseToUserCharset(fields.get("title") or "") 543 538 job.JobCopies = fields.get("copies") 544 job.JobOptions = unicode((fields.get("options") or ""), "UTF-8").encode(self.tool.getCharset())539 job.JobOptions = self.databaseToUserCharset(fields.get("options") or "") 545 540 job.JobDate = fields.get("jobdate") 546 541 job.JobHostName = fields.get("hostname")