Skip to content

Commit

Permalink
Cleanup docs on make clean, rename WebSocketDisconnected to WebSocket…
Browse files Browse the repository at this point in the history
…DisconnectedError
  • Loading branch information
asvetlov committed Jan 4, 2015
1 parent bcd30bd commit 1cc06f9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ clean:
rm -rf coverage
rm -rf build
rm -rf cover
make -C docs clean

doc:
make -C docs html
Expand Down
6 changes: 4 additions & 2 deletions aiohttp/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

'ClientError', 'ClientHttpProcessingError', 'ClientConnectionError',
'ClientOSError', 'ClientTimeoutError', 'ProxyConnectionError',
'ClientRequestError', 'ClientResponseError', 'WebSocketDisconnected']
'ClientRequestError', 'ClientResponseError', 'WebSocketDisconnectedError']

from asyncio import TimeoutError

Expand All @@ -26,18 +26,20 @@ class ServerDisconnectedError(DisconnectedError):
"""Server disconnected."""


class WebSocketDisconnected(ClientDisconnectedError):
class WebSocketDisconnectedError(ClientDisconnectedError):
"""Raised on closing websocket by peer."""

def __init__(self, code=None, message=None):
super().__init__(code, message)

@property
def code(self):
"""Code from websocket closing frame."""
return self.args[0]

@property
def message(self):
"""Message from websocket closing frame."""
return self.args[1]


Expand Down
8 changes: 4 additions & 4 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from .server import ServerHttpProtocol
from .streams import EOF_MARKER
from .websocket import do_handshake, MSG_BINARY, MSG_CLOSE, MSG_PING, MSG_TEXT
from .errors import HttpProcessingError, WebSocketDisconnected
from .errors import HttpProcessingError, WebSocketDisconnectedError


__all__ = [
'WebSocketDisconnected',
'WebSocketDisconnectedError',
'Application',
'HttpVersion',
'RequestHandler',
Expand Down Expand Up @@ -770,14 +770,14 @@ def receive(self):

if msg.tp == MSG_CLOSE:
if self._closing:
exc = WebSocketDisconnected(msg.data, msg.extra)
exc = WebSocketDisconnectedError(msg.data, msg.extra)
self._closing_fut.set_exception(exc)
raise exc
else:
self._closing = True
self._writer.close(msg.data, msg.extra)
yield from self.drain()
exc = WebSocketDisconnected(msg.data, msg.extra)
exc = WebSocketDisconnectedError(msg.data, msg.extra)
self._closing_fut.set_exception(exc)
raise exc
elif not self._closing:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_web_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import unittest
from unittest import mock
from aiohttp.multidict import MultiDict
from aiohttp.web import (Request, WebSocketResponse, WebSocketDisconnected,
from aiohttp.web import (Request, WebSocketResponse,
WebSocketDisconnectedError,
HTTPMethodNotAllowed, HTTPBadRequest)
from aiohttp.protocol import RawRequestMessage, HttpVersion11

Expand Down Expand Up @@ -90,7 +91,7 @@ def test_nested_exception(self):

@asyncio.coroutine
def a():
raise WebSocketDisconnected()
raise WebSocketDisconnectedError()

@asyncio.coroutine
def b():
Expand All @@ -100,7 +101,7 @@ def b():
def c():
yield from b()

with self.assertRaises(WebSocketDisconnected):
with self.assertRaises(WebSocketDisconnectedError):
self.loop.run_until_complete(c())

def test_can_start_ok(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_web_websocket_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def handler(request):

try:
yield from ws.receive()
except web.WebSocketDisconnected as exc:
except web.WebSocketDisconnectedError as exc:
self.assertEqual(1, exc.code)
self.assertEqual(b'exit message', exc.message)
closed.set_result(None)
Expand Down Expand Up @@ -175,7 +175,7 @@ def handler(request):
ws.ping()
try:
yield from ws.receive()
except web.WebSocketDisconnected as exc:
except web.WebSocketDisconnectedError as exc:
self.assertEqual(2, exc.code)
self.assertEqual(b'exit message', exc.message)
closed.set_result(None)
Expand Down Expand Up @@ -248,7 +248,7 @@ def handler(request):
ws.close()
try:
yield from ws.receive()
except web.WebSocketDisconnected:
except web.WebSocketDisconnectedError:
closed.set_result(None)
return ws

Expand All @@ -274,7 +274,7 @@ def handler(request):
ws.start(request)
try:
yield from ws.receive()
except web.WebSocketDisconnected:
except web.WebSocketDisconnectedError:
closed.set_result(None)
return ws

Expand All @@ -300,7 +300,7 @@ def closer(ws):
ws.close()
try:
yield from ws.wait_closed()
except web.WebSocketDisconnected:
except web.WebSocketDisconnectedError:
closed2.set_result(None)

@asyncio.coroutine
Expand All @@ -310,7 +310,7 @@ def handler(request):
asyncio.async(closer(ws), loop=request.app.loop)
try:
yield from ws.receive()
except web.WebSocketDisconnected:
except web.WebSocketDisconnectedError:
closed.set_result(None)
return ws

Expand All @@ -337,7 +337,7 @@ def handler(request):
ws.close()
try:
yield from ws.receive()
except web.WebSocketDisconnected:
except web.WebSocketDisconnectedError:
closed.set_result(None)
return ws

Expand Down

0 comments on commit 1cc06f9

Please sign in to comment.