prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Check resource error in container network API
  ```
  docker python client v2.4.2
  python v2.7.12
  docker v17.03.1-ce
  Ubuntu 16.04
  ```
  
  PR #1649 updated the `check_resource` decorator to handle different resource names.  Container network API functions  `connect_container_to_network()` and `disconnect_container_from_network()` check 'image' as resource ID and not 'container'.
  
  Reproduce using the following snippet:
  ```python
  import docker
  
  cli = docker.APIClient(base_url='unix:///var/run/docker.sock')
  cli.pull(repository='ubuntu', tag='latest')
  
  name = 'my_ubuntu'
  container = cli.create_container(image='ubuntu:latest', name=name)
  cli.connect_container_to_network(container=name, net_id='bridge')
  ```
  
  This causes:
  ```
  Traceback (most recent call last):
    File "test.py", line 8, in <module>
      cli.connect_container_to_network(container=name, net_id='bridge')
    File "/home/mberry/scratch/virtualenv/docker_py/local/lib/python2.7/site-packages/docker/utils/decorators.py", line 17, in wrapped
      'Resource ID was not provided'
  docker.errors.NullResource: Resource ID was not provided
  ```
  client.networks.create check_duplicates docs not reflective of behavior
  Docs say it does, but it's actually set to `None`.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `docker/version.py`
  Content:
  ```
  1 version = "2.6.0"
  2 version_info = tuple([int(d) for d in version.split("-")[0].split(".")])
  3
  ```
  
  Path: `docker/transport/unixconn.py`
  Content:
  ```
  1 import six
  2 import requests.adapters
  3 import socket
  4 
  5 from .. import constants
  6 
  7 if six.PY3:
  8     import http.client as httplib
  9 else:
  10     import httplib
  11 
  12 try:
  13     import requests.packages.urllib3 as urllib3
  14 except ImportError:
  15     import urllib3
  16 
  17 
  18 RecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer
  19 
  20 
  21 class UnixHTTPResponse(httplib.HTTPResponse, object):
  22     def __init__(self, sock, *args, **kwargs):
  23         disable_buffering = kwargs.pop('disable_buffering', False)
  24         super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)
  25         if disable_buffering is True:
  26             # We must first create a new pointer then close the old one
  27             # to avoid closing the underlying socket.
  28             new_fp = sock.makefile('rb', 0)
  29             self.fp.close()
  30             self.fp = new_fp
  31 
  32 
  33 class UnixHTTPConnection(httplib.HTTPConnection, object):
  34 
  35     def __init__(self, base_url, unix_socket, timeout=60):
  36         super(UnixHTTPConnection, self).__init__(
  37             'localhost', timeout=timeout
  38         )
  39         self.base_url = base_url
  40         self.unix_socket = unix_socket
  41         self.timeout = timeout
  42         self.disable_buffering = False
  43 
  44     def connect(self):
  45         sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  46         sock.settimeout(self.timeout)
  47         sock.connect(self.unix_socket)
  48         self.sock = sock
  49 
  50     def putheader(self, header, *values):
  51         super(UnixHTTPConnection, self).putheader(header, *values)
  52         if header == 'Connection' and 'Upgrade' in values:
  53             self.disable_buffering = True
  54 
  55     def response_class(self, sock, *args, **kwargs):
  56         if self.disable_buffering:
  57             kwargs['disable_buffering'] = True
  58 
  59         return UnixHTTPResponse(sock, *args, **kwargs)
  60 
  61 
  62 class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
  63     def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
  64         super(UnixHTTPConnectionPool, self).__init__(
  65             'localhost', timeout=timeout, maxsize=maxsize
  66         )
  67         self.base_url = base_url
  68         self.socket_path = socket_path
  69         self.timeout = timeout
  70 
  71     def _new_conn(self):
  72         return UnixHTTPConnection(
  73             self.base_url, self.socket_path, self.timeout
  74         )
  75 
  76 
  77 class UnixAdapter(requests.adapters.HTTPAdapter):
  78 
  79     __attrs__ = requests.adapters.HTTPAdapter.__attrs__ + ['pools',
  80                                                            'socket_path',
  81                                                            'timeout']
  82 
  83     def __init__(self, socket_url, timeout=60,
  84                  pool_connections=constants.DEFAULT_NUM_POOLS):
  85         socket_path = socket_url.replace('http+unix://', '')
  86         if not socket_path.startswith('/'):
  87             socket_path = '/' + socket_path
  88         self.socket_path = socket_path
  89         self.timeout = timeout
  90         self.pools = RecentlyUsedContainer(
  91             pool_connections, dispose_func=lambda p: p.close()
  92         )
  93         super(UnixAdapter, self).__init__()
  94 
  95     def get_connection(self, url, proxies=None):
  96         with self.pools.lock:
  97             pool = self.pools.get(url)
  98             if pool:
  99                 return pool
  100 
  101             pool = UnixHTTPConnectionPool(
  102                 url, self.socket_path, self.timeout
  103             )
  104             self.pools[url] = pool
  105 
  106         return pool
  107 
  108     def request_url(self, request, proxies):
  109         # The select_proxy utility in requests errors out when the provided URL
  110         # doesn't have a hostname, like is the case when using a UNIX socket.
  111         # Since proxies are an irrelevant notion in the case of UNIX sockets
  112         # anyway, we simply return the path URL directly.
  113         # See also: https://github.com/docker/docker-py/issues/811
  114         return request.path_url
  115 
  116     def close(self):
  117         self.pools.clear()
  118
  ```
  --- 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/docker/transport/unixconn.py b/docker/transport/unixconn.py
  --- a/docker/transport/unixconn.py
  +++ b/docker/transport/unixconn.py
  @@ -21,13 +21,12 @@
   class UnixHTTPResponse(httplib.HTTPResponse, object):
       def __init__(self, sock, *args, **kwargs):
           disable_buffering = kwargs.pop('disable_buffering', False)
  +        if six.PY2:
  +            # FIXME: We may need to disable buffering on Py3 as well,
  +            # but there's no clear way to do it at the moment. See:
  +            # https://github.com/docker/docker-py/issues/1799
  +            kwargs['buffering'] = not disable_buffering
           super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)
  -        if disable_buffering is True:
  -            # We must first create a new pointer then close the old one
  -            # to avoid closing the underlying socket.
  -            new_fp = sock.makefile('rb', 0)
  -            self.fp.close()
  -            self.fp = new_fp
   
   
   class UnixHTTPConnection(httplib.HTTPConnection, object):
  diff --git a/docker/version.py b/docker/version.py
  --- a/docker/version.py
  +++ b/docker/version.py
  @@ -1,2 +1,2 @@
  -version = "2.6.0"
  +version = "2.6.1"
   version_info = tuple([int(d) for d in version.split("-")[0].split(".")])
  
verification_info: {"golden_diff": "diff --git a/docker/transport/unixconn.py b/docker/transport/unixconn.py\n--- a/docker/transport/unixconn.py\n+++ b/docker/transport/unixconn.py\n@@ -21,13 +21,12 @@\n class UnixHTTPResponse(httplib.HTTPResponse, object):\n     def __init__(self, sock, *args, **kwargs):\n         disable_buffering = kwargs.pop('disable_buffering', False)\n+        if six.PY2:\n+            # FIXME: We may need to disable buffering on Py3 as well,\n+            # but there's no clear way to do it at the moment. See:\n+            # https://github.com/docker/docker-py/issues/1799\n+            kwargs['buffering'] = not disable_buffering\n         super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)\n-        if disable_buffering is True:\n-            # We must first create a new pointer then close the old one\n-            # to avoid closing the underlying socket.\n-            new_fp = sock.makefile('rb', 0)\n-            self.fp.close()\n-            self.fp = new_fp\n \n \n class UnixHTTPConnection(httplib.HTTPConnection, object):\ndiff --git a/docker/version.py b/docker/version.py\n--- a/docker/version.py\n+++ b/docker/version.py\n@@ -1,2 +1,2 @@\n-version = \"2.6.0\"\n+version = \"2.6.1\"\n version_info = tuple([int(d) for d in version.split(\"-\")[0].split(\".\")])\n", "issue": "Check resource error in container network API\n```\r\ndocker python client v2.4.2\r\npython v2.7.12\r\ndocker v17.03.1-ce\r\nUbuntu 16.04\r\n```\r\n\r\nPR #1649 updated the `check_resource` decorator to handle different resource names.  Container network API functions  `connect_container_to_network()` and `disconnect_container_from_network()` check 'image' as resource ID and not 'container'.\r\n\r\nReproduce using the following snippet:\r\n```python\r\nimport docker\r\n\r\ncli = docker.APIClient(base_url='unix:///var/run/docker.sock')\r\ncli.pull(repository='ubuntu', tag='latest')\r\n\r\nname = 'my_ubuntu'\r\ncontainer = cli.create_container(image='ubuntu:latest', name=name)\r\ncli.connect_container_to_network(container=name, net_id='bridge')\r\n```\r\n\r\nThis causes:\r\n```\r\nTraceback (most recent call last):\r\n  File \"test.py\", line 8, in <module>\r\n    cli.connect_container_to_network(container=name, net_id='bridge')\r\n  File \"/home/mberry/scratch/virtualenv/docker_py/local/lib/python2.7/site-packages/docker/utils/decorators.py\", line 17, in wrapped\r\n    'Resource ID was not provided'\r\ndocker.errors.NullResource: Resource ID was not provided\r\n```\nclient.networks.create check_duplicates docs not reflective of behavior\nDocs say it does, but it's actually set to `None`.\n", "before_files": [{"content": "version = \"2.6.0\"\nversion_info = tuple([int(d) for d in version.split(\"-\")[0].split(\".\")])\n", "path": "docker/version.py"}, {"content": "import six\nimport requests.adapters\nimport socket\n\nfrom .. import constants\n\nif six.PY3:\n    import http.client as httplib\nelse:\n    import httplib\n\ntry:\n    import requests.packages.urllib3 as urllib3\nexcept ImportError:\n    import urllib3\n\n\nRecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer\n\n\nclass UnixHTTPResponse(httplib.HTTPResponse, object):\n    def __init__(self, sock, *args, **kwargs):\n        disable_buffering = kwargs.pop('disable_buffering', False)\n        super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)\n        if disable_buffering is True:\n            # We must first create a new pointer then close the old one\n            # to avoid closing the underlying socket.\n            new_fp = sock.makefile('rb', 0)\n            self.fp.close()\n            self.fp = new_fp\n\n\nclass UnixHTTPConnection(httplib.HTTPConnection, object):\n\n    def __init__(self, base_url, unix_socket, timeout=60):\n        super(UnixHTTPConnection, self).__init__(\n            'localhost', timeout=timeout\n        )\n        self.base_url = base_url\n        self.unix_socket = unix_socket\n        self.timeout = timeout\n        self.disable_buffering = False\n\n    def connect(self):\n        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n        sock.settimeout(self.timeout)\n        sock.connect(self.unix_socket)\n        self.sock = sock\n\n    def putheader(self, header, *values):\n        super(UnixHTTPConnection, self).putheader(header, *values)\n        if header == 'Connection' and 'Upgrade' in values:\n            self.disable_buffering = True\n\n    def response_class(self, sock, *args, **kwargs):\n        if self.disable_buffering:\n            kwargs['disable_buffering'] = True\n\n        return UnixHTTPResponse(sock, *args, **kwargs)\n\n\nclass UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):\n    def __init__(self, base_url, socket_path, timeout=60, maxsize=10):\n        super(UnixHTTPConnectionPool, self).__init__(\n            'localhost', timeout=timeout, maxsize=maxsize\n        )\n        self.base_url = base_url\n        self.socket_path = socket_path\n        self.timeout = timeout\n\n    def _new_conn(self):\n        return UnixHTTPConnection(\n            self.base_url, self.socket_path, self.timeout\n        )\n\n\nclass UnixAdapter(requests.adapters.HTTPAdapter):\n\n    __attrs__ = requests.adapters.HTTPAdapter.__attrs__ + ['pools',\n                                                           'socket_path',\n                                                           'timeout']\n\n    def __init__(self, socket_url, timeout=60,\n                 pool_connections=constants.DEFAULT_NUM_POOLS):\n        socket_path = socket_url.replace('http+unix://', '')\n        if not socket_path.startswith('/'):\n            socket_path = '/' + socket_path\n        self.socket_path = socket_path\n        self.timeout = timeout\n        self.pools = RecentlyUsedContainer(\n            pool_connections, dispose_func=lambda p: p.close()\n        )\n        super(UnixAdapter, self).__init__()\n\n    def get_connection(self, url, proxies=None):\n        with self.pools.lock:\n            pool = self.pools.get(url)\n            if pool:\n                return pool\n\n            pool = UnixHTTPConnectionPool(\n                url, self.socket_path, self.timeout\n            )\n            self.pools[url] = pool\n\n        return pool\n\n    def request_url(self, request, proxies):\n        # The select_proxy utility in requests errors out when the provided URL\n        # doesn't have a hostname, like is the case when using a UNIX socket.\n        # Since proxies are an irrelevant notion in the case of UNIX sockets\n        # anyway, we simply return the path URL directly.\n        # See also: https://github.com/docker/docker-py/issues/811\n        return request.path_url\n\n    def close(self):\n        self.pools.clear()\n", "path": "docker/transport/unixconn.py"}], "after_files": [{"content": "version = \"2.6.1\"\nversion_info = tuple([int(d) for d in version.split(\"-\")[0].split(\".\")])\n", "path": "docker/version.py"}, {"content": "import six\nimport requests.adapters\nimport socket\n\nfrom .. import constants\n\nif six.PY3:\n    import http.client as httplib\nelse:\n    import httplib\n\ntry:\n    import requests.packages.urllib3 as urllib3\nexcept ImportError:\n    import urllib3\n\n\nRecentlyUsedContainer = urllib3._collections.RecentlyUsedContainer\n\n\nclass UnixHTTPResponse(httplib.HTTPResponse, object):\n    def __init__(self, sock, *args, **kwargs):\n        disable_buffering = kwargs.pop('disable_buffering', False)\n        if six.PY2:\n            # FIXME: We may need to disable buffering on Py3 as well,\n            # but there's no clear way to do it at the moment. See:\n            # https://github.com/docker/docker-py/issues/1799\n            kwargs['buffering'] = not disable_buffering\n        super(UnixHTTPResponse, self).__init__(sock, *args, **kwargs)\n\n\nclass UnixHTTPConnection(httplib.HTTPConnection, object):\n\n    def __init__(self, base_url, unix_socket, timeout=60):\n        super(UnixHTTPConnection, self).__init__(\n            'localhost', timeout=timeout\n        )\n        self.base_url = base_url\n        self.unix_socket = unix_socket\n        self.timeout = timeout\n        self.disable_buffering = False\n\n    def connect(self):\n        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n        sock.settimeout(self.timeout)\n        sock.connect(self.unix_socket)\n        self.sock = sock\n\n    def putheader(self, header, *values):\n        super(UnixHTTPConnection, self).putheader(header, *values)\n        if header == 'Connection' and 'Upgrade' in values:\n            self.disable_buffering = True\n\n    def response_class(self, sock, *args, **kwargs):\n        if self.disable_buffering:\n            kwargs['disable_buffering'] = True\n\n        return UnixHTTPResponse(sock, *args, **kwargs)\n\n\nclass UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):\n    def __init__(self, base_url, socket_path, timeout=60, maxsize=10):\n        super(UnixHTTPConnectionPool, self).__init__(\n            'localhost', timeout=timeout, maxsize=maxsize\n        )\n        self.base_url = base_url\n        self.socket_path = socket_path\n        self.timeout = timeout\n\n    def _new_conn(self):\n        return UnixHTTPConnection(\n            self.base_url, self.socket_path, self.timeout\n        )\n\n\nclass UnixAdapter(requests.adapters.HTTPAdapter):\n\n    __attrs__ = requests.adapters.HTTPAdapter.__attrs__ + ['pools',\n                                                           'socket_path',\n                                                           'timeout']\n\n    def __init__(self, socket_url, timeout=60,\n                 pool_connections=constants.DEFAULT_NUM_POOLS):\n        socket_path = socket_url.replace('http+unix://', '')\n        if not socket_path.startswith('/'):\n            socket_path = '/' + socket_path\n        self.socket_path = socket_path\n        self.timeout = timeout\n        self.pools = RecentlyUsedContainer(\n            pool_connections, dispose_func=lambda p: p.close()\n        )\n        super(UnixAdapter, self).__init__()\n\n    def get_connection(self, url, proxies=None):\n        with self.pools.lock:\n            pool = self.pools.get(url)\n            if pool:\n                return pool\n\n            pool = UnixHTTPConnectionPool(\n                url, self.socket_path, self.timeout\n            )\n            self.pools[url] = pool\n\n        return pool\n\n    def request_url(self, request, proxies):\n        # The select_proxy utility in requests errors out when the provided URL\n        # doesn't have a hostname, like is the case when using a UNIX socket.\n        # Since proxies are an irrelevant notion in the case of UNIX sockets\n        # anyway, we simply return the path URL directly.\n        # See also: https://github.com/docker/docker-py/issues/811\n        return request.path_url\n\n    def close(self):\n        self.pools.clear()\n", "path": "docker/transport/unixconn.py"}]}