prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Chat demo not working in aiohttp 3
  ## Long story short
  
  Want to learn websockets with example code. There's a lack of simple and runnable example code on the net demonstrating websockets in python.
  
  ## Expected behaviour
  
  Server runs and page loads
  
  ## Actual behaviour
  
  Server runs but page fails to load with following error:
  ```
  ~/work/aiohttp/demos/chat$ ~/venv3/bin/python aiohttpdemo_chat/main.py 
  DEBUG:asyncio:Using selector: EpollSelector
  ======== Running on http://0.0.0.0:8080 ========
  (Press CTRL+C to quit)
  ERROR:aiohttp.server:Error handling request
  Traceback (most recent call last):
    File "/home/robin/venv3/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 381, in start
      resp = await self._request_handler(request)
    File "/home/robin/venv3/lib/python3.6/site-packages/aiohttp/web_app.py", line 310, in _handle
      resp = await handler(request)
    File "/home/robin/venv3/lib/python3.6/site-packages/aiohttpdemo_chat-0.0.1-py3.6.egg/aiohttpdemo_chat/views.py", line 15, in index
      ok, protocol = resp.can_start(request)
  AttributeError: 'WebSocketResponse' object has no attribute 'can_start'
  ```
  
  ## Steps to reproduce
  
  Just run `aiohttpdemo_chat/main.py`
  
  ## Your environment
  
  archlinux, aiohttp 3.0.5 server?
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `demos/chat/aiohttpdemo_chat/views.py`
  Content:
  ```
  1 import json
  2 import logging
  3 import random
  4 import string
  5 
  6 import aiohttp_jinja2
  7 from aiohttp import web
  8 
  9 
  10 log = logging.getLogger(__name__)
  11 
  12 
  13 async def index(request):
  14     resp = web.WebSocketResponse()
  15     ok, protocol = resp.can_start(request)
  16     if not ok:
  17         return aiohttp_jinja2.render_template('index.html', request, {})
  18 
  19     await resp.prepare(request)
  20     name = (random.choice(string.ascii_uppercase) +
  21             ''.join(random.sample(string.ascii_lowercase*10, 10)))
  22     log.info('%s joined.', name)
  23     await resp.send_str(json.dumps({'action': 'connect',
  24                                     'name': name}))
  25     for ws in request.app['sockets'].values():
  26         await ws.send_str(json.dumps({'action': 'join',
  27                                       'name': name}))
  28     request.app['sockets'][name] = resp
  29 
  30     while True:
  31         msg = await resp.receive()
  32 
  33         if msg.type == web.MsgType.text:
  34             for ws in request.app['sockets'].values():
  35                 if ws is not resp:
  36                     await ws.send_str(json.dumps({'action': 'sent',
  37                                                   'name': name,
  38                                                   'text': msg.data}))
  39         else:
  40             break
  41 
  42     del request.app['sockets'][name]
  43     log.info('%s disconnected.', name)
  44     for ws in request.app['sockets'].values():
  45         await ws.send_str(json.dumps({'action': 'disconnect',
  46                                       'name': name}))
  47     return resp
  48 
  49 
  50 def setup(app):
  51     app.router.add_get('/', index)
  52
  ```
  --- 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/demos/chat/aiohttpdemo_chat/views.py b/demos/chat/aiohttpdemo_chat/views.py
  --- a/demos/chat/aiohttpdemo_chat/views.py
  +++ b/demos/chat/aiohttpdemo_chat/views.py
  @@ -12,8 +12,8 @@
   
   async def index(request):
       resp = web.WebSocketResponse()
  -    ok, protocol = resp.can_start(request)
  -    if not ok:
  +    is_ws = resp.can_prepare(request)
  +    if not is_ws:
           return aiohttp_jinja2.render_template('index.html', request, {})
   
       await resp.prepare(request)
  
verification_info: {"golden_diff": "diff --git a/demos/chat/aiohttpdemo_chat/views.py b/demos/chat/aiohttpdemo_chat/views.py\n--- a/demos/chat/aiohttpdemo_chat/views.py\n+++ b/demos/chat/aiohttpdemo_chat/views.py\n@@ -12,8 +12,8 @@\n \n async def index(request):\n     resp = web.WebSocketResponse()\n-    ok, protocol = resp.can_start(request)\n-    if not ok:\n+    is_ws = resp.can_prepare(request)\n+    if not is_ws:\n         return aiohttp_jinja2.render_template('index.html', request, {})\n \n     await resp.prepare(request)\n", "issue": "Chat demo not working in aiohttp 3\n## Long story short\r\n\r\nWant to learn websockets with example code. There's a lack of simple and runnable example code on the net demonstrating websockets in python.\r\n\r\n## Expected behaviour\r\n\r\nServer runs and page loads\r\n\r\n## Actual behaviour\r\n\r\nServer runs but page fails to load with following error:\r\n```\r\n~/work/aiohttp/demos/chat$ ~/venv3/bin/python aiohttpdemo_chat/main.py \r\nDEBUG:asyncio:Using selector: EpollSelector\r\n======== Running on http://0.0.0.0:8080 ========\r\n(Press CTRL+C to quit)\r\nERROR:aiohttp.server:Error handling request\r\nTraceback (most recent call last):\r\n  File \"/home/robin/venv3/lib/python3.6/site-packages/aiohttp/web_protocol.py\", line 381, in start\r\n    resp = await self._request_handler(request)\r\n  File \"/home/robin/venv3/lib/python3.6/site-packages/aiohttp/web_app.py\", line 310, in _handle\r\n    resp = await handler(request)\r\n  File \"/home/robin/venv3/lib/python3.6/site-packages/aiohttpdemo_chat-0.0.1-py3.6.egg/aiohttpdemo_chat/views.py\", line 15, in index\r\n    ok, protocol = resp.can_start(request)\r\nAttributeError: 'WebSocketResponse' object has no attribute 'can_start'\r\n```\r\n\r\n## Steps to reproduce\r\n\r\nJust run `aiohttpdemo_chat/main.py`\r\n\r\n## Your environment\r\n\r\narchlinux, aiohttp 3.0.5 server?\r\n\n", "before_files": [{"content": "import json\nimport logging\nimport random\nimport string\n\nimport aiohttp_jinja2\nfrom aiohttp import web\n\n\nlog = logging.getLogger(__name__)\n\n\nasync def index(request):\n    resp = web.WebSocketResponse()\n    ok, protocol = resp.can_start(request)\n    if not ok:\n        return aiohttp_jinja2.render_template('index.html', request, {})\n\n    await resp.prepare(request)\n    name = (random.choice(string.ascii_uppercase) +\n            ''.join(random.sample(string.ascii_lowercase*10, 10)))\n    log.info('%s joined.', name)\n    await resp.send_str(json.dumps({'action': 'connect',\n                                    'name': name}))\n    for ws in request.app['sockets'].values():\n        await ws.send_str(json.dumps({'action': 'join',\n                                      'name': name}))\n    request.app['sockets'][name] = resp\n\n    while True:\n        msg = await resp.receive()\n\n        if msg.type == web.MsgType.text:\n            for ws in request.app['sockets'].values():\n                if ws is not resp:\n                    await ws.send_str(json.dumps({'action': 'sent',\n                                                  'name': name,\n                                                  'text': msg.data}))\n        else:\n            break\n\n    del request.app['sockets'][name]\n    log.info('%s disconnected.', name)\n    for ws in request.app['sockets'].values():\n        await ws.send_str(json.dumps({'action': 'disconnect',\n                                      'name': name}))\n    return resp\n\n\ndef setup(app):\n    app.router.add_get('/', index)\n", "path": "demos/chat/aiohttpdemo_chat/views.py"}], "after_files": [{"content": "import json\nimport logging\nimport random\nimport string\n\nimport aiohttp_jinja2\nfrom aiohttp import web\n\n\nlog = logging.getLogger(__name__)\n\n\nasync def index(request):\n    resp = web.WebSocketResponse()\n    is_ws = resp.can_prepare(request)\n    if not is_ws:\n        return aiohttp_jinja2.render_template('index.html', request, {})\n\n    await resp.prepare(request)\n    name = (random.choice(string.ascii_uppercase) +\n            ''.join(random.sample(string.ascii_lowercase*10, 10)))\n    log.info('%s joined.', name)\n    await resp.send_str(json.dumps({'action': 'connect',\n                                    'name': name}))\n    for ws in request.app['sockets'].values():\n        await ws.send_str(json.dumps({'action': 'join',\n                                      'name': name}))\n    request.app['sockets'][name] = resp\n\n    while True:\n        msg = await resp.receive()\n\n        if msg.type == web.MsgType.text:\n            for ws in request.app['sockets'].values():\n                if ws is not resp:\n                    await ws.send_str(json.dumps({'action': 'sent',\n                                                  'name': name,\n                                                  'text': msg.data}))\n        else:\n            break\n\n    del request.app['sockets'][name]\n    log.info('%s disconnected.', name)\n    for ws in request.app['sockets'].values():\n        await ws.send_str(json.dumps({'action': 'disconnect',\n                                      'name': name}))\n    return resp\n\n\ndef setup(app):\n    app.router.add_get('/', index)\n", "path": "demos/chat/aiohttpdemo_chat/views.py"}]}