comparison roundup/dehtml.py @ 5838:b74f0b50bef1

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()
author John Rouillard <rouilj@ieee.org>
date Sat, 06 Jul 2019 17:36:25 -0400
parents c749d6795bc2
children 1700542408f3
comparison
equal deleted inserted replaced
5837:883c9e90b403 5838:b74f0b50bef1
27 # use the fallback below if beautiful soup is not installed. 27 # use the fallback below if beautiful soup is not installed.
28 try: 28 try:
29 # Python 3+. 29 # Python 3+.
30 from html.parser import HTMLParser 30 from html.parser import HTMLParser
31 from html.entities import name2codepoint 31 from html.entities import name2codepoint
32 pyver=3
32 except ImportError: 33 except ImportError:
33 # Python 2. 34 # Python 2.
34 from HTMLParser import HTMLParser 35 from HTMLParser import HTMLParser
35 from htmlentitydefs import name2codepoint 36 from htmlentitydefs import name2codepoint
37 pyver=2
36 38
37 class DumbHTMLParser(HTMLParser): 39 class DumbHTMLParser(HTMLParser):
38 # class attribute 40 # class attribute
39 text="" 41 text=""
40 42
73 c = uchr(name2codepoint[name]) 75 c = uchr(name2codepoint[name])
74 try: 76 try:
75 self.text= self.text + c 77 self.text= self.text + c
76 except UnicodeEncodeError: 78 except UnicodeEncodeError:
77 # print a space as a placeholder 79 # print a space as a placeholder
78 pass 80 self.text= self.text + ' '
79 81
80 def html2text(html): 82 def html2text(html):
81 parser = DumbHTMLParser() 83 if pyver == 3:
84 parser = DumbHTMLParser(convert_charrefs=True)
85 else:
86 parser = DumbHTMLParser()
82 parser.feed(html) 87 parser.feed(html)
83 parser.close() 88 parser.close()
84 return parser.text 89 return parser.text
85 90
86 self.html2text = html2text 91 self.html2text = html2text
128 known to require this.</p> 133 known to require this.</p>
129 <p>If you&#8217;re on windows, you will either need to be using the ActiveState python 134 <p>If you&#8217;re on windows, you will either need to be using the ActiveState python
130 distribution (at <a class="reference external" href="http://www.activestate.com/Products/ActivePython/">http://www.activestate.com/Products/ActivePython/</a>), or you&#8217;ll 135 distribution (at <a class="reference external" href="http://www.activestate.com/Products/ActivePython/">http://www.activestate.com/Products/ActivePython/</a>), or you&#8217;ll
131 have to install the win32all package separately (get it from 136 have to install the win32all package separately (get it from
132 <a class="reference external" href="http://starship.python.net/crew/mhammond/win32/">http://starship.python.net/crew/mhammond/win32/</a>).</p> 137 <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>
133 </div> 141 </div>
134 </body> 142 </body>
135 ''' 143 '''
136 144
137 html2text = dehtml("dehtml").html2text 145 html2text = dehtml("dehtml").html2text

Roundup Issue Tracker: http://roundup-tracker.org/