Skip to content

Commit ea46d69

Browse files
committed
workaround for gzip.open() failure in Windows Python 2.7
- fix #99 - implement workaround from https://bugs.python.org/issue30012 : for Python 3, use mode="rt", for Python 2, just use default ("r")
1 parent c8794b2 commit ea46d69

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

gridData/OpenDX.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@
174174

175175
import warnings
176176

177+
# Python 2/3 compatibility (see issue #99)
178+
# and https://bugs.python.org/issue30012
179+
import sys
180+
if sys.version_info >= (3, ):
181+
def _gzip_open(filename, mode="rt"):
182+
return gzip.open(filename, mode)
183+
else:
184+
def _gzip_open(filename, mode="rt"):
185+
return gzip.open(filename)
186+
del sys
187+
177188
class DXclass(object):
178189
"""'class' object as defined by OpenDX"""
179190
def __init__(self,classid):
@@ -707,7 +718,7 @@ def parse(self, DXfield):
707718
self.tokens = [] # token buffer
708719

709720
if self.filename.endswith('.gz'):
710-
with gzip.open(self.filename, 'rt') as self.dxfile:
721+
with _gzip_open(self.filename, 'rt') as self.dxfile:
711722
self.use_parser('general')
712723
else:
713724
with open(self.filename, 'r') as self.dxfile:

0 commit comments

Comments
 (0)