Mercurial > p > roundup > code
comparison roundup/dehtml.py @ 5376:64b05e24dbd8
Python 3 preparation: convert print to a function.
Tool-assisted patch. It is possible that some "from __future__ import
print_function" are not in fact needed, if a file only uses print()
with a single string as an argument and so would work fine in Python 2
without that import.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 09:54:52 +0000 |
| parents | e20f472fde7d |
| children | 9c6d98bf79db |
comparison
equal
deleted
inserted
replaced
| 5375:1ad46057ae4a | 5376:64b05e24dbd8 |
|---|---|
| 1 | 1 |
| 2 from __future__ import print_function | |
| 2 class dehtml: | 3 class dehtml: |
| 3 def __init__(self, converter): | 4 def __init__(self, converter): |
| 4 if converter == "none": | 5 if converter == "none": |
| 5 self.html2text = None | 6 self.html2text = None |
| 6 return | 7 return |
| 126 </body> | 127 </body> |
| 127 ''' | 128 ''' |
| 128 | 129 |
| 129 html2text = dehtml("dehtml").html2text | 130 html2text = dehtml("dehtml").html2text |
| 130 if html2text: | 131 if html2text: |
| 131 print html2text(html) | 132 print(html2text(html)) |
| 132 | 133 |
| 133 try: | 134 try: |
| 134 # trap error seen if N_TOKENS not defined when run. | 135 # trap error seen if N_TOKENS not defined when run. |
| 135 html2text = dehtml("beautifulsoup").html2text | 136 html2text = dehtml("beautifulsoup").html2text |
| 136 if html2text: | 137 if html2text: |
| 137 print html2text(html) | 138 print(html2text(html)) |
| 138 except NameError as e: | 139 except NameError as e: |
| 139 print "captured error %s"%e | 140 print("captured error %s"%e) |
| 140 | 141 |
| 141 html2text = dehtml("none").html2text | 142 html2text = dehtml("none").html2text |
| 142 if html2text: | 143 if html2text: |
| 143 print "FAIL: Error, dehtml(none) is returning a function" | 144 print("FAIL: Error, dehtml(none) is returning a function") |
| 144 else: | 145 else: |
| 145 print "PASS: dehtml(none) is returning None" | 146 print("PASS: dehtml(none) is returning None") |
| 146 | 147 |
| 147 | 148 |
