summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Hrázký <lhrazky@redhat.com>2020-01-21 14:11:54 +0100
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>2020-01-27 21:55:16 -0500
commitd357aebb37d824808cb1279a54a5b14f80060a64 (patch)
treea8a1a43d7999f6fbcf565a783b93e0843180a77e
parent06f2f52adb56602a7fa4a162e2702fa5a1cc75f0 (diff)
downloadurlgrabber-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.py10
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)