Remove use of the cgi module
This commit is contained in:
parent
bebea99d48
commit
30024fb1c1
94
0001-Remove-use-of-the-cgi-module.patch
Normal file
94
0001-Remove-use-of-the-cgi-module.patch
Normal file
@ -0,0 +1,94 @@
|
||||
diff -purN requests-ftp-0.3.1.orig/requests_ftp/ftp.py requests-ftp-0.3.1/requests_ftp/ftp.py
|
||||
--- requests-ftp-0.3.1.orig/requests_ftp/ftp.py 2023-10-02 11:37:02.265791589 -0400
|
||||
+++ requests-ftp-0.3.1/requests_ftp/ftp.py 2023-10-02 11:38:01.070198328 -0400
|
||||
@@ -6,7 +6,6 @@ from requests.compat import urlparse
|
||||
from requests.hooks import dispatch_hook
|
||||
from requests import Response, codes
|
||||
from io import BytesIO
|
||||
-import cgi
|
||||
import os
|
||||
import socket
|
||||
import logging
|
||||
@@ -30,12 +29,6 @@ class FTPSession(requests.Session):
|
||||
content field contains the binary data.'''
|
||||
return self.request('RETR', url, **kwargs)
|
||||
|
||||
- def stor(self, url, files=None, **kwargs):
|
||||
- '''Sends an FTP STOR to a given URL. Returns a Response object. Expects
|
||||
- to be given one file by the standard Requests method. The remote
|
||||
- filename will be given by the URL provided.'''
|
||||
- return self.request('STOR', url, files=files, **kwargs)
|
||||
-
|
||||
def nlst(self, url, **kwargs):
|
||||
'''Sends an FTP NLST. Returns a Response object.'''
|
||||
return self.request('NLST', url, **kwargs)
|
||||
@@ -54,30 +47,6 @@ def monkeypatch_session():
|
||||
return
|
||||
|
||||
|
||||
-def parse_multipart_files(request):
|
||||
- '''Given a prepared reqest, return a file-like object containing the
|
||||
- original data. This is pretty hacky.'''
|
||||
- # Start by grabbing the pdict.
|
||||
- _, pdict = cgi.parse_header(request.headers['Content-Type'])
|
||||
-
|
||||
- # Now, wrap the multipart data in a BytesIO buffer. This is annoying.
|
||||
- buf = BytesIO()
|
||||
- buf.write(request.body)
|
||||
- buf.seek(0)
|
||||
-
|
||||
- # Parse the data. Simply take the first file.
|
||||
- data = cgi.parse_multipart(buf, pdict)
|
||||
- _, filedata = data.popitem()
|
||||
- buf.close()
|
||||
-
|
||||
- # Get a BytesIO now, and write the file into it.
|
||||
- buf = BytesIO()
|
||||
- buf.write(''.join(filedata))
|
||||
- buf.seek(0)
|
||||
-
|
||||
- return buf
|
||||
-
|
||||
-
|
||||
def data_callback_factory(variable):
|
||||
'''Returns a callback suitable for use by the FTP library. This callback
|
||||
will repeatedly save data into the variable provided to this function. This
|
||||
@@ -180,7 +149,6 @@ class FTPAdapter(requests.adapters.BaseA
|
||||
# send the specific queries.
|
||||
self.func_table = {'LIST': self.list,
|
||||
'RETR': self.retr,
|
||||
- 'STOR': self.stor,
|
||||
'NLST': self.nlst,
|
||||
'SIZE': self.size,
|
||||
'HEAD': self.head,
|
||||
@@ -359,30 +327,6 @@ class FTPAdapter(requests.adapters.BaseA
|
||||
response.status_code = codes.ok
|
||||
return response
|
||||
|
||||
- def stor(self, path, request):
|
||||
- '''Executes the FTP STOR command on the given path.'''
|
||||
-
|
||||
- # First, get the file handle. We assume (bravely)
|
||||
- # that there is only one file to be sent to a given URL. We also
|
||||
- # assume that the filename is sent as part of the URL, not as part of
|
||||
- # the files argument. Both of these assumptions are rarely correct,
|
||||
- # but they are easy.
|
||||
- data = parse_multipart_files(request)
|
||||
-
|
||||
- # Split into the path and the filename.
|
||||
- path, filename = os.path.split(path)
|
||||
-
|
||||
- # Switch directories and upload the data.
|
||||
- self.conn.cwd(path)
|
||||
- code = self.conn.storbinary('STOR ' + filename, data)
|
||||
-
|
||||
- # Close the connection and build the response.
|
||||
- self.conn.close()
|
||||
-
|
||||
- response = build_binary_response(request, BytesIO(), code)
|
||||
-
|
||||
- return response
|
||||
-
|
||||
def nlst(self, path, request):
|
||||
'''Executes the FTP NLST command on the given path.'''
|
||||
data = BytesIO()
|
@ -16,7 +16,7 @@
|
||||
|
||||
Name: python-%{srcname}
|
||||
Version: 0.3.1
|
||||
Release: 29%{?dist}
|
||||
Release: 30%{?dist}
|
||||
Summary: FTP transport adapter for python-requests
|
||||
|
||||
License: ASL 2.0
|
||||
@ -34,8 +34,10 @@ Patch2: PR28-02-Adding-code-3-to-retr4ieve-status_code.patch
|
||||
Patch3: PR28-03-fix-warning-in-interpreting-ftp-status-codes-minor-d.patch
|
||||
# 2caa427 is only test updates, tests not in pypi tarball
|
||||
# from 7321ab3
|
||||
Patch5: PR28-05-Improve-logging-in-status-code-extraction.patch
|
||||
Patch5: PR28-05-Improve-logging-in-status-code-extraction.patch
|
||||
|
||||
# Remove use of the cgi module, which is only used to implement STOR
|
||||
Patch6: 0001-Remove-use-of-the-cgi-module.patch
|
||||
|
||||
%description
|
||||
Requests-FTP is an implementation of a very stupid FTP transport adapter for
|
||||
@ -114,6 +116,9 @@ rm -rf requests_ftp.egg-info
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Mon Oct 2 2023 David Shea <reallylongword@gmail.com> - 0.3.1-30
|
||||
- Remove use of the cgi module
|
||||
|
||||
* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.3.1-29
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user