From 64df118c65c6b5d48a8153ebbd830c0c7c9cac52 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Wed, 26 Jan 2011 20:28:34 -0600 Subject: [PATCH] move Twitter._unescape to Module._unencode_xml --- Module.py | 8 ++++++++ TODO | 2 -- modules/Twitter.py | 16 ++++------------ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Module.py b/Module.py index e761e9b..5a30be0 100644 --- a/Module.py +++ b/Module.py @@ -172,5 +172,13 @@ class Module(object): is no suitable help available""" return None + def _unencode_xml(self, text): + """Convert <, >, & to their real entities.""" + + text = text.replace('<', '<') + text = text.replace('>', '>') + text = text.replace('&', '&') + return text + # vi:tabstop=4:expandtab:autoindent # kate: indent-mode python;indent-width 4;replace-tabs on; diff --git a/TODO b/TODO index f9052cf..28106c3 100644 --- a/TODO +++ b/TODO @@ -13,6 +13,4 @@ dr.botzo --- TODO * fix the cheap unicode escapes in GoogleTranslate note: see commit 3333fe125e8c06a739b4d5e4bbc3ef5c1070fe91 * periodic reconnects when disconnected/split - * move Twitter's _unescape into something common, like DrBotIRC? - * actually, Module is probably better, where it should be __unencode_xml or something * Alias: convert to use database, since configparser stuff mangles (lowercases) keys diff --git a/modules/Twitter.py b/modules/Twitter.py index e2fa911..24ea76f 100644 --- a/modules/Twitter.py +++ b/modules/Twitter.py @@ -274,14 +274,14 @@ class Twitter(Module): if tweet.retweeted_status: retweet = tweet.retweeted_status if print_source: - return '%s (RT %s): %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), retweet.user.name.encode('utf-8', 'ignore'), self._unescape(retweet.text.encode('utf-8', 'ignore')), tweet.id) + return '%s (RT %s): %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), retweet.user.name.encode('utf-8', 'ignore'), super(Twitter, self)._unencode_xml(retweet.text.encode('utf-8', 'ignore')), tweet.id) else: - return '(RT %s): %s [%s]' % (retweet.user.name.encode('utf-8', 'ignore'), self._unescape(retweet.text.encode('utf-8', 'ignore')), tweet.id) + return '(RT %s): %s [%s]' % (retweet.user.name.encode('utf-8', 'ignore'), super(Twitter, self)._unencode_xml(retweet.text.encode('utf-8', 'ignore')), tweet.id) else: if print_source: - return '%s: %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), self._unescape(tweet.text.encode('utf-8', 'ignore')), tweet.id) + return '%s: %s [%s]' % (tweet.user.name.encode('utf-8', 'ignore'), super(Twitter, self)._unencode_xml(tweet.text.encode('utf-8', 'ignore')), tweet.id) else: - return '%s [%s]' % (self._unescape(tweet.text.encode('utf-8', 'ignore')), tweet.id) + return '%s [%s]' % (super(Twitter, self)._unencode_xml(tweet.text.encode('utf-8', 'ignore')), tweet.id) def _get_last_since_id(self): """Get the since_id out of the database.""" @@ -349,13 +349,5 @@ class Twitter(Module): return latest - def _unescape(self, text): - """Convert <, >, & to their real entities.""" - - text = text.replace('<', '<') - text = text.replace('>', '>') - text = text.replace('&', '&') - return text - # vi:tabstop=4:expandtab:autoindent # kate: indent-mode python;indent-width 4;replace-tabs on;