diff options
author | Lukáš Hrázký <lhrazky@redhat.com> | 2020-01-21 14:11:54 +0100 |
---|---|---|
committer | Neal Gompa (ニール・ゴンパ) <ngompa13@gmail.com> | 2020-01-27 21:55:16 -0500 |
commit | d357aebb37d824808cb1279a54a5b14f80060a64 (patch) | |
tree | a8a1a43d7999f6fbcf565a783b93e0843180a77e | |
parent | 06f2f52adb56602a7fa4a162e2702fa5a1cc75f0 (diff) | |
download | urlgrabber-d357aebb37d824808cb1279a54a5b14f80060a64.tar.gz |
Decode bytes to a string for ftplib.parse150() (RhBug:1734527)
ftplib.parse150() expects a string, we need to decode the bytes before
passing them to the function in Python 3.
https://bugzilla.redhat.com/show_bug.cgi?id=1734527
-rw-r--r-- | urlgrabber/grabber.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py index b72d089..d443548 100644 --- a/urlgrabber/grabber.py +++ b/urlgrabber/grabber.py @@ -720,6 +720,14 @@ def exception2msg(e): # always use byte strings return text_type(e).encode('utf8') +def bytes_to_string(b): + if sys.version_info < (3,): + # in python 2 strings are bytes + return b + else: + # python 3, will ignore any non-ascii characters if the encoding isn't utf8 + return b.decode('utf8', 'ignore') + ######################################################################## # END UTILITY FUNCTIONS ######################################################################## @@ -1425,7 +1433,7 @@ class PyCurlFileObject(object): if len(s) >= 14: s = None # ignore MDTM responses elif buf.startswith(b'150 '): - s = parse150(buf) + s = parse150(bytes_to_string(buf)) if s: self.size = int(s) |