Skip to content

Commit

Permalink
Add missing docstrings for BaseServerQuerier
Browse files Browse the repository at this point in the history
  • Loading branch information
Holiverh committed Sep 9, 2017
1 parent 7ee9b63 commit 7ee58a3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion valve/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class NoResponseError(Exception):


class BaseServerQuerier(object):
"""Base class for implementing source server queriers.
:ivar host: Host requests will be sent to.
:ivar port: Port number requests will be sent to.
:ivar timeout: How long to wait for a response to a request.
"""

def __init__(self, address, timeout=5.0):
self.host = address[0]
Expand All @@ -24,11 +30,18 @@ def request(self, request):
self.socket.sendto(request.encode(), (self.host, self.port))

def get_response(self):
"""Wait for a response to a request.
:raises NoResponseError: If the configured :attr:`timeout` is
reached before a response is received.
:returns: The raw response as a :class:`bytes`.
"""
ready = select.select([self.socket], [], [], self.timeout)
if not ready[0]:
raise NoResponseError("Timed out waiting for response")
try:
data = ready[0][0].recv(1400)
except socket.error as exc:
raise NoResponseError(exc)
raise NoResponseError(exc) from exc
return data

0 comments on commit 7ee58a3

Please sign in to comment.