Skip to content

Commit

Permalink
Restructure the mercury/hermes request/response system (assume return…
Browse files Browse the repository at this point in the history
…ed items match request)
  • Loading branch information
fuzeman committed Aug 4, 2014
1 parent aa444ec commit 4b6360f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions spotify/hermes/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ def cached_response(self, request):

return True

def update_response(self, index, header, content_type, internal):
def update_response(self, request, header, content_type, internal):
uri = None

if type(internal) is dict:
if request and request.uri:
uri = request.uri
elif type(internal) is dict:
uri = internal.get('uri')
else:
uri = cache.get_object_uri(content_type, internal)

if uri is None and index < len(self.prepared_requests):
# Fallback to original request uri
uri = self.prepared_requests[index].uri

if not uri:
# URI doesn't look valid
raise NotImplementedError()
Expand All @@ -48,3 +46,5 @@ def update_response(self, index, header, content_type, internal):

# Store in cache for later use
cache.store(header, content_type, internal)

return uri
10 changes: 7 additions & 3 deletions spotify/mercury/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def reply(self, header, data):
items = self.reply_mercury(header.content_type, data)

for x, (content_type, internal) in enumerate(items):
self.update_response(x, header, content_type, internal)
uri = self.update_response(
self.prepared_requests[x], header,
content_type, internal
)

self.respond()

Expand Down Expand Up @@ -264,8 +267,9 @@ def parse_request(request):
def cached_response(self, request):
return False

def update_response(self, index, header, content_type, internal):
self.response[internal.gid] = (content_type, internal)
def update_response(self, request, header, content_type, internal):
self.response[request.uri] = (content_type, internal)
return request.uri

def __repr__(self):
return "<%s uris: %s>" % (
Expand Down

0 comments on commit 4b6360f

Please sign in to comment.