Skip to content

Commit

Permalink
Avoid ResourceWarnings about unclosed file descriptors.
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 14, 2017
1 parent 4cc5e5c commit 34db5b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/DocumentTemplate/DT_String.py
Expand Up @@ -566,7 +566,9 @@ def read_raw(self):
print('file not found: %s' % self.raw)

if self.raw:
return open(self.raw, 'r').read()
with open(self.raw, 'r') as fd:
raw = fd.read()
return raw
return ''


Expand Down
5 changes: 2 additions & 3 deletions src/DocumentTemplate/tests/testDTML.py
Expand Up @@ -562,9 +562,8 @@ def read_file(name):
import os
from DocumentTemplate import tests
here = tests.__path__[0]
f = open(os.path.join(here, name), 'r')
res = f.read()
f.close()
with open(os.path.join(here, name), 'r') as fd:
res = fd.read()
return res


Expand Down

0 comments on commit 34db5b9

Please sign in to comment.