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+
129134hashtagRe = re .compile (r'(?P<hashtag>#\S+)' )
130135profileRe = re .compile (r'(?P<profile>\@\S+)' )
131136ansiFormatter = ansi .AnsiCmd (False )
@@ -207,7 +212,7 @@ def reRepl(m):
207212
208213
209214def 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
232237class 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
254259class 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