From 626d4cf2cd6754457a82e22ebcf747c0b469537d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Fri, 3 Jun 2022 16:42:42 +0100
Subject: [PATCH 1/4] Drop six usage

---
 scripts/urlgrabber-ext-down |  6 ++----
 setup.py                    |  1 -
 test/munittest.py           |  8 +++-----
 test/test_grabber.py        |  5 ++---
 urlgrabber/grabber.py       | 22 ++++++++++------------
 urlgrabber/mirror.py        |  4 +---
 urlgrabber/progress.py      |  6 ++----
 8 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/scripts/urlgrabber-ext-down b/scripts/urlgrabber-ext-down
index 40469a7..acc84f6 100755
--- a/scripts/urlgrabber-ext-down
+++ b/scripts/urlgrabber-ext-down
@@ -19,15 +19,13 @@
 #      Boston, MA  02111-1307  USA
 
 import time, os, errno, sys
-import six
 from urlgrabber.grabber import \
     _readlines, URLGrabberOptions, _loads, \
     PyCurlFileObject, URLGrabError, _to_utf8
 
 def write(fmt, *arg):
     buf = fmt % arg
-    if six.PY3:
-        buf = buf.encode()
+    buf = buf.encode()
     try:
         os.write(1, buf)
     except OSError as e:
@@ -51,7 +49,7 @@ def main():
         lines = _readlines(0)
         if not lines: break
         for line in lines:
-            if not isinstance(line, six.string_types):
+            if not isinstance(line, str):
                 line = line.decode('utf-8')
             cnt += 1
             opts = URLGrabberOptions()
diff --git a/setup.py b/setup.py
index 6f6a6bd..a751d54 100644
--- a/setup.py
+++ b/setup.py
@@ -47,7 +47,6 @@
     include_package_data=True,
     install_requires=[
         "pycurl",
-        "six",
         "setuptools",
     ],
     scripts = ['scripts/urlgrabber'],
diff --git a/test/munittest.py b/test/munittest.py
index 5fdf6f6..5310cfd 100644
--- a/test/munittest.py
+++ b/test/munittest.py
@@ -108,8 +108,6 @@ def testMultiply(self):
 import types
 import unittest
 
-from six import class_types, string_types
-
 try:
     cmp
 except NameError:
@@ -565,7 +563,7 @@ def loadTestsFromModule(self, module):
         tests = []
         for name in dir(module):
             obj = getattr(module, name)
-            if (isinstance(obj, class_types) and
+            if (isinstance(obj, type) and
                 issubclass(obj, TestCase) and
                 not obj in [TestCase, FunctionTestCase]):
                 tests.append(self.loadTestsFromTestCase(obj))
@@ -604,7 +602,7 @@ def loadTestsFromName(self, name, module=None):
         import unittest
         if isinstance(obj, types.ModuleType):
             return self.loadTestsFromModule(obj)
-        elif (isinstance(obj, class_types) and
+        elif (isinstance(obj, type) and
               issubclass(obj, unittest.TestCase)):
             return self.loadTestsFromTestCase(obj)
         elif isinstance(obj, types.UnboundMethodType):
@@ -845,7 +843,7 @@ class TestProgram:
 """
     def __init__(self, module='__main__', defaultTest=None,
                  argv=None, testRunner=None, testLoader=defaultTestLoader):
-        if isinstance(module, string_types):
+        if isinstance(module, str):
             self.module = __import__(module)
             for part in module.split('.')[1:]:
                 self.module = getattr(self.module, part)
diff --git a/test/test_grabber.py b/test/test_grabber.py
index 465e5f5..4c153cd 100644
--- a/test/test_grabber.py
+++ b/test/test_grabber.py
@@ -28,7 +28,6 @@
 import tempfile, random, os
 import socket
 from io import BytesIO
-from six import string_types
 
 if sys.version_info >= (3,):
     # We do an explicit version check here because because python2
@@ -333,7 +332,7 @@ def test_failure_callback_args(self):
         self.assertEqual(self.kwargs, {'bar': 'baz'})
         self.assertTrue(isinstance(self.obj, CallbackObject))
         url = self.obj.url
-        if not isinstance(url, string_types):
+        if not isinstance(url, str):
             url = url.decode('utf8')
         self.assertEqual(url, ref_404)
         self.assertTrue(isinstance(self.obj.exception, URLGrabError))
@@ -413,7 +412,7 @@ def _check_common_args(self):
         self.assertEqual(self.kwargs, {'bar': 'baz'})
         self.assertTrue(isinstance(self.obj, CallbackObject))
         url = self.obj.url
-        if not isinstance(url, string_types):
+        if not isinstance(url, str):
             url = url.decode()
         self.assertEqual(url, short_ref_http)
 
diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 2552091..8f464d0 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -571,8 +571,6 @@
 else:
     from cStringIO import StringIO
 
-from six import text_type, string_types
-
 from .byterange import range_tuple_normalize, range_tuple_to_header, RangeError
 
 try:
@@ -584,13 +582,13 @@
 
 def _bytes_repr(s):
     "A wrapper to avoid the b'' that python3 insists on when printing bytes"
-    if isinstance(s, string_types):
+    if isinstance(s, str):
         return s
     else:
         return repr(s)[2:-1]
 
 def _urlunquote_convert(s):
-    if not isinstance(s, text_type):
+    if not isinstance(s, str):
         s = s.decode('utf8')
     return urlunquote(s)
 
@@ -709,7 +707,7 @@ def _(st):
 def _to_utf8(obj, errors='replace'):
     '''convert 'unicode' to an encoded utf-8 byte string '''
     # stolen from yum.i18n
-    if isinstance(obj, text_type):
+    if isinstance(obj, str):
         obj = obj.encode('utf-8', errors)
     return obj
 
@@ -718,7 +716,7 @@ def exception2msg(e):
         return str(e)
     except UnicodeEncodeError:
         # always use byte strings
-        return text_type(e).encode('utf8')
+        return str(e).encode('utf8')
 
 ########################################################################
 #                 END UTILITY FUNCTIONS
@@ -918,7 +916,7 @@ def quote(self, parts):
         """
         (scheme, host, path, parm, query, frag) = parts
         newpath = urlquote(path, safe='/$')
-        if not isinstance(path, text_type) and isinstance(newpath, text_type):
+        if not isinstance(path, str) and isinstance(newpath, str):
             newpath = newpath.encode('utf8')
         return (scheme, host, newpath, parm, query, frag)
 
@@ -934,7 +932,7 @@ def guess_should_quote(self, parts):
         else       ->  1
         """
         (scheme, host, path, parm, query, frag) = parts
-        if not isinstance(path, text_type):
+        if not isinstance(path, str):
             path = path.decode('utf8')
         if ' ' in path:
             return 1
@@ -1711,7 +1709,7 @@ def _add_headers(self):
     def _build_range(self):
         reget_length = 0
         rt = None
-        if self.opts.reget and isinstance(self.filename, string_types):
+        if self.opts.reget and isinstance(self.filename, str):
             # we have reget turned on and we're dumping to a file
             try:
                 s = os.stat(self.filename)
@@ -1806,7 +1804,7 @@ def _do_grab(self):
         if self._complete:
             return
         _was_filename = False
-        if isinstance(self.filename, string_types) and self.filename:
+        if isinstance(self.filename, str) and self.filename:
             _was_filename = True
             self._prog_reportname = str(self.filename)
             self._prog_basename = os.path.basename(self.filename)
@@ -2075,10 +2073,10 @@ def _dumps(v):
     if v is False: return 'False'
     if isinstance(v, numbers.Number):
         return str(v)
-    if isinstance(v, (str, text_type, bytes)):
+    if isinstance(v, (str, str, bytes)):
         # standarize to str on both py2 to py3
         if sys.version_info < (3,):
-            if isinstance(v, text_type):
+            if isinstance(v, str):
                 v = v.encode('utf8')
         else:
             if isinstance(v, bytes):
diff --git a/urlgrabber/mirror.py b/urlgrabber/mirror.py
index d95863e..3a62fab 100644
--- a/urlgrabber/mirror.py
+++ b/urlgrabber/mirror.py
@@ -105,8 +105,6 @@
 except ImportError:
     import urlparse
 
-from six import string_types
-
 from .grabber import URLGrabError, CallbackObject, DEBUG, _to_utf8
 from .grabber import _run_callback, _do_raise
 from .grabber import exception2msg
@@ -299,7 +297,7 @@ def _process_kwargs(self, kwargs):
     def _parse_mirrors(self, mirrors):
         parsed_mirrors = []
         for m in mirrors:
-            if isinstance(m, string_types):
+            if isinstance(m, str):
                 m = {'mirror': _to_utf8(m)}
             parsed_mirrors.append(m)
         return parsed_mirrors
diff --git a/urlgrabber/progress.py b/urlgrabber/progress.py
index fd18adb..108d08e 100644
--- a/urlgrabber/progress.py
+++ b/urlgrabber/progress.py
@@ -32,8 +32,6 @@
 else:
     import thread
 
-from six import integer_types, string_types
-
 # Code from http://mail.python.org/pipermail/python-list/2000-May/033365.html
 def terminal_width(fd=1):
     """ Get the real terminal width """
@@ -614,7 +612,7 @@ def _do_failure_meter(self, meter, message, now):
         try:
             format = "%-30.30s %6.6s %s"
             fn = meter.text or meter.basename
-            if isinstance(message, string_types):
+            if isinstance(message, str):
                 message = message.splitlines()
             if not message: message = ['']
             out = '%-79s' % (format % (fn, 'FAILED', message[0] or ''))
@@ -786,7 +784,7 @@ def format_number(number, SI=0, space=' '):
         depth  = depth + 1
         number = number / step
 
-    if isinstance(number, integer_types):
+    if isinstance(number, int):
         # it's an int or a long, which means it didn't get divided,
         # which means it's already short enough
         format = '%i%s%s'

From 6b08b5267a91da0e82a6593212234bfae3310f39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Fri, 3 Jun 2022 16:45:32 +0100
Subject: [PATCH 2/4] Fix wrong logic for find_proxy method

---
 urlgrabber/grabber.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 8f464d0..d1c83b8 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -983,16 +983,18 @@ def find_proxy(self, url, scheme):
         Use the proxies dictionary first, then libproxy.
         """
         self.proxy = None
-        if scheme not in ('ftp', 'http', 'https'):
+        if scheme not in (b'ftp', b'http', b'https'):
             return
 
         if self.proxies:
             proxy = self.proxies.get(scheme)
             if proxy is None:
-                if scheme == 'http':
-                    proxy = self.proxies.get('https')
-                elif scheme == 'https':
+                if scheme == b'http':
                     proxy = self.proxies.get('http')
+                elif scheme == b'https':
+                    proxy = self.proxies.get('https')
+                elif scheme == b'ftp':
+                    proxy = self.proxies.get('ftp')
             if proxy == '_none_':
                 proxy = ''
             self.proxy = proxy

From 854cb70afddbe49576b248121ab0e9d9917ce9f8 Mon Sep 17 00:00:00 2001
From: Victor Zhestkov <Victor.Zhestkov@suse.com>
Date: Fri, 29 Jul 2022 16:34:58 +0300
Subject: [PATCH 3/4] Fix the find_proxy bit different way

---
 urlgrabber/grabber.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index d1c83b8..741234e 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -983,20 +983,20 @@ def find_proxy(self, url, scheme):
         Use the proxies dictionary first, then libproxy.
         """
         self.proxy = None
-        if scheme not in (b'ftp', b'http', b'https'):
+        if isinstance(scheme, bytes):
+            scheme = scheme.decode('utf-8')
+        if scheme not in ('ftp', 'http', 'https'):
             return
 
         if self.proxies:
             proxy = self.proxies.get(scheme)
             if proxy is None:
-                if scheme == b'http':
-                    proxy = self.proxies.get('http')
-                elif scheme == b'https':
+                if scheme == 'http':
                     proxy = self.proxies.get('https')
-                elif scheme == b'ftp':
-                    proxy = self.proxies.get('ftp')
+                elif scheme == 'https':
+                    proxy = self.proxies.get('http')
             if proxy == '_none_':
-                proxy = ''
+                proxy = None
             self.proxy = proxy
             return
 

From 63e2c440cd57b74d0cbfe3352c1febf8fa4706c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
 <psuarezhernandez@suse.com>
Date: Mon, 1 Aug 2022 12:29:49 +0100
Subject: [PATCH 4/4] Avoid using system proxy when proxy set to _none_

---
 urlgrabber/grabber.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 741234e..88237cc 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -996,7 +996,7 @@ def find_proxy(self, url, scheme):
                 elif scheme == 'https':
                     proxy = self.proxies.get('http')
             if proxy == '_none_':
-                proxy = None
+                proxy = ''
             self.proxy = proxy
             return
 
