From 3795974c6f92b8fb406fa0283f31fb2de6ec48d6 Mon Sep 17 00:00:00 2001 From: Gary Burton Date: Tue, 22 Jan 2013 20:56:11 +0000 Subject: [PATCH] Bug #6255. svn: r21201 --- gramps/plugins/importer/importxml.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gramps/plugins/importer/importxml.py b/gramps/plugins/importer/importxml.py index 102717872..e07c8e77f 100644 --- a/gramps/plugins/importer/importxml.py +++ b/gramps/plugins/importer/importxml.py @@ -375,16 +375,21 @@ class LineParser(object): try: if use_gzip: - 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")) + if sys.version_info[0] == 2: + ofile = gzip.open(filename, "rb") + else: + 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. + # 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%. + # It should work correctly from version 3.3. + ofile = io.TextIOWrapper(gzip.open(filename, "rb")) else: ofile = open(filename, "r")