From f22cde697363c32a56ca7af32744160308850b30 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 8 Oct 2024 20:02:08 +0000 Subject: [PATCH] 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 --- wsme/rest/args.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wsme/rest/args.py b/wsme/rest/args.py index 855b51a..1053697 100644 --- a/wsme/rest/args.py +++ b/wsme/rest/args.py @@ -1,4 +1,3 @@ -import cgi import datetime import re @@ -36,8 +35,13 @@ def datetime_from_param(datatype, value): @from_param.when_object(File) def filetype_from_param(datatype, value): - if isinstance(value, cgi.FieldStorage): - return File(fieldstorage=value) + # TODO(johnsom) Remove once python 3.13 is the minimum supported version. + try: + import cgi + if isinstance(value, cgi.FieldStorage): + return File(fieldstorage=value) + except ImportError: + pass return File(content=value)