Remove support for cgi.FieldStorage

The python cgi module is being removed in python 3.13[1].

This patch moves the use of cgi.FieldStorage under a try block that will
skip the check for cgi.FieldStorage object in File type parsing.

[1] https://docs.python.org/3/library/cgi.html

Change-Id: Iff145680312c3aba18b5be078fbf1ea32b06080b
This commit is contained in:
Michael Johnson 2024-10-08 20:02:08 +00:00
parent 4c0da145f2
commit f22cde6973

View File

@ -1,4 +1,3 @@
import cgi
import datetime import datetime
import re import re
@ -36,8 +35,13 @@ def datetime_from_param(datatype, value):
@from_param.when_object(File) @from_param.when_object(File)
def filetype_from_param(datatype, value): def filetype_from_param(datatype, value):
# TODO(johnsom) Remove once python 3.13 is the minimum supported version.
try:
import cgi
if isinstance(value, cgi.FieldStorage): if isinstance(value, cgi.FieldStorage):
return File(fieldstorage=value) return File(fieldstorage=value)
except ImportError:
pass
return File(content=value) return File(content=value)