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.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • 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) :