Skip to content

Commit c26bf79

Browse files
committed
Fix CI deprication warning for HTMLParser convert_charrefs under py3.
/home/travis/build/roundup-tracker/roundup/roundup/dehtml.py:81: DeprecationWarning: The value of convert_charrefs will become True in 3.5. You are encouraged to set the value explicitly. parser = DumbHTMLParser()
1 parent 4dcc57e commit c26bf79

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

roundup/dehtml.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ def html2text(html):
2929
# Python 3+.
3030
from html.parser import HTMLParser
3131
from html.entities import name2codepoint
32+
pyver=3
3233
except ImportError:
3334
# Python 2.
3435
from HTMLParser import HTMLParser
3536
from htmlentitydefs import name2codepoint
37+
pyver=2
3638

3739
class DumbHTMLParser(HTMLParser):
3840
# class attribute
@@ -75,10 +77,13 @@ def handle_entityref(self, name):
7577
self.text= self.text + c
7678
except UnicodeEncodeError:
7779
# print a space as a placeholder
78-
pass
80+
self.text= self.text + ' '
7981

8082
def html2text(html):
81-
parser = DumbHTMLParser()
83+
if pyver == 3:
84+
parser = DumbHTMLParser(convert_charrefs=True)
85+
else:
86+
parser = DumbHTMLParser()
8287
parser.feed(html)
8388
parser.close()
8489
return parser.text
@@ -130,6 +135,9 @@ def html2text(html):
130135
distribution (at <a class="reference external" href="http://www.activestate.com/Products/ActivePython/">http://www.activestate.com/Products/ActivePython/</a>), or you&#8217;ll
131136
have to install the win32all package separately (get it from
132137
<a class="reference external" href="http://starship.python.net/crew/mhammond/win32/">http://starship.python.net/crew/mhammond/win32/</a>).</p>
138+
<script>
139+
&lt; HELP &GT;
140+
</script>
133141
</div>
134142
</body>
135143
'''

0 commit comments

Comments
 (0)