Skip to content

Commit

Permalink
Fix HTMLParser.unescape method remove from python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
tyjak committed Dec 2, 2020
1 parent 0e8c29c commit a5b6d22
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions twitter/cmdline.py
Expand Up @@ -125,7 +125,12 @@
'force-ansi': False,
}

gHtmlParser = HTMLParser.HTMLParser()
try:
unescape = HTMLParser.HTMLParser().unescape
except AttributeError:
import html
unescape = html.unescape

hashtagRe = re.compile(r'(?P<hashtag>#\S+)')
profileRe = re.compile(r'(?P<profile>\@\S+)')
ansiFormatter = ansi.AnsiCmd(False)
Expand Down Expand Up @@ -207,7 +212,7 @@ def reRepl(m):


def replaceInStatus(status):
txt = gHtmlParser.unescape(status)
txt = unescape(status)
txt = re.sub(hashtagRe, reRepl, txt)
txt = re.sub(profileRe, reRepl, txt)
return txt
Expand All @@ -226,7 +231,7 @@ def __call__(self, status, options):
return ("%s@%s %s" % (
get_time_string(status, options),
status['user']['screen_name'],
gHtmlParser.unescape(correctRTStatus(status))))
unescape(correctRTStatus(status))))


class AnsiStatusFormatter(object):
Expand All @@ -248,12 +253,12 @@ def __call__(self, status, options):
status['user']['screen_name'],
status['user']['location'],
status['created_at'],
gHtmlParser.unescape(correctRTStatus(status))))
unescape(correctRTStatus(status))))


class JSONStatusFormatter(object):
def __call__(self, status, options):
status['text'] = gHtmlParser.unescape(status['text'])
status['text'] = unescape(status['text'])
return json.dumps(status)


Expand Down

0 comments on commit a5b6d22

Please sign in to comment.