Skip to content

Commit

Permalink
Fixed Python2/3 compatibility for bz2 module.
Browse files Browse the repository at this point in the history
  • Loading branch information
smelandr committed Oct 6, 2017
1 parent 8aa5786 commit bee7379
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nmrstarlib/nmrstarlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def read(self, filehandle):
self.update(json_str)
self.bmrbid = self[u"data"]
else:
raise TypeError("Unknown file format")
print("Unknown file format")
# raise TypeError("Unknown file format")
filehandle.close()

def write(self, filehandle, file_format):
Expand Down Expand Up @@ -550,6 +551,7 @@ def _generate_filenames(sources):
if os.path.isdir(source):
for path, dirlist, filelist in os.walk(source):
for fname in filelist:
print("Processing...", fname)
if GenericFilePath.is_compressed(fname):
if VERBOSE:
print("Skipping compressed file: {}".format(os.path.abspath(fname)))
Expand Down Expand Up @@ -653,7 +655,7 @@ def open(self):
filehandle.close()

elif compressiontype == "bz2":
filehandle = bz2.open(io.BytesIO(path)) if is_url else bz2.open(path)
filehandle = bz2.BZ2File(io.BytesIO(path)) if is_url else bz2.BZ2File(path)
source = self.path
yield filehandle, source
filehandle.close()
Expand Down

0 comments on commit bee7379

Please sign in to comment.