prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Erorr in websockets.py: '<=' not supported between instances of 'int' and 'NoneType'
  * web3 (4.3.0)
  * websockets (4.0.1)
  * Python: 3.6
  * OS: osx HighSierra
  
  
  ### What was wrong?
  
  `web3 = Web3(Web3.WebsocketProvider("ws://10.224.12.6:8546"))`
  `web3.eth.syncing //returns data`
  
  The websocket is clearly open but when I run a filter which is supposed to have many entries, I get the following error trace:
  
  Upon running: `data = web3.eth.getFilterLogs(new_block_filter.filter_id)`, I get:
  
  ```
  ~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/web3/providers/websocket.py in make_request(self, method, params)
       81             WebsocketProvider._loop
       82         )
  ---> 83         return future.result()
  
  /anaconda3/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)
      430                 raise CancelledError()
      431             elif self._state == FINISHED:
  --> 432                 return self.__get_result()
      433             else:
      434                 raise TimeoutError()
  
  /anaconda3/lib/python3.6/concurrent/futures/_base.py in __get_result(self)
      382     def __get_result(self):
      383         if self._exception:
  --> 384             raise self._exception
      385         else:
      386             return self._result
  
  ~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/web3/providers/websocket.py in coro_make_request(self, request_data)
       71         async with self.conn as conn:
       72             await conn.send(request_data)
  ---> 73             return json.loads(await conn.recv())
       74 
       75     def make_request(self, method, params):
  
  ~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/websockets/protocol.py in recv(self)
      321             next_message.cancel()
      322             if not self.legacy_recv:
  --> 323                 raise ConnectionClosed(self.close_code, self.close_reason)
      324 
      325     @asyncio.coroutine
  
  ~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/websockets/exceptions.py in __init__(self, code, reason)
      145         self.reason = reason
      146         message = "WebSocket connection is closed: "
  --> 147         if 3000 <= code < 4000:
      148             explanation = "registered"
      149         elif 4000 <= code < 5000:
  
  TypeError: '<=' not supported between instances of 'int' and 'NoneType'
  ```
  
  The same filter runs fine (albeit a bit slow) using `Web3.HTTPProvider()`
  
  
  
  </issue>
  <code>
  [start of web3/providers/websocket.py]
  1 import asyncio
  2 import json
  3 import logging
  4 import os
  5 from threading import (
  6     Thread,
  7 )
  8 
  9 import websockets
  10 
  11 from web3.providers.base import (
  12     JSONBaseProvider,
  13 )
  14 
  15 
  16 def _start_event_loop(loop):
  17     asyncio.set_event_loop(loop)
  18     loop.run_forever()
  19     loop.close()
  20 
  21 
  22 def _get_threaded_loop():
  23     new_loop = asyncio.new_event_loop()
  24     thread_loop = Thread(target=_start_event_loop, args=(new_loop,), daemon=True)
  25     thread_loop.start()
  26     return new_loop
  27 
  28 
  29 def get_default_endpoint():
  30     return os.environ.get('WEB3_WS_PROVIDER_URI', 'ws://127.0.0.1:8546')
  31 
  32 
  33 class PersistentWebSocket:
  34 
  35     def __init__(self, endpoint_uri, loop):
  36         self.ws = None
  37         self.endpoint_uri = endpoint_uri
  38         self.loop = loop
  39 
  40     async def __aenter__(self):
  41         if self.ws is None:
  42             self.ws = await websockets.connect(uri=self.endpoint_uri, loop=self.loop)
  43         return self.ws
  44 
  45     async def __aexit__(self, exc_type, exc_val, exc_tb):
  46         if exc_val is not None:
  47             try:
  48                 await self.ws.close()
  49             except Exception:
  50                 pass
  51             self.ws = None
  52 
  53 
  54 class WebsocketProvider(JSONBaseProvider):
  55     logger = logging.getLogger("web3.providers.WebsocketProvider")
  56     _loop = None
  57 
  58     def __init__(self, endpoint_uri=None):
  59         self.endpoint_uri = endpoint_uri
  60         if self.endpoint_uri is None:
  61             self.endpoint_uri = get_default_endpoint()
  62         if WebsocketProvider._loop is None:
  63             WebsocketProvider._loop = _get_threaded_loop()
  64         self.conn = PersistentWebSocket(self.endpoint_uri, WebsocketProvider._loop)
  65         super().__init__()
  66 
  67     def __str__(self):
  68         return "WS connection {0}".format(self.endpoint_uri)
  69 
  70     async def coro_make_request(self, request_data):
  71         async with self.conn as conn:
  72             await conn.send(request_data)
  73             return json.loads(await conn.recv())
  74 
  75     def make_request(self, method, params):
  76         self.logger.debug("Making request WebSocket. URI: %s, "
  77                           "Method: %s", self.endpoint_uri, method)
  78         request_data = self.encode_rpc_request(method, params)
  79         future = asyncio.run_coroutine_threadsafe(
  80             self.coro_make_request(request_data),
  81             WebsocketProvider._loop
  82         )
  83         return future.result()
  84
  [end of web3/providers/websocket.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/web3/providers/websocket.py b/web3/providers/websocket.py
  --- a/web3/providers/websocket.py
  +++ b/web3/providers/websocket.py
  @@ -8,10 +8,15 @@
   
   import websockets
   
  +from web3.exceptions import (
  +    ValidationError,
  +)
   from web3.providers.base import (
       JSONBaseProvider,
   )
   
  +RESTRICTED_WEBSOCKET_KWARGS = {'uri', 'loop'}
  +
   
   def _start_event_loop(loop):
       asyncio.set_event_loop(loop)
  @@ -32,14 +37,17 @@
   
   class PersistentWebSocket:
   
  -    def __init__(self, endpoint_uri, loop):
  +    def __init__(self, endpoint_uri, loop, websocket_kwargs):
           self.ws = None
           self.endpoint_uri = endpoint_uri
           self.loop = loop
  +        self.websocket_kwargs = websocket_kwargs
   
       async def __aenter__(self):
           if self.ws is None:
  -            self.ws = await websockets.connect(uri=self.endpoint_uri, loop=self.loop)
  +            self.ws = await websockets.connect(
  +                uri=self.endpoint_uri, loop=self.loop, **self.websocket_kwargs
  +            )
           return self.ws
   
       async def __aexit__(self, exc_type, exc_val, exc_tb):
  @@ -55,13 +63,26 @@
       logger = logging.getLogger("web3.providers.WebsocketProvider")
       _loop = None
   
  -    def __init__(self, endpoint_uri=None):
  +    def __init__(self, endpoint_uri=None, websocket_kwargs=None):
           self.endpoint_uri = endpoint_uri
           if self.endpoint_uri is None:
               self.endpoint_uri = get_default_endpoint()
           if WebsocketProvider._loop is None:
               WebsocketProvider._loop = _get_threaded_loop()
  -        self.conn = PersistentWebSocket(self.endpoint_uri, WebsocketProvider._loop)
  +        if websocket_kwargs is None:
  +            websocket_kwargs = {}
  +        else:
  +            found_restricted_keys = set(websocket_kwargs.keys()).intersection(
  +                RESTRICTED_WEBSOCKET_KWARGS
  +            )
  +            if found_restricted_keys:
  +                raise ValidationError(
  +                    '{0} are not allowed in websocket_kwargs, '
  +                    'found: {1}'.format(RESTRICTED_WEBSOCKET_KWARGS, found_restricted_keys)
  +                )
  +        self.conn = PersistentWebSocket(
  +            self.endpoint_uri, WebsocketProvider._loop, websocket_kwargs
  +        )
           super().__init__()
   
       def __str__(self):
  
verification_info: {"golden_diff": "diff --git a/web3/providers/websocket.py b/web3/providers/websocket.py\n--- a/web3/providers/websocket.py\n+++ b/web3/providers/websocket.py\n@@ -8,10 +8,15 @@\n \n import websockets\n \n+from web3.exceptions import (\n+    ValidationError,\n+)\n from web3.providers.base import (\n     JSONBaseProvider,\n )\n \n+RESTRICTED_WEBSOCKET_KWARGS = {'uri', 'loop'}\n+\n \n def _start_event_loop(loop):\n     asyncio.set_event_loop(loop)\n@@ -32,14 +37,17 @@\n \n class PersistentWebSocket:\n \n-    def __init__(self, endpoint_uri, loop):\n+    def __init__(self, endpoint_uri, loop, websocket_kwargs):\n         self.ws = None\n         self.endpoint_uri = endpoint_uri\n         self.loop = loop\n+        self.websocket_kwargs = websocket_kwargs\n \n     async def __aenter__(self):\n         if self.ws is None:\n-            self.ws = await websockets.connect(uri=self.endpoint_uri, loop=self.loop)\n+            self.ws = await websockets.connect(\n+                uri=self.endpoint_uri, loop=self.loop, **self.websocket_kwargs\n+            )\n         return self.ws\n \n     async def __aexit__(self, exc_type, exc_val, exc_tb):\n@@ -55,13 +63,26 @@\n     logger = logging.getLogger(\"web3.providers.WebsocketProvider\")\n     _loop = None\n \n-    def __init__(self, endpoint_uri=None):\n+    def __init__(self, endpoint_uri=None, websocket_kwargs=None):\n         self.endpoint_uri = endpoint_uri\n         if self.endpoint_uri is None:\n             self.endpoint_uri = get_default_endpoint()\n         if WebsocketProvider._loop is None:\n             WebsocketProvider._loop = _get_threaded_loop()\n-        self.conn = PersistentWebSocket(self.endpoint_uri, WebsocketProvider._loop)\n+        if websocket_kwargs is None:\n+            websocket_kwargs = {}\n+        else:\n+            found_restricted_keys = set(websocket_kwargs.keys()).intersection(\n+                RESTRICTED_WEBSOCKET_KWARGS\n+            )\n+            if found_restricted_keys:\n+                raise ValidationError(\n+                    '{0} are not allowed in websocket_kwargs, '\n+                    'found: {1}'.format(RESTRICTED_WEBSOCKET_KWARGS, found_restricted_keys)\n+                )\n+        self.conn = PersistentWebSocket(\n+            self.endpoint_uri, WebsocketProvider._loop, websocket_kwargs\n+        )\n         super().__init__()\n \n     def __str__(self):\n", "issue": "Erorr in websockets.py: '<=' not supported between instances of 'int' and 'NoneType'\n* web3 (4.3.0)\r\n* websockets (4.0.1)\r\n* Python: 3.6\r\n* OS: osx HighSierra\r\n\r\n\r\n### What was wrong?\r\n\r\n`web3 = Web3(Web3.WebsocketProvider(\"ws://10.224.12.6:8546\"))`\r\n`web3.eth.syncing //returns data`\r\n\r\nThe websocket is clearly open but when I run a filter which is supposed to have many entries, I get the following error trace:\r\n\r\nUpon running: `data = web3.eth.getFilterLogs(new_block_filter.filter_id)`, I get:\r\n\r\n```\r\n~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/web3/providers/websocket.py in make_request(self, method, params)\r\n     81             WebsocketProvider._loop\r\n     82         )\r\n---> 83         return future.result()\r\n\r\n/anaconda3/lib/python3.6/concurrent/futures/_base.py in result(self, timeout)\r\n    430                 raise CancelledError()\r\n    431             elif self._state == FINISHED:\r\n--> 432                 return self.__get_result()\r\n    433             else:\r\n    434                 raise TimeoutError()\r\n\r\n/anaconda3/lib/python3.6/concurrent/futures/_base.py in __get_result(self)\r\n    382     def __get_result(self):\r\n    383         if self._exception:\r\n--> 384             raise self._exception\r\n    385         else:\r\n    386             return self._result\r\n\r\n~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/web3/providers/websocket.py in coro_make_request(self, request_data)\r\n     71         async with self.conn as conn:\r\n     72             await conn.send(request_data)\r\n---> 73             return json.loads(await conn.recv())\r\n     74 \r\n     75     def make_request(self, method, params):\r\n\r\n~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/websockets/protocol.py in recv(self)\r\n    321             next_message.cancel()\r\n    322             if not self.legacy_recv:\r\n--> 323                 raise ConnectionClosed(self.close_code, self.close_reason)\r\n    324 \r\n    325     @asyncio.coroutine\r\n\r\n~/Desktop/contracts-py/contracts/lib/python3.6/site-packages/websockets/exceptions.py in __init__(self, code, reason)\r\n    145         self.reason = reason\r\n    146         message = \"WebSocket connection is closed: \"\r\n--> 147         if 3000 <= code < 4000:\r\n    148             explanation = \"registered\"\r\n    149         elif 4000 <= code < 5000:\r\n\r\nTypeError: '<=' not supported between instances of 'int' and 'NoneType'\r\n```\r\n\r\nThe same filter runs fine (albeit a bit slow) using `Web3.HTTPProvider()`\r\n\r\n\n", "before_files": [{"content": "import asyncio\nimport json\nimport logging\nimport os\nfrom threading import (\n    Thread,\n)\n\nimport websockets\n\nfrom web3.providers.base import (\n    JSONBaseProvider,\n)\n\n\ndef _start_event_loop(loop):\n    asyncio.set_event_loop(loop)\n    loop.run_forever()\n    loop.close()\n\n\ndef _get_threaded_loop():\n    new_loop = asyncio.new_event_loop()\n    thread_loop = Thread(target=_start_event_loop, args=(new_loop,), daemon=True)\n    thread_loop.start()\n    return new_loop\n\n\ndef get_default_endpoint():\n    return os.environ.get('WEB3_WS_PROVIDER_URI', 'ws://127.0.0.1:8546')\n\n\nclass PersistentWebSocket:\n\n    def __init__(self, endpoint_uri, loop):\n        self.ws = None\n        self.endpoint_uri = endpoint_uri\n        self.loop = loop\n\n    async def __aenter__(self):\n        if self.ws is None:\n            self.ws = await websockets.connect(uri=self.endpoint_uri, loop=self.loop)\n        return self.ws\n\n    async def __aexit__(self, exc_type, exc_val, exc_tb):\n        if exc_val is not None:\n            try:\n                await self.ws.close()\n            except Exception:\n                pass\n            self.ws = None\n\n\nclass WebsocketProvider(JSONBaseProvider):\n    logger = logging.getLogger(\"web3.providers.WebsocketProvider\")\n    _loop = None\n\n    def __init__(self, endpoint_uri=None):\n        self.endpoint_uri = endpoint_uri\n        if self.endpoint_uri is None:\n            self.endpoint_uri = get_default_endpoint()\n        if WebsocketProvider._loop is None:\n            WebsocketProvider._loop = _get_threaded_loop()\n        self.conn = PersistentWebSocket(self.endpoint_uri, WebsocketProvider._loop)\n        super().__init__()\n\n    def __str__(self):\n        return \"WS connection {0}\".format(self.endpoint_uri)\n\n    async def coro_make_request(self, request_data):\n        async with self.conn as conn:\n            await conn.send(request_data)\n            return json.loads(await conn.recv())\n\n    def make_request(self, method, params):\n        self.logger.debug(\"Making request WebSocket. URI: %s, \"\n                          \"Method: %s\", self.endpoint_uri, method)\n        request_data = self.encode_rpc_request(method, params)\n        future = asyncio.run_coroutine_threadsafe(\n            self.coro_make_request(request_data),\n            WebsocketProvider._loop\n        )\n        return future.result()\n", "path": "web3/providers/websocket.py"}]}