Mercurial > xib
comparison bot.py @ 246:5e65f52be453
make sure Bot.error doesn't raise a transcoding exception and uses repr() when there is a problem
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Mon, 08 Mar 2010 18:39:53 +0100 |
parents | c9652650d5b5 |
children | 5d6ff929e6bc |
comparison
equal
deleted
inserted
replaced
245:cf4f00441628 | 246:5e65f52be453 |
---|---|
62 self.xmpp_thread.start() | 62 self.xmpp_thread.start() |
63 | 63 |
64 | 64 |
65 def error(self, importance, message, debug=False, no_debug_add='', send_to_admins=False): | 65 def error(self, importance, message, debug=False, no_debug_add='', send_to_admins=False): |
66 """Output an error message.""" | 66 """Output an error message.""" |
67 try: | |
68 message = message.encode('utf-8') | |
69 except: | |
70 message = repr(message) | |
67 if not self.debug: | 71 if not self.debug: |
68 message += no_debug_add | 72 message += no_debug_add |
69 if send_to_admins == True: | 73 if send_to_admins == True: |
70 self._send_message_to_admins(importance, message) | 74 self._send_message_to_admins(importance, message) |
71 if importance == -1: | 75 if importance == -1: |
72 return | 76 return |
73 if not debug: | 77 if not debug: |
74 self.error_fd.write(self.format_message(importance, message).encode('utf-8')+'\n') | 78 self.error_fd.write(self.format_message(importance, message)+'\n') |
75 elif self.debug: | 79 elif self.debug: |
76 self.error_fd.write('='*importance+'> '+message.encode('utf-8')+'\n') | 80 self.error_fd.write('='*importance+'> '+message+'\n') |
77 | 81 |
78 | 82 |
79 def _xmpp_loop(self): | 83 def _xmpp_loop(self): |
80 """[Internal] XMPP infinite loop.""" | 84 """[Internal] XMPP infinite loop.""" |
81 i = 1 | 85 i = 1 |