Bug #6255. Wrap gzip files with TextIOWrapper to allow them to be read as text.
svn: r21177
This commit is contained in:
parent
99c54b5e2e
commit
f479a876e3
@ -375,7 +375,16 @@ class LineParser(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if use_gzip:
|
if use_gzip:
|
||||||
ofile = gzip.open(filename, "rb")
|
import io
|
||||||
|
# Bug 6255. TextIOWrapper is required for python3 to present
|
||||||
|
# file contents as text, otherwise they are read
|
||||||
|
# as binary. However due to a missing method (read1)
|
||||||
|
# in early python3 versions this try block will fail
|
||||||
|
# It should work correctly from version 3.3
|
||||||
|
# Gramps will still import XML files using python
|
||||||
|
# versions < 3.3.0 but the file progress meter will
|
||||||
|
# not work properly, going immediately to 100%.
|
||||||
|
ofile = io.TextIOWrapper(gzip.open(filename, "rb"))
|
||||||
else:
|
else:
|
||||||
ofile = open(filename, "r")
|
ofile = open(filename, "r")
|
||||||
|
|
||||||
@ -383,11 +392,12 @@ class LineParser(object):
|
|||||||
self.count += 1
|
self.count += 1
|
||||||
if PERSON_RE.match(line):
|
if PERSON_RE.match(line):
|
||||||
self.person_count += 1
|
self.person_count += 1
|
||||||
|
|
||||||
ofile.close()
|
|
||||||
except:
|
except:
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.person_count = 0
|
self.person_count = 0
|
||||||
|
finally:
|
||||||
|
# Ensure the file handle is always closed
|
||||||
|
ofile.close()
|
||||||
|
|
||||||
def get_count(self):
|
def get_count(self):
|
||||||
return self.count
|
return self.count
|
||||||
|
Loading…
Reference in New Issue
Block a user