File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -884,6 +884,9 @@ def raw(self):
884
884
885
885
Warning, this may consume a lot of memory, check :attr:`size` first.
886
886
"""
887
+ if self .file is None :
888
+ raise MultipartError ("Cannot read from closed MultipartPart" )
889
+
887
890
pos = self .file .tell ()
888
891
self .file .seek (0 )
889
892
@@ -895,6 +898,8 @@ def save_as(self, path):
895
898
""" Save a copy of this part to `path` and return the number of bytes
896
899
written.
897
900
"""
901
+ if self .file is None :
902
+ raise MultipartError ("Cannot read from closed MultipartPart" )
898
903
899
904
with open (path , "wb" ) as fp :
900
905
pos = self .file .tell ()
Original file line number Diff line number Diff line change @@ -197,5 +197,12 @@ def test_segment_close(self):
197
197
file1 .close ()
198
198
self .assertIsNone (file1 .file )
199
199
200
+ with self .assertMultipartError ("Cannot read from closed MultipartPart" ):
201
+ file1 .raw
202
+ with self .assertMultipartError ("Cannot read from closed MultipartPart" ):
203
+ file1 .value
204
+ with self .assertMultipartError ("Cannot read from closed MultipartPart" ):
205
+ file1 .save_as ("/tmp/foo" )
206
+
200
207
# Closing again is a NOP
201
208
file1 .close () # Do nothing
You can’t perform that action at this time.
0 commit comments