11
22from __future__ import print_function
3- from roundup .anypy .strings import u2s , uchr
43
54import sys
5+
6+ from roundup .anypy .strings import u2s , uchr
7+
68_pyver = sys .version_info [0 ]
79
810
@@ -24,7 +26,7 @@ def html2text(html):
2426 for script in soup (["script" , "style" ]):
2527 script .extract ()
2628
27- return u2s (soup .get_text (' \n ' , strip = True ))
29+ return u2s (soup .get_text (" \n " , strip = True ))
2830
2931 self .html2text = html2text
3032 else :
@@ -33,12 +35,12 @@ def html2text(html):
3335 # use the fallback below if beautiful soup is not installed.
3436 try :
3537 # Python 3+.
36- from html .parser import HTMLParser
3738 from html .entities import name2codepoint
39+ from html .parser import HTMLParser
3840 except ImportError :
3941 # Python 2.
40- from HTMLParser import HTMLParser
4142 from htmlentitydefs import name2codepoint
43+ from HTMLParser import HTMLParser
4244
4345 class DumbHTMLParser (HTMLParser ):
4446 # class attribute
@@ -81,7 +83,7 @@ def handle_entityref(self, name):
8183 self .text = self .text + c
8284 except UnicodeEncodeError :
8385 # print a space as a placeholder
84- self .text = self .text + ' '
86+ self .text = self .text + " "
8587
8688 def html2text (html ):
8789 if _pyver == 3 :
@@ -95,8 +97,8 @@ def html2text(html):
9597 self .html2text = html2text
9698
9799
98- if "__main__" == __name__ :
99- html = '''
100+ if __name__ == "__main__" :
101+ html = """
100102<body>
101103<script>
102104this must not be in output
@@ -145,7 +147,7 @@ def html2text(html):
145147</script>
146148</div>
147149</body>
148- '''
150+ """
149151
150152 html2text = dehtml ("dehtml" ).html2text
151153 if html2text :
0 commit comments