Skip to content

Commit

Permalink
fix: ResourceWarning when using parse_form_data
Browse files Browse the repository at this point in the history
parse_form_data() is responsible for closing MultipartPart instances that are not returned to the caller.

fixes #57
  • Loading branch information
defnull committed Sep 28, 2024
1 parent 6756044 commit 01f2d89
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ def parse_form_data(environ, charset="utf8", strict=False, **kwargs):
files.append(part.name, part)
else: # TODO: Big form-fields go into the files dict. Really?
forms.append(part.name, part.value)
part.close()

elif content_type in (
"application/x-www-form-urlencoded",
Expand All @@ -824,8 +825,9 @@ def parse_form_data(environ, charset="utf8", strict=False, **kwargs):

except MultipartError:
if strict:
for part in files.values():
part.close()
for _, part in files.iterallitems():
if hasattr(part, 'close'):
part.close()
raise

return forms, files

0 comments on commit 01f2d89

Please sign in to comment.