| 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 |