From c9b77d697344e655a1d4ce9723445f8dff185754 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Tue, 1 Oct 2024 13:05:34 +0200 Subject: [PATCH] rest: remove usage of deprecated cgi module --- master/buildbot/www/rest.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/master/buildbot/www/rest.py b/master/buildbot/www/rest.py index e4b3b04372b..04d33603fcb 100644 --- a/master/buildbot/www/rest.py +++ b/master/buildbot/www/rest.py @@ -15,7 +15,6 @@ from __future__ import annotations -import cgi import datetime import fnmatch import json @@ -57,12 +56,13 @@ def __init__(self, message, jsonrpccode): class ContentTypeParser: - def __init__(self, contenttype): + def __init__(self, contenttype: str | bytes | None) -> None: self.typeheader = contenttype - def gettype(self): - mimetype, _ = cgi.parse_header(bytes2unicode(self.typeheader)) - return mimetype + def gettype(self) -> str | None: + if self.typeheader is None: + return None + return bytes2unicode(self.typeheader).split(';', 1)[0] URL_ENCODED = b"application/x-www-form-urlencoded" @@ -191,7 +191,7 @@ def handleErrors(self, writeError): # JSONRPC2 support - def decodeJsonRPC2(self, request): + def decodeJsonRPC2(self, request: server.Request): # Verify the content-type. Browsers are easily convinced to send # POST data to arbitrary URLs via 'form' elements, but they won't # use the application/json content-type.