move Twitter._unescape to Module._unencode_xml

This commit is contained in:
Brian S. Stephan 2011-01-26 20:28:34 -06:00
parent 28f450ab5d
commit 64df118c65
3 changed files with 12 additions and 14 deletions

View File

@ -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('&lt;', '<')
text = text.replace('&gt;', '>')
text = text.replace('&amp;', '&')
return text
# vi:tabstop=4:expandtab:autoindent
# kate: indent-mode python;indent-width 4;replace-tabs on;

2
TODO
View File

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

View File

@ -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 &lt;, &gt;, &amp; to their real entities."""
text = text.replace('&lt;', '<')
text = text.replace('&gt;', '>')
text = text.replace('&amp;', '&')
return text
# vi:tabstop=4:expandtab:autoindent
# kate: indent-mode python;indent-width 4;replace-tabs on;