1python 3.13 removed some modules such as cgi which is required by python3-requests-ftp: 2 3 https://docs.python.org/3/whatsnew/3.13.html 4 5 Important removals: 6 7 PEP 594: The remaining 19 “dead batteries” (legacy stdlib modules) have 8 been removed from the standard library: aifc, audioop, cgi, cgitb, 9 chunk, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, 10 sndhdr, spwd, sunau, telnetlib, uu and xdrlib. 11 12Backport and rebase a patch from Fedora to remove use of module cgi. 13 14Upstream-Status: Backport [https://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Server/source/tree/Packages/p/python-requests-ftp-0.3.1-36.fc42.src.rpm] 15 16Signed-off-by: Kai Kang <kai.kang@windriver.com> 17--- 18 requests_ftp/ftp.py | 56 --------------------------------------------- 19 1 file changed, 56 deletions(-) 20 21diff --git a/requests_ftp/ftp.py b/requests_ftp/ftp.py 22index 9711905..85dac47 100644 23--- a/requests_ftp/ftp.py 24+++ b/requests_ftp/ftp.py 25@@ -6,7 +6,6 @@ from requests.compat import urlparse 26 from requests.hooks import dispatch_hook 27 from requests import Response, codes 28 from io import BytesIO 29-import cgi 30 import os 31 import socket 32 33@@ -29,12 +28,6 @@ class FTPSession(requests.Session): 34 content field contains the binary data.''' 35 return self.request('RETR', url, **kwargs) 36 37- def stor(self, url, files=None, **kwargs): 38- '''Sends an FTP STOR to a given URL. Returns a Response object. Expects 39- to be given one file by the standard Requests method. The remote 40- filename will be given by the URL provided.''' 41- return self.request('STOR', url, files=files, **kwargs) 42- 43 def nlst(self, url, **kwargs): 44 '''Sends an FTP NLST. Returns a Response object.''' 45 return self.request('NLST', url, **kwargs) 46@@ -52,30 +45,6 @@ def monkeypatch_session(): 47 return 48 49 50-def parse_multipart_files(request): 51- '''Given a prepared reqest, return a file-like object containing the 52- original data. This is pretty hacky.''' 53- # Start by grabbing the pdict. 54- _, pdict = cgi.parse_header(request.headers['Content-Type']) 55- 56- # Now, wrap the multipart data in a BytesIO buffer. This is annoying. 57- buf = BytesIO() 58- buf.write(request.body) 59- buf.seek(0) 60- 61- # Parse the data. Simply take the first file. 62- data = cgi.parse_multipart(buf, pdict) 63- _, filedata = data.popitem() 64- buf.close() 65- 66- # Get a BytesIO now, and write the file into it. 67- buf = BytesIO() 68- buf.write(''.join(filedata)) 69- buf.seek(0) 70- 71- return buf 72- 73- 74 def data_callback_factory(variable): 75 '''Returns a callback suitable for use by the FTP library. This callback 76 will repeatedly save data into the variable provided to this function. This 77@@ -135,7 +104,6 @@ class FTPAdapter(requests.adapters.BaseAdapter): 78 # send the specific queries. 79 self.func_table = {'LIST': self.list, 80 'RETR': self.retr, 81- 'STOR': self.stor, 82 'NLST': self.nlst, 83 'SIZE': self.size, 84 'HEAD': self.head, 85@@ -314,30 +282,6 @@ class FTPAdapter(requests.adapters.BaseAdapter): 86 response.status_code = codes.ok 87 return response 88 89- def stor(self, path, request): 90- '''Executes the FTP STOR command on the given path.''' 91- 92- # First, get the file handle. We assume (bravely) 93- # that there is only one file to be sent to a given URL. We also 94- # assume that the filename is sent as part of the URL, not as part of 95- # the files argument. Both of these assumptions are rarely correct, 96- # but they are easy. 97- data = parse_multipart_files(request) 98- 99- # Split into the path and the filename. 100- path, filename = os.path.split(path) 101- 102- # Switch directories and upload the data. 103- self.conn.cwd(path) 104- code = self.conn.storbinary('STOR ' + filename, data) 105- 106- # Close the connection and build the response. 107- self.conn.close() 108- 109- response = build_binary_response(request, BytesIO(), code) 110- 111- return response 112- 113 def nlst(self, path, request): 114 '''Executes the FTP NLST command on the given path.''' 115 data = BytesIO() 116