Skip to content

Commit

Permalink
Merge ffaa617 into 8c80ab8
Browse files Browse the repository at this point in the history
  • Loading branch information
rossengeorgiev committed Oct 27, 2018
2 parents 8c80ab8 + ffaa617 commit 9d1d1a5
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions steam/client/builtins/unified_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def __init__(self, *args, **kwargs):
self.unified_messages = SteamUnifiedMessages(self, name) #: instance of :class:`SteamUnifiedMessages`


class UnifiedMessageError(object):
def __init__(self, eresult, message):
self.eresult = eresult
self.message = message

def __repr__(self):
return "%s(%s, %s)" % (self.__class__.__name__, self.eresult, repr(self.message))

def __str__(self):
return self.message


class SteamUnifiedMessages(EventEmitter):
"""Simple API for send/recv of unified messages
Expand Down Expand Up @@ -66,18 +78,21 @@ def _handle_client_service_method(self, message):
self._LOG.error("Unable to find proto for %s" % repr(method_name))
return

error = None
if message.header.eresult != EResult.OK:
self._LOG.error("%s (%s): %s" % (method_name, repr(EResult(message.header.eresult)),
message.header.error_message))
error = UnifiedMessageError(EResult(message.header.eresult),
message.header.error_message)

resp = proto()
resp.ParseFromString(message.body.serialized_method_response)

self.emit(method_name, resp)
self.emit(method_name, resp, error)

jobid = message.header.jobid_target
if jobid not in (-1, 18446744073709551615):
self.emit("job_%d" % jobid, resp)
self.emit("job_%d" % jobid, resp, error)

def get(self, method_name):
"""Get request proto instance for given methed name
Expand Down Expand Up @@ -113,7 +128,7 @@ def send(self, message, params=None):
if isinstance(message, str):
message = self.get(message)
if message not in self._data:
raise ValueError("Supplied message seems to be invalid. Did you use 'get' method?")
raise ValueError("Supplied message is invalid. Use 'get' method.")

if params:
proto_fill_from_dict(message, params)
Expand All @@ -138,12 +153,12 @@ def send_and_wait(self, message, params=None, timeout=None, raises=False):
:param raises: (optional) On timeout if :class:`False` return :class:`None`, else raise :class:`gevent.Timeout`
:type raises: :class:`bool`
:return: response proto message instance
:rtype: proto message, :class:`None`
:rtype: (proto message, :class:`.UnifiedMessageError`)
:raises: :class:`gevent.Timeout`
"""
job_id = self.send(message, params)
resp = self.wait_event(job_id, timeout, raises=raises)
if resp is None and not raises:
return None
else:
return resp[0]
return resp

0 comments on commit 9d1d1a5

Please sign in to comment.