Skip to content

Commit 9317742

Browse files
committed
Fixing opening mask for Win, PY2
1 parent f154491 commit 9317742

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

jwzthreading/utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from __future__ import division
55
from __future__ import print_function
66
from __future__ import unicode_literals
7-
import re
7+
8+
import os
9+
import sys
810

911
MAILBOX_DELIMITER = '^From .*\d\d \d\d\d\d$'
1012

@@ -42,6 +44,7 @@ def parse_mailbox(filename, encoding='utf-8', headersonly=False):
4244
else:
4345
fopen = open
4446

47+
4548
with fopen(filename, 'rb') as fh:
4649
for idx, line in enumerate(fh):
4750
line = line.decode(encoding)
@@ -88,7 +91,11 @@ def parse_mailman_htmlthread(filename):
8891
fopen = open
8992

9093
parser = etree.HTMLParser()
91-
with fopen(filename, 'rt') as fh:
94+
if os.name == 'nt' and sys.version_info < (3, 0):
95+
fmask = 'r'
96+
else:
97+
fmask = 'rt'
98+
with fopen(filename, fmask) as fh:
9299
tree = etree.parse(fh, parser)
93100

94101
elements = filter(lambda x: x.tag == 'ul', tree.find('body'))

0 commit comments

Comments
 (0)