diff options
author | Philip Paquette <pcpaquette@gmail.com> | 2019-09-11 12:58:45 -0400 |
---|---|---|
committer | Philip Paquette <pcpaquette@gmail.com> | 2019-09-14 18:18:53 -0400 |
commit | abb42dcd4886705d6ba8af27f68ef605218ac67c (patch) | |
tree | 9ae16f7a09fff539fa72e65198e284bca6ac3376 /diplomacy/server/connection_handler.py | |
parent | a954a00d263750c279dbb2c0a9ae85707022bcd7 (diff) |
Added ReadtheDocs documentation for the public API
- Reformatted the docstring to be compatible
- Added tests to make sure the documentation compiles properly
- Added sphinx as a pip requirement
Co-authored-by: Philip Paquette <pcpaquette@gmail.com>
Co-authored-by: notoraptor <stevenbocco@gmail.com>
Diffstat (limited to 'diplomacy/server/connection_handler.py')
-rw-r--r-- | diplomacy/server/connection_handler.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/diplomacy/server/connection_handler.py b/diplomacy/server/connection_handler.py index a70db7d..2b2ae4d 100644 --- a/diplomacy/server/connection_handler.py +++ b/diplomacy/server/connection_handler.py @@ -33,6 +33,7 @@ LOGGER = logging.getLogger(__name__) class ConnectionHandler(WebSocketHandler): """ ConnectionHandler class. Properties: + - server: server object representing running server. """ # pylint: disable=abstract-method @@ -43,6 +44,7 @@ class ConnectionHandler(WebSocketHandler): def initialize(self, server=None): """ Initialize the connection handler. + :param server: a Server object. :type server: diplomacy.Server """ @@ -69,6 +71,7 @@ class ConnectionHandler(WebSocketHandler): parsed_origin = urlparse(origin) origin = parsed_origin.netloc.split(':')[0] origin = origin.lower() + # Split host with ':' and keep only first piece to ignore eventual port. host = self.request.headers.get("Host").split(':')[0] return origin == host @@ -89,6 +92,7 @@ class ConnectionHandler(WebSocketHandler): @staticmethod def translate_notification(notification): """ Translate a notification to an array of notifications. + :param notification: a notification object to pass to handler function. See diplomacy.communication.notifications for possible notifications. :return: An array of notifications containing a single notification. @@ -103,8 +107,10 @@ class ConnectionHandler(WebSocketHandler): if not isinstance(json_request, dict): raise ValueError("Unable to convert a JSON string to a dictionary.") except ValueError as exc: - # Error occurred because either message is not a JSON string or parsed JSON object is not a dict. - response = responses.Error(message='%s/%s' % (type(exc).__name__, str(exc))) + # Error occurred because either message is not a JSON string + # or parsed JSON object is not a dict. + response = responses.Error(error_type=exceptions.ResponseException.__name__, + message=str(exc)) else: try: request = requests.parse_dict(json_request) @@ -118,7 +124,8 @@ class ConnectionHandler(WebSocketHandler): response = responses.Ok(request_id=request.request_id) except exceptions.ResponseException as exc: - response = responses.Error(message='%s/%s' % (type(exc).__name__, exc.message), + response = responses.Error(error_type=type(exc).__name__, + message=exc.message, request_id=json_request.get(strings.REQUEST_ID, None)) if response: |