python-requests-ftp/PR28-03-fix-warning-in-interpreting-ftp-status-codes-minor-d.patch

49 lines
2.6 KiB
Diff
Raw Permalink Normal View History

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 <SP>, 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