Skip to content

Commit

Permalink
Close files (load()/dump()).
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Mar 26, 2018
1 parent 4bf76a8 commit 678ce6b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions objutils/hexfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__copyright__ = """
pyObjUtils - Object file library for Python.
(C) 2010-2016 by Christoph Schueler <cpu12.gems@googlemail.com>
(C) 2010-2018 by Christoph Schueler <cpu12.gems@googlemail.com>
All Rights Reserved
Expand Down Expand Up @@ -187,9 +187,16 @@ def __init__(self):

def load(self, fp, **kws):
if PYTHON_VERSION.major == 3:
return self.read(fp)#.decode()
data = self.read(fp)#.decode()
if hasattr(fp, "close"):
fp.close()
return data
else:
return self.read(fp)
data = self.read(fp)
if hasattr(fp, "close"):
fp.close()
return data


def loads(self, image, **kws):
if PYTHON_VERSION.major == 3:
Expand Down Expand Up @@ -319,6 +326,8 @@ def __init__(self):

def dump(self, fp, image, rowLength = 16, **kws): # TODO: rename to bytesPerRow!
fp.write(self.dumps(image, rowLength))
if hasattr(fp, "close"):
fp.close()

def dumps(self, image, rowLength = 16, **kws):
result = []
Expand Down

0 comments on commit 678ce6b

Please sign in to comment.