Commit 77507820 authored by sim's avatar sim

[REFACT] Parser: make use of context managers for zipfiles

parent d857fdb8
...@@ -165,11 +165,10 @@ class Parser: ...@@ -165,11 +165,10 @@ class Parser:
file = self._file file = self._file
# if the file is a ZIP archive, recurse on each of its files... # if the file is a ZIP archive, recurse on each of its files...
if zipfile.is_zipfile(file): if zipfile.is_zipfile(file):
zipArchive = zipfile.ZipFile(file) with zipfile.ZipFile(file) as zipArchive:
for filename in zipArchive.namelist(): for filename in zipArchive.namelist():
f = zipArchive.open(filename, 'r') with zipArchive.open(filename) as f:
yield from self.__iter__(f) yield from self.__iter__(f)
f.close()
# ...otherwise, let's parse it directly! # ...otherwise, let's parse it directly!
else: else:
try: try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment