prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Broken vendoring in socks contrib module
  Awkwardly, the SOCKS contrib module doesn't work properly when vendored because it tries to do an absolute import. We should probably rewrite it to use relative imports.
  
  My bad.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `urllib3/contrib/socks.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 """
  3 SOCKS support for urllib3
  4 ~~~~~~~~~~~~~~~~~~~~~~~~~
  5 
  6 This contrib module contains provisional support for SOCKS proxies from within
  7 urllib3. This module supports SOCKS4 (specifically the SOCKS4A variant) and
  8 SOCKS5. To enable its functionality, either install PySocks or install this
  9 module with the ``socks`` extra.
  10 
  11 Known Limitations:
  12 
  13 - Currently PySocks does not support contacting remote websites via literal
  14   IPv6 addresses. Any such connection attempt will fail.
  15 - Currently PySocks does not support IPv6 connections to the SOCKS proxy. Any
  16   such connection attempt will fail.
  17 """
  18 from __future__ import absolute_import
  19 
  20 try:
  21     import socks
  22 except ImportError:
  23     import warnings
  24     from urllib3.exceptions import DependencyWarning
  25 
  26     warnings.warn((
  27         'SOCKS support in urllib3 requires the installation of optional '
  28         'dependencies: specifically, PySocks.  For more information, see '
  29         'https://urllib3.readthedocs.org/en/latest/contrib.html#socks-proxies'
  30         ),
  31         DependencyWarning
  32     )
  33     raise
  34 
  35 from socket import error as SocketError, timeout as SocketTimeout
  36 
  37 from urllib3.connection import (
  38     HTTPConnection, HTTPSConnection
  39 )
  40 from urllib3.connectionpool import (
  41     HTTPConnectionPool, HTTPSConnectionPool
  42 )
  43 from urllib3.exceptions import ConnectTimeoutError, NewConnectionError
  44 from urllib3.poolmanager import PoolManager
  45 from urllib3.util.url import parse_url
  46 
  47 try:
  48     import ssl
  49 except ImportError:
  50     ssl = None
  51 
  52 
  53 class SOCKSConnection(HTTPConnection):
  54     """
  55     A plain-text HTTP connection that connects via a SOCKS proxy.
  56     """
  57     def __init__(self, *args, **kwargs):
  58         self._socks_options = kwargs.pop('_socks_options')
  59         super(SOCKSConnection, self).__init__(*args, **kwargs)
  60 
  61     def _new_conn(self):
  62         """
  63         Establish a new connection via the SOCKS proxy.
  64         """
  65         extra_kw = {}
  66         if self.source_address:
  67             extra_kw['source_address'] = self.source_address
  68 
  69         if self.socket_options:
  70             extra_kw['socket_options'] = self.socket_options
  71 
  72         try:
  73             conn = socks.create_connection(
  74                 (self.host, self.port),
  75                 proxy_type=self._socks_options['socks_version'],
  76                 proxy_addr=self._socks_options['proxy_host'],
  77                 proxy_port=self._socks_options['proxy_port'],
  78                 proxy_username=self._socks_options['username'],
  79                 proxy_password=self._socks_options['password'],
  80                 timeout=self.timeout,
  81                 **extra_kw
  82             )
  83 
  84         except SocketTimeout as e:
  85             raise ConnectTimeoutError(
  86                 self, "Connection to %s timed out. (connect timeout=%s)" %
  87                 (self.host, self.timeout))
  88 
  89         except socks.ProxyError as e:
  90             # This is fragile as hell, but it seems to be the only way to raise
  91             # useful errors here.
  92             if e.socket_err:
  93                 error = e.socket_err
  94                 if isinstance(error, SocketTimeout):
  95                     raise ConnectTimeoutError(
  96                         self,
  97                         "Connection to %s timed out. (connect timeout=%s)" %
  98                         (self.host, self.timeout)
  99                     )
  100                 else:
  101                     raise NewConnectionError(
  102                         self,
  103                         "Failed to establish a new connection: %s" % error
  104                     )
  105             else:
  106                 raise NewConnectionError(
  107                     self,
  108                     "Failed to establish a new connection: %s" % e
  109                 )
  110 
  111         except SocketError as e:  # Defensive: PySocks should catch all these.
  112             raise NewConnectionError(
  113                 self, "Failed to establish a new connection: %s" % e)
  114 
  115         return conn
  116 
  117 
  118 # We don't need to duplicate the Verified/Unverified distinction from
  119 # urllib3/connection.py here because the HTTPSConnection will already have been
  120 # correctly set to either the Verified or Unverified form by that module. This
  121 # means the SOCKSHTTPSConnection will automatically be the correct type.
  122 class SOCKSHTTPSConnection(SOCKSConnection, HTTPSConnection):
  123     pass
  124 
  125 
  126 class SOCKSHTTPConnectionPool(HTTPConnectionPool):
  127     ConnectionCls = SOCKSConnection
  128 
  129 
  130 class SOCKSHTTPSConnectionPool(HTTPSConnectionPool):
  131     ConnectionCls = SOCKSHTTPSConnection
  132 
  133 
  134 class SOCKSProxyManager(PoolManager):
  135     """
  136     A version of the urllib3 ProxyManager that routes connections via the
  137     defined SOCKS proxy.
  138     """
  139     pool_classes_by_scheme = {
  140         'http': SOCKSHTTPConnectionPool,
  141         'https': SOCKSHTTPSConnectionPool,
  142     }
  143 
  144     def __init__(self, proxy_url, username=None, password=None,
  145                  num_pools=10, headers=None, **connection_pool_kw):
  146         parsed = parse_url(proxy_url)
  147 
  148         if parsed.scheme == 'socks5':
  149             socks_version = socks.PROXY_TYPE_SOCKS5
  150         elif parsed.scheme == 'socks4':
  151             socks_version = socks.PROXY_TYPE_SOCKS4
  152         else:
  153             raise ValueError(
  154                 "Unable to determine SOCKS version from %s" % proxy_url
  155             )
  156 
  157         self.proxy_url = proxy_url
  158 
  159         socks_options = {
  160             'socks_version': socks_version,
  161             'proxy_host': parsed.host,
  162             'proxy_port': parsed.port,
  163             'username': username,
  164             'password': password,
  165         }
  166         connection_pool_kw['_socks_options'] = socks_options
  167 
  168         super(SOCKSProxyManager, self).__init__(
  169             num_pools, headers, **connection_pool_kw
  170         )
  171 
  172         self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme
  173
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/urllib3/contrib/socks.py b/urllib3/contrib/socks.py
  --- a/urllib3/contrib/socks.py
  +++ b/urllib3/contrib/socks.py
  @@ -21,7 +21,7 @@
       import socks
   except ImportError:
       import warnings
  -    from urllib3.exceptions import DependencyWarning
  +    from ..exceptions import DependencyWarning
   
       warnings.warn((
           'SOCKS support in urllib3 requires the installation of optional '
  @@ -34,15 +34,15 @@
   
   from socket import error as SocketError, timeout as SocketTimeout
   
  -from urllib3.connection import (
  +from ..connection import (
       HTTPConnection, HTTPSConnection
   )
  -from urllib3.connectionpool import (
  +from ..connectionpool import (
       HTTPConnectionPool, HTTPSConnectionPool
   )
  -from urllib3.exceptions import ConnectTimeoutError, NewConnectionError
  -from urllib3.poolmanager import PoolManager
  -from urllib3.util.url import parse_url
  +from ..exceptions import ConnectTimeoutError, NewConnectionError
  +from ..poolmanager import PoolManager
  +from ..util.url import parse_url
   
   try:
       import ssl
  
verification_info: {"golden_diff": "diff --git a/urllib3/contrib/socks.py b/urllib3/contrib/socks.py\n--- a/urllib3/contrib/socks.py\n+++ b/urllib3/contrib/socks.py\n@@ -21,7 +21,7 @@\n     import socks\n except ImportError:\n     import warnings\n-    from urllib3.exceptions import DependencyWarning\n+    from ..exceptions import DependencyWarning\n \n     warnings.warn((\n         'SOCKS support in urllib3 requires the installation of optional '\n@@ -34,15 +34,15 @@\n \n from socket import error as SocketError, timeout as SocketTimeout\n \n-from urllib3.connection import (\n+from ..connection import (\n     HTTPConnection, HTTPSConnection\n )\n-from urllib3.connectionpool import (\n+from ..connectionpool import (\n     HTTPConnectionPool, HTTPSConnectionPool\n )\n-from urllib3.exceptions import ConnectTimeoutError, NewConnectionError\n-from urllib3.poolmanager import PoolManager\n-from urllib3.util.url import parse_url\n+from ..exceptions import ConnectTimeoutError, NewConnectionError\n+from ..poolmanager import PoolManager\n+from ..util.url import parse_url\n \n try:\n     import ssl\n", "issue": "Broken vendoring in socks contrib module\nAwkwardly, the SOCKS contrib module doesn't work properly when vendored because it tries to do an absolute import. We should probably rewrite it to use relative imports.\n\nMy bad.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nSOCKS support for urllib3\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis contrib module contains provisional support for SOCKS proxies from within\nurllib3. This module supports SOCKS4 (specifically the SOCKS4A variant) and\nSOCKS5. To enable its functionality, either install PySocks or install this\nmodule with the ``socks`` extra.\n\nKnown Limitations:\n\n- Currently PySocks does not support contacting remote websites via literal\n  IPv6 addresses. Any such connection attempt will fail.\n- Currently PySocks does not support IPv6 connections to the SOCKS proxy. Any\n  such connection attempt will fail.\n\"\"\"\nfrom __future__ import absolute_import\n\ntry:\n    import socks\nexcept ImportError:\n    import warnings\n    from urllib3.exceptions import DependencyWarning\n\n    warnings.warn((\n        'SOCKS support in urllib3 requires the installation of optional '\n        'dependencies: specifically, PySocks.  For more information, see '\n        'https://urllib3.readthedocs.org/en/latest/contrib.html#socks-proxies'\n        ),\n        DependencyWarning\n    )\n    raise\n\nfrom socket import error as SocketError, timeout as SocketTimeout\n\nfrom urllib3.connection import (\n    HTTPConnection, HTTPSConnection\n)\nfrom urllib3.connectionpool import (\n    HTTPConnectionPool, HTTPSConnectionPool\n)\nfrom urllib3.exceptions import ConnectTimeoutError, NewConnectionError\nfrom urllib3.poolmanager import PoolManager\nfrom urllib3.util.url import parse_url\n\ntry:\n    import ssl\nexcept ImportError:\n    ssl = None\n\n\nclass SOCKSConnection(HTTPConnection):\n    \"\"\"\n    A plain-text HTTP connection that connects via a SOCKS proxy.\n    \"\"\"\n    def __init__(self, *args, **kwargs):\n        self._socks_options = kwargs.pop('_socks_options')\n        super(SOCKSConnection, self).__init__(*args, **kwargs)\n\n    def _new_conn(self):\n        \"\"\"\n        Establish a new connection via the SOCKS proxy.\n        \"\"\"\n        extra_kw = {}\n        if self.source_address:\n            extra_kw['source_address'] = self.source_address\n\n        if self.socket_options:\n            extra_kw['socket_options'] = self.socket_options\n\n        try:\n            conn = socks.create_connection(\n                (self.host, self.port),\n                proxy_type=self._socks_options['socks_version'],\n                proxy_addr=self._socks_options['proxy_host'],\n                proxy_port=self._socks_options['proxy_port'],\n                proxy_username=self._socks_options['username'],\n                proxy_password=self._socks_options['password'],\n                timeout=self.timeout,\n                **extra_kw\n            )\n\n        except SocketTimeout as e:\n            raise ConnectTimeoutError(\n                self, \"Connection to %s timed out. (connect timeout=%s)\" %\n                (self.host, self.timeout))\n\n        except socks.ProxyError as e:\n            # This is fragile as hell, but it seems to be the only way to raise\n            # useful errors here.\n            if e.socket_err:\n                error = e.socket_err\n                if isinstance(error, SocketTimeout):\n                    raise ConnectTimeoutError(\n                        self,\n                        \"Connection to %s timed out. (connect timeout=%s)\" %\n                        (self.host, self.timeout)\n                    )\n                else:\n                    raise NewConnectionError(\n                        self,\n                        \"Failed to establish a new connection: %s\" % error\n                    )\n            else:\n                raise NewConnectionError(\n                    self,\n                    \"Failed to establish a new connection: %s\" % e\n                )\n\n        except SocketError as e:  # Defensive: PySocks should catch all these.\n            raise NewConnectionError(\n                self, \"Failed to establish a new connection: %s\" % e)\n\n        return conn\n\n\n# We don't need to duplicate the Verified/Unverified distinction from\n# urllib3/connection.py here because the HTTPSConnection will already have been\n# correctly set to either the Verified or Unverified form by that module. This\n# means the SOCKSHTTPSConnection will automatically be the correct type.\nclass SOCKSHTTPSConnection(SOCKSConnection, HTTPSConnection):\n    pass\n\n\nclass SOCKSHTTPConnectionPool(HTTPConnectionPool):\n    ConnectionCls = SOCKSConnection\n\n\nclass SOCKSHTTPSConnectionPool(HTTPSConnectionPool):\n    ConnectionCls = SOCKSHTTPSConnection\n\n\nclass SOCKSProxyManager(PoolManager):\n    \"\"\"\n    A version of the urllib3 ProxyManager that routes connections via the\n    defined SOCKS proxy.\n    \"\"\"\n    pool_classes_by_scheme = {\n        'http': SOCKSHTTPConnectionPool,\n        'https': SOCKSHTTPSConnectionPool,\n    }\n\n    def __init__(self, proxy_url, username=None, password=None,\n                 num_pools=10, headers=None, **connection_pool_kw):\n        parsed = parse_url(proxy_url)\n\n        if parsed.scheme == 'socks5':\n            socks_version = socks.PROXY_TYPE_SOCKS5\n        elif parsed.scheme == 'socks4':\n            socks_version = socks.PROXY_TYPE_SOCKS4\n        else:\n            raise ValueError(\n                \"Unable to determine SOCKS version from %s\" % proxy_url\n            )\n\n        self.proxy_url = proxy_url\n\n        socks_options = {\n            'socks_version': socks_version,\n            'proxy_host': parsed.host,\n            'proxy_port': parsed.port,\n            'username': username,\n            'password': password,\n        }\n        connection_pool_kw['_socks_options'] = socks_options\n\n        super(SOCKSProxyManager, self).__init__(\n            num_pools, headers, **connection_pool_kw\n        )\n\n        self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme\n", "path": "urllib3/contrib/socks.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\nSOCKS support for urllib3\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis contrib module contains provisional support for SOCKS proxies from within\nurllib3. This module supports SOCKS4 (specifically the SOCKS4A variant) and\nSOCKS5. To enable its functionality, either install PySocks or install this\nmodule with the ``socks`` extra.\n\nKnown Limitations:\n\n- Currently PySocks does not support contacting remote websites via literal\n  IPv6 addresses. Any such connection attempt will fail.\n- Currently PySocks does not support IPv6 connections to the SOCKS proxy. Any\n  such connection attempt will fail.\n\"\"\"\nfrom __future__ import absolute_import\n\ntry:\n    import socks\nexcept ImportError:\n    import warnings\n    from ..exceptions import DependencyWarning\n\n    warnings.warn((\n        'SOCKS support in urllib3 requires the installation of optional '\n        'dependencies: specifically, PySocks.  For more information, see '\n        'https://urllib3.readthedocs.org/en/latest/contrib.html#socks-proxies'\n        ),\n        DependencyWarning\n    )\n    raise\n\nfrom socket import error as SocketError, timeout as SocketTimeout\n\nfrom ..connection import (\n    HTTPConnection, HTTPSConnection\n)\nfrom ..connectionpool import (\n    HTTPConnectionPool, HTTPSConnectionPool\n)\nfrom ..exceptions import ConnectTimeoutError, NewConnectionError\nfrom ..poolmanager import PoolManager\nfrom ..util.url import parse_url\n\ntry:\n    import ssl\nexcept ImportError:\n    ssl = None\n\n\nclass SOCKSConnection(HTTPConnection):\n    \"\"\"\n    A plain-text HTTP connection that connects via a SOCKS proxy.\n    \"\"\"\n    def __init__(self, *args, **kwargs):\n        self._socks_options = kwargs.pop('_socks_options')\n        super(SOCKSConnection, self).__init__(*args, **kwargs)\n\n    def _new_conn(self):\n        \"\"\"\n        Establish a new connection via the SOCKS proxy.\n        \"\"\"\n        extra_kw = {}\n        if self.source_address:\n            extra_kw['source_address'] = self.source_address\n\n        if self.socket_options:\n            extra_kw['socket_options'] = self.socket_options\n\n        try:\n            conn = socks.create_connection(\n                (self.host, self.port),\n                proxy_type=self._socks_options['socks_version'],\n                proxy_addr=self._socks_options['proxy_host'],\n                proxy_port=self._socks_options['proxy_port'],\n                proxy_username=self._socks_options['username'],\n                proxy_password=self._socks_options['password'],\n                timeout=self.timeout,\n                **extra_kw\n            )\n\n        except SocketTimeout as e:\n            raise ConnectTimeoutError(\n                self, \"Connection to %s timed out. (connect timeout=%s)\" %\n                (self.host, self.timeout))\n\n        except socks.ProxyError as e:\n            # This is fragile as hell, but it seems to be the only way to raise\n            # useful errors here.\n            if e.socket_err:\n                error = e.socket_err\n                if isinstance(error, SocketTimeout):\n                    raise ConnectTimeoutError(\n                        self,\n                        \"Connection to %s timed out. (connect timeout=%s)\" %\n                        (self.host, self.timeout)\n                    )\n                else:\n                    raise NewConnectionError(\n                        self,\n                        \"Failed to establish a new connection: %s\" % error\n                    )\n            else:\n                raise NewConnectionError(\n                    self,\n                    \"Failed to establish a new connection: %s\" % e\n                )\n\n        except SocketError as e:  # Defensive: PySocks should catch all these.\n            raise NewConnectionError(\n                self, \"Failed to establish a new connection: %s\" % e)\n\n        return conn\n\n\n# We don't need to duplicate the Verified/Unverified distinction from\n# urllib3/connection.py here because the HTTPSConnection will already have been\n# correctly set to either the Verified or Unverified form by that module. This\n# means the SOCKSHTTPSConnection will automatically be the correct type.\nclass SOCKSHTTPSConnection(SOCKSConnection, HTTPSConnection):\n    pass\n\n\nclass SOCKSHTTPConnectionPool(HTTPConnectionPool):\n    ConnectionCls = SOCKSConnection\n\n\nclass SOCKSHTTPSConnectionPool(HTTPSConnectionPool):\n    ConnectionCls = SOCKSHTTPSConnection\n\n\nclass SOCKSProxyManager(PoolManager):\n    \"\"\"\n    A version of the urllib3 ProxyManager that routes connections via the\n    defined SOCKS proxy.\n    \"\"\"\n    pool_classes_by_scheme = {\n        'http': SOCKSHTTPConnectionPool,\n        'https': SOCKSHTTPSConnectionPool,\n    }\n\n    def __init__(self, proxy_url, username=None, password=None,\n                 num_pools=10, headers=None, **connection_pool_kw):\n        parsed = parse_url(proxy_url)\n\n        if parsed.scheme == 'socks5':\n            socks_version = socks.PROXY_TYPE_SOCKS5\n        elif parsed.scheme == 'socks4':\n            socks_version = socks.PROXY_TYPE_SOCKS4\n        else:\n            raise ValueError(\n                \"Unable to determine SOCKS version from %s\" % proxy_url\n            )\n\n        self.proxy_url = proxy_url\n\n        socks_options = {\n            'socks_version': socks_version,\n            'proxy_host': parsed.host,\n            'proxy_port': parsed.port,\n            'username': username,\n            'password': password,\n        }\n        connection_pool_kw['_socks_options'] = socks_options\n\n        super(SOCKSProxyManager, self).__init__(\n            num_pools, headers, **connection_pool_kw\n        )\n\n        self.pool_classes_by_scheme = SOCKSProxyManager.pool_classes_by_scheme\n", "path": "urllib3/contrib/socks.py"}]}