Skip to content

Commit 38d70a2

Browse files
author
Célian Haydont
committed
[PR review] use "with/as" syntax
1 parent 3294c0b commit 38d70a2

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

dataikuapi/dss/wiki.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,12 @@ def export_to_file(self, path, paperSize="A4", exportAttachment=False):
104104
"""
105105
Download the whole wiki of the project in PDF format into the given output file.
106106
"""
107-
stream = self.get_export_stream(paperSize=paperSize, exportAttachment=exportAttachment)
108-
109-
with open(path, 'wb') as f:
110-
for chunk in stream.iter_content(chunk_size=10000):
111-
if chunk:
112-
f.write(chunk)
113-
f.flush()
114-
stream.close()
107+
with self.get_export_stream(paperSize=paperSize, exportAttachment=exportAttachment) as stream:
108+
with open(path, 'wb') as f:
109+
for chunk in stream.iter_content(chunk_size=10000):
110+
if chunk:
111+
f.write(chunk)
112+
f.flush()
115113

116114
class DSSWikiSettings(object):
117115
"""
@@ -287,14 +285,12 @@ def export_to_file(self, path, paperSize="A4", exportChildren=False, exportAttac
287285
"""
288286
Download an article in PDF format into the given output file.
289287
"""
290-
stream = self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren, exportAttachment=exportAttachment)
291-
292-
with open(path, 'wb') as f:
293-
for chunk in stream.iter_content(chunk_size=10000):
294-
if chunk:
295-
f.write(chunk)
296-
f.flush()
297-
stream.close()
288+
with self.get_export_stream(paperSize=paperSize, exportChildren=exportChildren, exportAttachment=exportAttachment) as stream:
289+
with open(path, 'wb') as f:
290+
for chunk in stream.iter_content(chunk_size=10000):
291+
if chunk:
292+
f.write(chunk)
293+
f.flush()
298294

299295

300296
def delete(self):

0 commit comments

Comments
 (0)