Slightly reduce the insane amounts of indentation in main http server response path, by 'continue'ing around a non-match or falling through

This commit is contained in:
Paul "LeoNerd" Evans 2015-03-05 16:24:13 +00:00
parent dc4b774f1e
commit 9d9d39536b

View File

@ -124,27 +124,29 @@ class JsonResource(HttpServer, resource.Resource):
# and path regex match # and path regex match
for path_entry in self.path_regexs.get(request.method, []): for path_entry in self.path_regexs.get(request.method, []):
m = path_entry.pattern.match(request.path) m = path_entry.pattern.match(request.path)
if m: if not m:
# We found a match! Trigger callback and then return the continue
# returned response. We pass both the request and any
# matched groups from the regex to the callback.
args = [ # We found a match! Trigger callback and then return the
urllib.unquote(u).decode("UTF-8") for u in m.groups() # returned response. We pass both the request and any
] # matched groups from the regex to the callback.
logger.info( args = [
"Received request: %s %s", urllib.unquote(u).decode("UTF-8") for u in m.groups()
request.method, request.path ]
)
code, response = yield path_entry.callback( logger.info(
request, "Received request: %s %s",
*args request.method, request.path
) )
self._send_response(request, code, response) code, response = yield path_entry.callback(
return request,
*args
)
self._send_response(request, code, response)
return
# Huh. No one wanted to handle that? Fiiiiiine. Send 400. # Huh. No one wanted to handle that? Fiiiiiine. Send 400.
raise UnrecognizedRequestError() raise UnrecognizedRequestError()