Changeset 2804 for pykota/trunk

Show
Ignore:
Timestamp:
03/25/06 22:22:07 (18 years ago)
Author:
jerome
Message:

Ensures that all texts sent by pknotify to a remote pykoticon server
are UTF-8 encoded.

Location:
pykota/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/pknotify

    r2802 r2804  
    152152    def sanitizeMessage(self, msg) : 
    153153        """Replaces \\n and returns a messagee in xmlrpclib Binary format.""" 
    154         return xmlrpclib.Binary(msg.replace("\\n", "\n")) 
     154        return xmlrpclib.Binary(self.userCharsetToUTF8(msg.replace("\\n", "\n"))) 
    155155         
    156156    def convPAM(self, auth, queries=[], userdata=None) : 
     
    243243                    if options["checkauth"] : 
    244244                        if ("username" in varnames) and ("password" in varnames) : 
    245                             if self.checkAuth(result["username"].data, result["password"].data) : 
     245                            if self.checkAuth(self.UTF8ToUserCharset(result["username"].data[:]),  
     246                                              self.UTF8ToUserCharset(result["password"].data[:])) : 
    246247                                authok = "AUTH=YES" 
    247248                            else :     
     
    252253                        if (varname != "password") \ 
    253254                           and ((varname != "username") or (authok in (None, "AUTH=YES"))) : 
    254                             print "%s=%s" % (varname.upper(), result[varname].data) 
     255                            print "%s=%s" % (varname.upper(), self.UTF8ToUserCharset(result[varname].data[:])) 
    255256                    if authok is not None :         
    256257                        print authok         
     
    275276    try : 
    276277        defaults = { \ 
    277                      "denyafter" : 1, 
     278                     "denyafter" : 0, 
    278279                     "timeout" : 0, 
    279280                   } 
  • pykota/trunk/pykota/storage.py

    r2801 r2804  
    646646    def databaseToUserCharset(self, text) : 
    647647        """Converts from database format (UTF-8) to user's charset.""" 
    648         if text is not None : 
    649             try : 
    650                 return unicode(text, "UTF-8").encode(self.tool.getCharset())  
    651             except UnicodeError :     
    652                 try : 
    653                     # Incorrect locale settings ? 
    654                     return unicode(text, "UTF-8").encode("ISO-8859-15")  
    655                 except UnicodeError :     
    656                     pass 
    657         return text 
     648        return self.tool.UTF8ToUserCharset(text) 
    658649         
    659650    def userCharsetToDatabase(self, text) : 
    660651        """Converts from user's charset to database format (UTF-8).""" 
    661         if text is not None : 
    662             try : 
    663                 return unicode(text, self.tool.getCharset()).encode("UTF-8")  
    664             except UnicodeError :     
    665                 try : 
    666                     # Incorrect locale settings ? 
    667                     return unicode(text, "ISO-8859-15").encode("UTF-8")  
    668                 except UnicodeError :     
    669                     pass 
    670         return text 
     652        return self.tool.userCharsetToUTF8(text) 
    671653         
    672654    def cleanDates(self, startdate, enddate) :     
  • pykota/trunk/pykota/tool.py

    r2795 r2804  
    236236        """Returns the charset in use.""" 
    237237        return self.charset 
     238         
     239    def UTF8ToUserCharset(self, text) : 
     240        """Converts from UTF-8 to user's charset.""" 
     241        if text is not None : 
     242            try : 
     243                return unicode(text, "UTF-8").encode(self.charset)  
     244            except UnicodeError :     
     245                try : 
     246                    # Incorrect locale settings ? 
     247                    return unicode(text, "UTF-8").encode("ISO-8859-15")  
     248                except UnicodeError :     
     249                    pass 
     250        return text 
     251         
     252    def userCharsetToUTF8(self, text) : 
     253        """Converts from user's charset to UTF-8.""" 
     254        if text is not None : 
     255            try : 
     256                return unicode(text, self.charset).encode("UTF-8")  
     257            except UnicodeError :     
     258                try : 
     259                    # Incorrect locale settings ? 
     260                    return unicode(text, "ISO-8859-15").encode("UTF-8")  
     261                except UnicodeError :     
     262                    pass 
     263        return text 
    238264         
    239265    def display(self, message) :