Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit ce7c91a

Browse files
tyjakboogheta
authored andcommitted
Fix HTMLParser.unescape method remove from python 3.9
1 parent 06cb7c4 commit ce7c91a

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

twitter/cmdline.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@
125125
'force-ansi': False,
126126
}
127127

128-
gHtmlParser = HTMLParser.HTMLParser()
128+
try:
129+
unescape = HTMLParser.HTMLParser().unescape
130+
except AttributeError:
131+
import html
132+
unescape = html.unescape
133+
129134
hashtagRe = re.compile(r'(?P<hashtag>#\S+)')
130135
profileRe = re.compile(r'(?P<profile>\@\S+)')
131136
ansiFormatter = ansi.AnsiCmd(False)
@@ -207,7 +212,7 @@ def reRepl(m):
207212

208213

209214
def replaceInStatus(status):
210-
txt = gHtmlParser.unescape(status)
215+
txt = unescape(status)
211216
txt = re.sub(hashtagRe, reRepl, txt)
212217
txt = re.sub(profileRe, reRepl, txt)
213218
return txt
@@ -226,7 +231,7 @@ def __call__(self, status, options):
226231
return ("%s@%s %s" % (
227232
get_time_string(status, options),
228233
status['user']['screen_name'],
229-
gHtmlParser.unescape(correctRTStatus(status))))
234+
unescape(correctRTStatus(status))))
230235

231236

232237
class AnsiStatusFormatter(object):
@@ -248,12 +253,12 @@ def __call__(self, status, options):
248253
status['user']['screen_name'],
249254
status['user']['location'],
250255
status['created_at'],
251-
gHtmlParser.unescape(correctRTStatus(status))))
256+
unescape(correctRTStatus(status))))
252257

253258

254259
class JSONStatusFormatter(object):
255260
def __call__(self, status, options):
256-
status['text'] = gHtmlParser.unescape(status['text'])
261+
status['text'] = unescape(status['text'])
257262
return json.dumps(status)
258263

259264

0 commit comments

Comments
 (0)