From 6e8a908362f49e05c25a39e89d21b6376d09aec3 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Tue, 7 May 2019 06:08:37 -0400 Subject: [PATCH] import python-requests-ftp-0.3.1-11.el8 --- .gitignore | 1 + .python-requests-ftp.metadata | 1 + ...-tests-and-updated-statud_code-build.patch | 22 +++ ...ding-code-3-to-retr4ieve-status_code.patch | 58 +++++++ ...nterpreting-ftp-status-codes-minor-d.patch | 48 ++++++ ...ve-logging-in-status-code-extraction.patch | 28 +++ SPECS/python-requests-ftp.spec | 161 ++++++++++++++++++ 7 files changed, 319 insertions(+) create mode 100644 .gitignore create mode 100644 .python-requests-ftp.metadata create mode 100644 SOURCES/PR28-01-Adding-2-tests-and-updated-statud_code-build.patch create mode 100644 SOURCES/PR28-02-Adding-code-3-to-retr4ieve-status_code.patch create mode 100644 SOURCES/PR28-03-fix-warning-in-interpreting-ftp-status-codes-minor-d.patch create mode 100644 SOURCES/PR28-05-Improve-logging-in-status-code-extraction.patch create mode 100644 SPECS/python-requests-ftp.spec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e9b96a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/requests-ftp-0.3.1.tar.gz diff --git a/.python-requests-ftp.metadata b/.python-requests-ftp.metadata new file mode 100644 index 0000000..6f8575f --- /dev/null +++ b/.python-requests-ftp.metadata @@ -0,0 +1 @@ +ea1ff9cec32458fc3b61382d50b2492855570697 SOURCES/requests-ftp-0.3.1.tar.gz diff --git a/SOURCES/PR28-01-Adding-2-tests-and-updated-statud_code-build.patch b/SOURCES/PR28-01-Adding-2-tests-and-updated-statud_code-build.patch new file mode 100644 index 0000000..c8da902 --- /dev/null +++ b/SOURCES/PR28-01-Adding-2-tests-and-updated-statud_code-build.patch @@ -0,0 +1,22 @@ +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 2015-08-13 16:57:27.000000000 -0400 ++++ requests-ftp-0.3.1/requests_ftp/ftp.py 2018-08-02 10:13:15.801731787 -0400 +@@ -99,7 +99,7 @@ def build_text_response(request, data, c + + def build_binary_response(request, data, code): + '''Build a response for data whose encoding is unknown.''' +- return build_response(request, data, code, None) ++ return build_response(request, data, code, None) + + + def build_response(request, data, code, encoding): +@@ -113,7 +113,8 @@ def build_response(request, data, code, + response.raw = data + response.url = request.url + response.request = request +- response.status_code = int(code.split()[0]) ++ last_valid_line_from_code = [line for line in code.split('\n') if line][-1] ++ response.status_code = int(last_valid_line_from_code.split()[0]) + if hasattr(data, "content_len"): + response.headers['Content-Length'] = str(data.content_len) + diff --git a/SOURCES/PR28-02-Adding-code-3-to-retr4ieve-status_code.patch b/SOURCES/PR28-02-Adding-code-3-to-retr4ieve-status_code.patch new file mode 100644 index 0000000..d746fcf --- /dev/null +++ b/SOURCES/PR28-02-Adding-code-3-to-retr4ieve-status_code.patch @@ -0,0 +1,58 @@ +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 2018-08-02 10:13:15.801731787 -0400 ++++ requests-ftp-0.3.1/requests_ftp/ftp.py 2018-08-02 10:14:20.633933095 -0400 +@@ -9,6 +9,7 @@ from io import BytesIO + import cgi + import os + import socket ++import logging + + from requests.exceptions import ConnectionError, ConnectTimeout, ReadTimeout + from requests.exceptions import RequestException +@@ -102,6 +103,35 @@ def build_binary_response(request, data, + return build_response(request, data, code, None) + + ++def get_status_code_from_code_response(code): ++ ''' ++ The idea is to handle complicated code response (even multi lines). ++ We get the status code in two ways: ++ - extracting the code from the last valid line in the response ++ - getting it from the 3first digits in the code ++ After a comparaison between the two values, ++ we can safely set the code or raise a warning. ++ ++ Examples: ++ - get_code('200 Welcome') == 200 ++ ++ - multi_line_code = '226-File successfully transferred\n226 0.000 seconds' ++ get_code(multi_line_code) == 226 ++ ++ - multi_line_with_code_conflits = '200-File successfully transferred\n226 0.000 seconds' ++ get_code(multi_line_with_code_conflits) == 226 ++ ''' ++ last_valid_line_from_code = [line for line in code.split('\n') if line][-1] ++ status_code_from_last_line = int(last_valid_line_from_code.split()[0]) ++ status_code_from_first_digits = int(code[:3]) ++ if status_code_from_last_line != status_code_from_first_digits: ++ logging.warning( ++ 'Status code seems to be non consistant.\n' ++ 'Code received: %d, extracted: %d and %d' % ( ++ code, status_code_from_last_line, status_code_from_first_digits)) ++ return status_code_from_last_line ++ ++ + def build_response(request, data, code, encoding): + '''Builds a response object from the data returned by ftplib, using the + specified encoding.''' +@@ -113,8 +143,8 @@ def build_response(request, data, code, + response.raw = data + response.url = request.url + response.request = request +- last_valid_line_from_code = [line for line in code.split('\n') if line][-1] +- response.status_code = int(last_valid_line_from_code.split()[0]) ++ response.status_code = get_status_code_from_code_response(code) ++ + if hasattr(data, "content_len"): + response.headers['Content-Length'] = str(data.content_len) + diff --git a/SOURCES/PR28-03-fix-warning-in-interpreting-ftp-status-codes-minor-d.patch b/SOURCES/PR28-03-fix-warning-in-interpreting-ftp-status-codes-minor-d.patch new file mode 100644 index 0000000..5a2f8a6 --- /dev/null +++ b/SOURCES/PR28-03-fix-warning-in-interpreting-ftp-status-codes-minor-d.patch @@ -0,0 +1,48 @@ +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 2018-08-02 10:14:20.633933095 -0400 ++++ requests-ftp-0.3.1/requests_ftp/ftp.py 2018-08-02 10:15:20.491042199 -0400 +@@ -108,26 +108,36 @@ def get_status_code_from_code_response(c + The idea is to handle complicated code response (even multi lines). + We get the status code in two ways: + - extracting the code from the last valid line in the response +- - getting it from the 3first digits in the code +- After a comparaison between the two values, ++ - getting it from the 3 first digits in the code ++ After a comparison between the two values, + we can safely set the code or raise a warning. + + Examples: +- - get_code('200 Welcome') == 200 ++ - get_status_code_from_code_response('200 Welcome') == 200 + + - multi_line_code = '226-File successfully transferred\n226 0.000 seconds' +- get_code(multi_line_code) == 226 ++ get_status_code_from_code_response(multi_line_code) == 226 + +- - multi_line_with_code_conflits = '200-File successfully transferred\n226 0.000 seconds' +- get_code(multi_line_with_code_conflits) == 226 ++ - multi_line_with_code_conflicts = '200-File successfully transferred\n226 0.000 seconds' ++ get_status_code_from_code_response(multi_line_with_code_conflicts) == 226 ++ ++ For more detail see RFC 959, page 36, on multi-line responses: ++ https://www.ietf.org/rfc/rfc959.txt ++ ++ "Thus the format for multi-line replies is that the first line ++ will begin with the exact required reply code, followed ++ immediately by a Hyphen, "-" (also known as Minus), followed by ++ text. The last line will begin with the same code, followed ++ immediately by Space , optionally some text, and the Telnet ++ end-of-line code." + ''' + last_valid_line_from_code = [line for line in code.split('\n') if line][-1] + status_code_from_last_line = int(last_valid_line_from_code.split()[0]) + status_code_from_first_digits = int(code[:3]) + if status_code_from_last_line != status_code_from_first_digits: + logging.warning( +- 'Status code seems to be non consistant.\n' +- 'Code received: %d, extracted: %d and %d' % ( ++ 'FTP response status code seems to be inconsistent.\n' ++ 'Code received: {0}, extracted: {1} and {2}'.format( + code, status_code_from_last_line, status_code_from_first_digits)) + return status_code_from_last_line + diff --git a/SOURCES/PR28-05-Improve-logging-in-status-code-extraction.patch b/SOURCES/PR28-05-Improve-logging-in-status-code-extraction.patch new file mode 100644 index 0000000..6b2c817 --- /dev/null +++ b/SOURCES/PR28-05-Improve-logging-in-status-code-extraction.patch @@ -0,0 +1,28 @@ +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 2018-08-02 10:15:20.491042199 -0400 ++++ requests-ftp-0.3.1/requests_ftp/ftp.py 2018-08-02 10:16:16.588081626 -0400 +@@ -44,6 +44,7 @@ class FTPSession(requests.Session): + '''Sends an FTP SIZE. Returns a decimal number.''' + return self.request('SIZE', url, **kwargs) + ++log = logging.getLogger(__name__) + + def monkeypatch_session(): + '''Monkeypatch Requests Sessions to provide all the helper +@@ -135,10 +136,13 @@ def get_status_code_from_code_response(c + status_code_from_last_line = int(last_valid_line_from_code.split()[0]) + status_code_from_first_digits = int(code[:3]) + if status_code_from_last_line != status_code_from_first_digits: +- logging.warning( ++ log.warning( + 'FTP response status code seems to be inconsistent.\n' +- 'Code received: {0}, extracted: {1} and {2}'.format( +- code, status_code_from_last_line, status_code_from_first_digits)) ++ 'Code received: %s, extracted: %s and %s', ++ code, ++ status_code_from_last_line, ++ status_code_from_first_digits ++ ) + return status_code_from_last_line + + diff --git a/SPECS/python-requests-ftp.spec b/SPECS/python-requests-ftp.spec new file mode 100644 index 0000000..ab5dd5b --- /dev/null +++ b/SPECS/python-requests-ftp.spec @@ -0,0 +1,161 @@ +%global srcname requests-ftp + +# Disable python3 by default on RHEL < 7 +%if 0%{?rhel} && 0%{?rhel} <= 7 +%bcond_with python3 +%else +%bcond_without python3 +%endif + +# Diable python2 by default on RHEL > 7 or Fedora > 28 +%if 0%{?rhel} > 7 || 0%{?fedora} > 28 +%bcond_with python2 +%else +%bcond_without python2 +%endif + +Name: python-%{srcname} +Version: 0.3.1 +Release: 11%{?dist} +Summary: FTP transport adapter for python-requests + +License: ASL 2.0 +URL: https://github.com/Lukasa/requests-ftp +Source0: https://pypi.python.org/packages/source/r/%{srcname}/%{srcname}-%{version}.tar.gz + +BuildArch: noarch + +# from https://github.com/Lukasa/requests-ftp/pull/28, handle multi-line responses +# from 4090846 +Patch1: PR28-01-Adding-2-tests-and-updated-statud_code-build.patch +# from 4f6a9f5 +Patch2: PR28-02-Adding-code-3-to-retr4ieve-status_code.patch +# from 3fb2700 +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 + + +%description +Requests-FTP is an implementation of a very stupid FTP transport adapter for +use with the awesome Requests Python library. + +%if %{with python2} +%package -n python2-%{srcname} +Summary: FTP transport adapter for python-requests +%{?python_provide:%python_provide python2-%{srcname}} + +BuildRequires: python2-devel +BuildRequires: python2-setuptools + +Requires: python2-requests + +%description -n python2-%{srcname} +Requests-FTP is an implementation of a very stupid FTP transport adapter for +use with the awesome Requests Python library. + +This is the Python 2 version of the transport adapter module. +%endif + +%if %{with python3} +%package -n python3-%{srcname} +Summary: FTP transport adapter for python3-requests +%{?python_provide:%python_provide python3-%{srcname}} + +BuildRequires: python3-devel +BuildRequires: python3-setuptools + +Requires: python3-requests + +%description -n python3-requests-ftp +Requests-FTP is an implementation of a very stupid FTP transport adapter for +use with the awesome Requests Python library. + +This is the Python 3 version of the transport adapter module. +%endif + +%prep +%autosetup -n %{srcname}-%{version} -p1 +rm -rf requests_ftp.egg-info + +%build +%if %{with python2} +%py2_build +%endif + +%if %{with python3} +%py3_build +%endif + +%install +%if %{with python2} +%py2_install +%endif + +%if %{with python3} +%py3_install +%endif + +%if %{with python2} +%files -n python2-%{srcname} +%doc README.rst +%license LICENSE +%{python2_sitelib}/requests_ftp/ +%{python2_sitelib}/requests_ftp*.egg-info* +%endif + +%if %{with python3} +%files -n python3-%{srcname} +%doc README.rst +%license LICENSE +%{python3_sitelib}/requests_ftp/ +%{python3_sitelib}/requests_ftp*.egg-info* +%endif + +%changelog +* Mon Aug 13 2018 David Shea - 0.3.1-11 +- Fix handling of multi-line FTP responses + Resolves: rhbz#1591065 + +* Tue Apr 24 2018 David Shea - 0.3.1-10 +- Conditionalize the python2 and python3 builds + +* Fri Feb 09 2018 Fedora Release Engineering - 0.3.1-9 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild + +* Sat Jan 27 2018 Iryna Shcherbina - 0.3.1-8 +- Update Python 2 dependency declarations to new packaging standards + (See https://fedoraproject.org/wiki/FinalizingFedoraSwitchtoPython3) + +* Thu Jul 27 2017 Fedora Release Engineering - 0.3.1-7 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild + +* Sat Feb 11 2017 Fedora Release Engineering - 0.3.1-6 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild + +* Tue Dec 13 2016 Stratakis Charalampos - 0.3.1-5 +- Rebuild for Python 3.6 + +* Tue Jul 19 2016 Fedora Release Engineering - 0.3.1-4 +- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages + +* Thu Feb 04 2016 Fedora Release Engineering - 0.3.1-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_24_Mass_Rebuild + +* Tue Nov 03 2015 Robert Kuska - 0.3.1-2 +- Rebuilt for Python3.5 rebuild + +* Mon Sep 14 2015 David Shea - 0.3.1-1 +- Update to requests-ftp-0.3.1, which fixes the LIST command +- Switch to the new python packaging guidelines, which renames python-requests-ftp to python2-requests-ftp + +* Thu Jun 18 2015 Fedora Release Engineering - 0.3.0-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_23_Mass_Rebuild + +* Fri Apr 10 2015 David Shea - 0.3.0-1 +- New upstream version 0.3.0 +- Adds proxy support and improves compatibility with HTTP requests + +* Thu Mar 12 2015 David Shea - 0.2.0-1 +- Initial package