diff --git a/html2text.py b/html2text.py
index 17528901..99b36b83 100755
--- a/html2text.py
+++ b/html2text.py
@@ -35,6 +35,11 @@ def has_key(x, y):
try: from textwrap import wrap
except: pass
+#support the python3 API
+if sys.version_info[0] == 3:
+ unichr=chr
+ xrange=range
+
# Use Unicode characters instead of their ascii psuedo-replacements
UNICODE_SNOB = 0
@@ -543,7 +548,7 @@ def handle_tag(self, tag, attrs, start):
nest_count = self.google_nest_count(tag_style)
else:
nest_count = len(self.list)
- self.o(" " * nest_count) #TODO: line up
- s > 9 correctly.
+ self.o(" " * int(nest_count)) #TODO: line up
- s > 9 correctly.
if li['name'] == "ul": self.o(self.ul_item_mark + " ")
elif li['name'] == "ol":
li['num'] += 1
diff --git a/test/run_tests.py b/test/run_tests.py
index 7ebfd394..b2257536 100644
--- a/test/run_tests.py
+++ b/test/run_tests.py
@@ -20,11 +20,18 @@ def test_module(fn, google_doc=False, **kwargs):
h.body_width = 0
h.hide_strikethrough = True
- for k, v in kwargs.iteritems():
- setattr(h, k, v)
+ if sys.version_info[0] == 3:
+ for k, v in kwargs.items():
+ setattr(h, k, v)
+ else:
+ for k, v in kwargs.iteritems():
+ setattr(h, k, v)
result = get_baseline(fn)
- actual = h.handle(file(fn).read())
+ if sys.version_info[0] == 3:
+ actual = h.handle(codecs.open(fn, mode='r', encoding='utf8').read())
+ else:
+ actual = h.handle(file(fn).read())
return print_result(fn, 'module', result, actual)
def test_command(fn, *args):
@@ -43,7 +50,10 @@ def test_command(fn, *args):
cmd += [fn]
result = get_baseline(fn)
- actual = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()
+ if sys.version_info[0] == 3:
+ actual = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read().decode('utf8')
+ else:
+ actual = subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout.read()
if os.name == 'nt':
# Fix the unwanted CR to CRCRLF replacement