We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
NpipeSocket.settimeout - Blocking and non-blocking are mixed up
`settimeout(None)` puts the socket in non-blocking mode, `settimeout(0)` in blocking mode. Specification indicates it should be the other way around.

--- 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/transport/npipesocket.py`
Content:
```
1 import functools
2 import io
3 
4 import six
5 import win32file
6 import win32pipe
7 
8 cERROR_PIPE_BUSY = 0xe7
9 cSECURITY_SQOS_PRESENT = 0x100000
10 cSECURITY_ANONYMOUS = 0
11 
12 RETRY_WAIT_TIMEOUT = 10000
13 
14 
15 def check_closed(f):
16     @functools.wraps(f)
17     def wrapped(self, *args, **kwargs):
18         if self._closed:
19             raise RuntimeError(
20                 'Can not reuse socket after connection was closed.'
21             )
22         return f(self, *args, **kwargs)
23     return wrapped
24 
25 
26 class NpipeSocket(object):
27     """ Partial implementation of the socket API over windows named pipes.
28         This implementation is only designed to be used as a client socket,
29         and server-specific methods (bind, listen, accept...) are not
30         implemented.
31     """
32 
33     def __init__(self, handle=None):
34         self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT
35         self._handle = handle
36         self._closed = False
37 
38     def accept(self):
39         raise NotImplementedError()
40 
41     def bind(self, address):
42         raise NotImplementedError()
43 
44     def close(self):
45         self._handle.Close()
46         self._closed = True
47 
48     @check_closed
49     def connect(self, address):
50         win32pipe.WaitNamedPipe(address, self._timeout)
51         try:
52             handle = win32file.CreateFile(
53                 address,
54                 win32file.GENERIC_READ | win32file.GENERIC_WRITE,
55                 0,
56                 None,
57                 win32file.OPEN_EXISTING,
58                 cSECURITY_ANONYMOUS | cSECURITY_SQOS_PRESENT,
59                 0
60             )
61         except win32pipe.error as e:
62             # See Remarks:
63             # https://msdn.microsoft.com/en-us/library/aa365800.aspx
64             if e.winerror == cERROR_PIPE_BUSY:
65                 # Another program or thread has grabbed our pipe instance
66                 # before we got to it. Wait for availability and attempt to
67                 # connect again.
68                 win32pipe.WaitNamedPipe(address, RETRY_WAIT_TIMEOUT)
69                 return self.connect(address)
70             raise e
71 
72         self.flags = win32pipe.GetNamedPipeInfo(handle)[0]
73 
74         self._handle = handle
75         self._address = address
76 
77     @check_closed
78     def connect_ex(self, address):
79         return self.connect(address)
80 
81     @check_closed
82     def detach(self):
83         self._closed = True
84         return self._handle
85 
86     @check_closed
87     def dup(self):
88         return NpipeSocket(self._handle)
89 
90     @check_closed
91     def fileno(self):
92         return int(self._handle)
93 
94     def getpeername(self):
95         return self._address
96 
97     def getsockname(self):
98         return self._address
99 
100     def getsockopt(self, level, optname, buflen=None):
101         raise NotImplementedError()
102 
103     def ioctl(self, control, option):
104         raise NotImplementedError()
105 
106     def listen(self, backlog):
107         raise NotImplementedError()
108 
109     def makefile(self, mode=None, bufsize=None):
110         if mode.strip('b') != 'r':
111             raise NotImplementedError()
112         rawio = NpipeFileIOBase(self)
113         if bufsize is None or bufsize <= 0:
114             bufsize = io.DEFAULT_BUFFER_SIZE
115         return io.BufferedReader(rawio, buffer_size=bufsize)
116 
117     @check_closed
118     def recv(self, bufsize, flags=0):
119         err, data = win32file.ReadFile(self._handle, bufsize)
120         return data
121 
122     @check_closed
123     def recvfrom(self, bufsize, flags=0):
124         data = self.recv(bufsize, flags)
125         return (data, self._address)
126 
127     @check_closed
128     def recvfrom_into(self, buf, nbytes=0, flags=0):
129         return self.recv_into(buf, nbytes, flags), self._address
130 
131     @check_closed
132     def recv_into(self, buf, nbytes=0):
133         if six.PY2:
134             return self._recv_into_py2(buf, nbytes)
135 
136         readbuf = buf
137         if not isinstance(buf, memoryview):
138             readbuf = memoryview(buf)
139 
140         err, data = win32file.ReadFile(
141             self._handle,
142             readbuf[:nbytes] if nbytes else readbuf
143         )
144         return len(data)
145 
146     def _recv_into_py2(self, buf, nbytes):
147         err, data = win32file.ReadFile(self._handle, nbytes or len(buf))
148         n = len(data)
149         buf[:n] = data
150         return n
151 
152     @check_closed
153     def send(self, string, flags=0):
154         err, nbytes = win32file.WriteFile(self._handle, string)
155         return nbytes
156 
157     @check_closed
158     def sendall(self, string, flags=0):
159         return self.send(string, flags)
160 
161     @check_closed
162     def sendto(self, string, address):
163         self.connect(address)
164         return self.send(string)
165 
166     def setblocking(self, flag):
167         if flag:
168             return self.settimeout(None)
169         return self.settimeout(0)
170 
171     def settimeout(self, value):
172         if value is None:
173             self._timeout = win32pipe.NMPWAIT_NOWAIT
174         elif not isinstance(value, (float, int)) or value < 0:
175             raise ValueError('Timeout value out of range')
176         elif value == 0:
177             self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT
178         else:
179             self._timeout = value
180 
181     def gettimeout(self):
182         return self._timeout
183 
184     def setsockopt(self, level, optname, value):
185         raise NotImplementedError()
186 
187     @check_closed
188     def shutdown(self, how):
189         return self.close()
190 
191 
192 class NpipeFileIOBase(io.RawIOBase):
193     def __init__(self, npipe_socket):
194         self.sock = npipe_socket
195 
196     def close(self):
197         super(NpipeFileIOBase, self).close()
198         self.sock = None
199 
200     def fileno(self):
201         return self.sock.fileno()
202 
203     def isatty(self):
204         return False
205 
206     def readable(self):
207         return True
208 
209     def readinto(self, buf):
210         return self.sock.recv_into(buf)
211 
212     def seekable(self):
213         return False
214 
215     def writable(self):
216         return False
217
```
--- 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()

```

diff --git a/docker/transport/npipesocket.py b/docker/transport/npipesocket.py
--- a/docker/transport/npipesocket.py
+++ b/docker/transport/npipesocket.py
@@ -170,13 +170,16 @@
 
     def settimeout(self, value):
         if value is None:
-            self._timeout = win32pipe.NMPWAIT_NOWAIT
+            # Blocking mode
+            self._timeout = win32pipe.NMPWAIT_WAIT_FOREVER
         elif not isinstance(value, (float, int)) or value < 0:
             raise ValueError('Timeout value out of range')
         elif value == 0:
-            self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT
+            # Non-blocking mode
+            self._timeout = win32pipe.NMPWAIT_NO_WAIT
         else:
-            self._timeout = value
+            # Timeout mode - Value converted to milliseconds
+            self._timeout = value * 1000
 
     def gettimeout(self):
         return self._timeout

{"golden_diff": "diff --git a/docker/transport/npipesocket.py b/docker/transport/npipesocket.py\n--- a/docker/transport/npipesocket.py\n+++ b/docker/transport/npipesocket.py\n@@ -170,13 +170,16 @@\n \n     def settimeout(self, value):\n         if value is None:\n-            self._timeout = win32pipe.NMPWAIT_NOWAIT\n+            # Blocking mode\n+            self._timeout = win32pipe.NMPWAIT_WAIT_FOREVER\n         elif not isinstance(value, (float, int)) or value < 0:\n             raise ValueError('Timeout value out of range')\n         elif value == 0:\n-            self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT\n+            # Non-blocking mode\n+            self._timeout = win32pipe.NMPWAIT_NO_WAIT\n         else:\n-            self._timeout = value\n+            # Timeout mode - Value converted to milliseconds\n+            self._timeout = value * 1000\n \n     def gettimeout(self):\n         return self._timeout\n", "issue": "NpipeSocket.settimeout - Blocking and non-blocking are mixed up\n`settimeout(None)` puts the socket in non-blocking mode, `settimeout(0)` in blocking mode. Specification indicates it should be the other way around.\n", "before_files": [{"content": "import functools\nimport io\n\nimport six\nimport win32file\nimport win32pipe\n\ncERROR_PIPE_BUSY = 0xe7\ncSECURITY_SQOS_PRESENT = 0x100000\ncSECURITY_ANONYMOUS = 0\n\nRETRY_WAIT_TIMEOUT = 10000\n\n\ndef check_closed(f):\n    @functools.wraps(f)\n    def wrapped(self, *args, **kwargs):\n        if self._closed:\n            raise RuntimeError(\n                'Can not reuse socket after connection was closed.'\n            )\n        return f(self, *args, **kwargs)\n    return wrapped\n\n\nclass NpipeSocket(object):\n    \"\"\" Partial implementation of the socket API over windows named pipes.\n        This implementation is only designed to be used as a client socket,\n        and server-specific methods (bind, listen, accept...) are not\n        implemented.\n    \"\"\"\n\n    def __init__(self, handle=None):\n        self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT\n        self._handle = handle\n        self._closed = False\n\n    def accept(self):\n        raise NotImplementedError()\n\n    def bind(self, address):\n        raise NotImplementedError()\n\n    def close(self):\n        self._handle.Close()\n        self._closed = True\n\n    @check_closed\n    def connect(self, address):\n        win32pipe.WaitNamedPipe(address, self._timeout)\n        try:\n            handle = win32file.CreateFile(\n                address,\n                win32file.GENERIC_READ | win32file.GENERIC_WRITE,\n                0,\n                None,\n                win32file.OPEN_EXISTING,\n                cSECURITY_ANONYMOUS | cSECURITY_SQOS_PRESENT,\n                0\n            )\n        except win32pipe.error as e:\n            # See Remarks:\n            # https://msdn.microsoft.com/en-us/library/aa365800.aspx\n            if e.winerror == cERROR_PIPE_BUSY:\n                # Another program or thread has grabbed our pipe instance\n                # before we got to it. Wait for availability and attempt to\n                # connect again.\n                win32pipe.WaitNamedPipe(address, RETRY_WAIT_TIMEOUT)\n                return self.connect(address)\n            raise e\n\n        self.flags = win32pipe.GetNamedPipeInfo(handle)[0]\n\n        self._handle = handle\n        self._address = address\n\n    @check_closed\n    def connect_ex(self, address):\n        return self.connect(address)\n\n    @check_closed\n    def detach(self):\n        self._closed = True\n        return self._handle\n\n    @check_closed\n    def dup(self):\n        return NpipeSocket(self._handle)\n\n    @check_closed\n    def fileno(self):\n        return int(self._handle)\n\n    def getpeername(self):\n        return self._address\n\n    def getsockname(self):\n        return self._address\n\n    def getsockopt(self, level, optname, buflen=None):\n        raise NotImplementedError()\n\n    def ioctl(self, control, option):\n        raise NotImplementedError()\n\n    def listen(self, backlog):\n        raise NotImplementedError()\n\n    def makefile(self, mode=None, bufsize=None):\n        if mode.strip('b') != 'r':\n            raise NotImplementedError()\n        rawio = NpipeFileIOBase(self)\n        if bufsize is None or bufsize <= 0:\n            bufsize = io.DEFAULT_BUFFER_SIZE\n        return io.BufferedReader(rawio, buffer_size=bufsize)\n\n    @check_closed\n    def recv(self, bufsize, flags=0):\n        err, data = win32file.ReadFile(self._handle, bufsize)\n        return data\n\n    @check_closed\n    def recvfrom(self, bufsize, flags=0):\n        data = self.recv(bufsize, flags)\n        return (data, self._address)\n\n    @check_closed\n    def recvfrom_into(self, buf, nbytes=0, flags=0):\n        return self.recv_into(buf, nbytes, flags), self._address\n\n    @check_closed\n    def recv_into(self, buf, nbytes=0):\n        if six.PY2:\n            return self._recv_into_py2(buf, nbytes)\n\n        readbuf = buf\n        if not isinstance(buf, memoryview):\n            readbuf = memoryview(buf)\n\n        err, data = win32file.ReadFile(\n            self._handle,\n            readbuf[:nbytes] if nbytes else readbuf\n        )\n        return len(data)\n\n    def _recv_into_py2(self, buf, nbytes):\n        err, data = win32file.ReadFile(self._handle, nbytes or len(buf))\n        n = len(data)\n        buf[:n] = data\n        return n\n\n    @check_closed\n    def send(self, string, flags=0):\n        err, nbytes = win32file.WriteFile(self._handle, string)\n        return nbytes\n\n    @check_closed\n    def sendall(self, string, flags=0):\n        return self.send(string, flags)\n\n    @check_closed\n    def sendto(self, string, address):\n        self.connect(address)\n        return self.send(string)\n\n    def setblocking(self, flag):\n        if flag:\n            return self.settimeout(None)\n        return self.settimeout(0)\n\n    def settimeout(self, value):\n        if value is None:\n            self._timeout = win32pipe.NMPWAIT_NOWAIT\n        elif not isinstance(value, (float, int)) or value < 0:\n            raise ValueError('Timeout value out of range')\n        elif value == 0:\n            self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT\n        else:\n            self._timeout = value\n\n    def gettimeout(self):\n        return self._timeout\n\n    def setsockopt(self, level, optname, value):\n        raise NotImplementedError()\n\n    @check_closed\n    def shutdown(self, how):\n        return self.close()\n\n\nclass NpipeFileIOBase(io.RawIOBase):\n    def __init__(self, npipe_socket):\n        self.sock = npipe_socket\n\n    def close(self):\n        super(NpipeFileIOBase, self).close()\n        self.sock = None\n\n    def fileno(self):\n        return self.sock.fileno()\n\n    def isatty(self):\n        return False\n\n    def readable(self):\n        return True\n\n    def readinto(self, buf):\n        return self.sock.recv_into(buf)\n\n    def seekable(self):\n        return False\n\n    def writable(self):\n        return False\n", "path": "docker/transport/npipesocket.py"}], "after_files": [{"content": "import functools\nimport io\n\nimport six\nimport win32file\nimport win32pipe\n\ncERROR_PIPE_BUSY = 0xe7\ncSECURITY_SQOS_PRESENT = 0x100000\ncSECURITY_ANONYMOUS = 0\n\nRETRY_WAIT_TIMEOUT = 10000\n\n\ndef check_closed(f):\n    @functools.wraps(f)\n    def wrapped(self, *args, **kwargs):\n        if self._closed:\n            raise RuntimeError(\n                'Can not reuse socket after connection was closed.'\n            )\n        return f(self, *args, **kwargs)\n    return wrapped\n\n\nclass NpipeSocket(object):\n    \"\"\" Partial implementation of the socket API over windows named pipes.\n        This implementation is only designed to be used as a client socket,\n        and server-specific methods (bind, listen, accept...) are not\n        implemented.\n    \"\"\"\n\n    def __init__(self, handle=None):\n        self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT\n        self._handle = handle\n        self._closed = False\n\n    def accept(self):\n        raise NotImplementedError()\n\n    def bind(self, address):\n        raise NotImplementedError()\n\n    def close(self):\n        self._handle.Close()\n        self._closed = True\n\n    @check_closed\n    def connect(self, address):\n        win32pipe.WaitNamedPipe(address, self._timeout)\n        try:\n            handle = win32file.CreateFile(\n                address,\n                win32file.GENERIC_READ | win32file.GENERIC_WRITE,\n                0,\n                None,\n                win32file.OPEN_EXISTING,\n                cSECURITY_ANONYMOUS | cSECURITY_SQOS_PRESENT,\n                0\n            )\n        except win32pipe.error as e:\n            # See Remarks:\n            # https://msdn.microsoft.com/en-us/library/aa365800.aspx\n            if e.winerror == cERROR_PIPE_BUSY:\n                # Another program or thread has grabbed our pipe instance\n                # before we got to it. Wait for availability and attempt to\n                # connect again.\n                win32pipe.WaitNamedPipe(address, RETRY_WAIT_TIMEOUT)\n                return self.connect(address)\n            raise e\n\n        self.flags = win32pipe.GetNamedPipeInfo(handle)[0]\n\n        self._handle = handle\n        self._address = address\n\n    @check_closed\n    def connect_ex(self, address):\n        return self.connect(address)\n\n    @check_closed\n    def detach(self):\n        self._closed = True\n        return self._handle\n\n    @check_closed\n    def dup(self):\n        return NpipeSocket(self._handle)\n\n    @check_closed\n    def fileno(self):\n        return int(self._handle)\n\n    def getpeername(self):\n        return self._address\n\n    def getsockname(self):\n        return self._address\n\n    def getsockopt(self, level, optname, buflen=None):\n        raise NotImplementedError()\n\n    def ioctl(self, control, option):\n        raise NotImplementedError()\n\n    def listen(self, backlog):\n        raise NotImplementedError()\n\n    def makefile(self, mode=None, bufsize=None):\n        if mode.strip('b') != 'r':\n            raise NotImplementedError()\n        rawio = NpipeFileIOBase(self)\n        if bufsize is None or bufsize <= 0:\n            bufsize = io.DEFAULT_BUFFER_SIZE\n        return io.BufferedReader(rawio, buffer_size=bufsize)\n\n    @check_closed\n    def recv(self, bufsize, flags=0):\n        err, data = win32file.ReadFile(self._handle, bufsize)\n        return data\n\n    @check_closed\n    def recvfrom(self, bufsize, flags=0):\n        data = self.recv(bufsize, flags)\n        return (data, self._address)\n\n    @check_closed\n    def recvfrom_into(self, buf, nbytes=0, flags=0):\n        return self.recv_into(buf, nbytes, flags), self._address\n\n    @check_closed\n    def recv_into(self, buf, nbytes=0):\n        if six.PY2:\n            return self._recv_into_py2(buf, nbytes)\n\n        readbuf = buf\n        if not isinstance(buf, memoryview):\n            readbuf = memoryview(buf)\n\n        err, data = win32file.ReadFile(\n            self._handle,\n            readbuf[:nbytes] if nbytes else readbuf\n        )\n        return len(data)\n\n    def _recv_into_py2(self, buf, nbytes):\n        err, data = win32file.ReadFile(self._handle, nbytes or len(buf))\n        n = len(data)\n        buf[:n] = data\n        return n\n\n    @check_closed\n    def send(self, string, flags=0):\n        err, nbytes = win32file.WriteFile(self._handle, string)\n        return nbytes\n\n    @check_closed\n    def sendall(self, string, flags=0):\n        return self.send(string, flags)\n\n    @check_closed\n    def sendto(self, string, address):\n        self.connect(address)\n        return self.send(string)\n\n    def setblocking(self, flag):\n        if flag:\n            return self.settimeout(None)\n        return self.settimeout(0)\n\n    def settimeout(self, value):\n        if value is None:\n            # Blocking mode\n            self._timeout = win32pipe.NMPWAIT_WAIT_FOREVER\n        elif not isinstance(value, (float, int)) or value < 0:\n            raise ValueError('Timeout value out of range')\n        elif value == 0:\n            # Non-blocking mode\n            self._timeout = win32pipe.NMPWAIT_NO_WAIT\n        else:\n            # Timeout mode - Value converted to milliseconds\n            self._timeout = value * 1000\n\n    def gettimeout(self):\n        return self._timeout\n\n    def setsockopt(self, level, optname, value):\n        raise NotImplementedError()\n\n    @check_closed\n    def shutdown(self, how):\n        return self.close()\n\n\nclass NpipeFileIOBase(io.RawIOBase):\n    def __init__(self, npipe_socket):\n        self.sock = npipe_socket\n\n    def close(self):\n        super(NpipeFileIOBase, self).close()\n        self.sock = None\n\n    def fileno(self):\n        return self.sock.fileno()\n\n    def isatty(self):\n        return False\n\n    def readable(self):\n        return True\n\n    def readinto(self, buf):\n        return self.sock.recv_into(buf)\n\n    def seekable(self):\n        return False\n\n    def writable(self):\n        return False\n", "path": "docker/transport/npipesocket.py"}]}