Skip to content

Commit

Permalink
Respond to new feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sadielbartholomew committed May 3, 2019
1 parent 46abd56 commit ace9155
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions lib/python/rosie/ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,34 @@ def __init__(self, service_root_mode=False, *args, **kwargs):
self.db_url_map = db_url_map

# Specify the root URL for the handlers and template.
self.service_root = r"/"
ROOT = "%s-%s" % (self.NAMESPACE, self.UTIL)
service_root = r"/?"
if self.service_root_mode:
service_root += ROOT + r"/?"
self.service_root += ROOT + r"/"

# Set-up the Tornado application request-handling structure.
prefix_handlers = []
class_args = {"props": self.props}
root_class_args = dict(class_args) # mutable so copy for safety
root_class_args.update({"db_url_map": self.db_url_map})
root_handler = (service_root, RosieDiscoServiceRoot, root_class_args)
root_handler = (
self.service_root, RosieDiscoServiceRoot, root_class_args)
for key, db_url in list(self.db_url_map.items()):
prefix_class_args = dict(class_args) # mutable so copy for safety
prefix_class_args.update({
"prefix": key,
"db_url": db_url,
"service_root": service_root,
"service_root": self.service_root,
})
handler = (service_root + key + r"/?", RosieDiscoService,
handler = (self.service_root + key + r"/?", RosieDiscoService,
prefix_class_args)
get_handler = (service_root + key + r"/get_(.+)", GetHandler,
get_handler = (self.service_root + key + r"/get_(.+)", GetHandler,
prefix_class_args)
hello_handler = (service_root + key + r"/hello/?", HelloHandler,
prefix_class_args)
search_handler = (service_root + key + r"/search", SearchHandler,
prefix_class_args)
query_handler = (service_root + key + r"/query", QueryHandler,
hello_handler = (self.service_root + key + r"/hello/?",
HelloHandler, prefix_class_args)
search_handler = (self.service_root + key + r"/search",
SearchHandler, prefix_class_args)
query_handler = (self.service_root + key + r"/query", QueryHandler,
prefix_class_args)
prefix_handlers.extend(
[handler, get_handler, hello_handler, search_handler,
Expand Down Expand Up @@ -244,12 +245,12 @@ class GetHandler(RosieDiscoService):
"optional_keys", # Return the names of the optional fields.
]

def get(self, get_arg):
def get(self, *args):
"""Return data for basic API points of query keys without values."""
format_arg = self.get_query_argument("format", default=None)
if get_arg and format_arg == "json":
if args[0] and format_arg == "json":
for query in self.QUERY_KEYS:
if get_arg.startswith(query):
if args[0].startswith(query):
# No need to catch AttributeError as all QUERY_KEYS valid.
self.write(json.dumps(getattr(self.dao, "get_" + query)()))

Expand Down Expand Up @@ -294,7 +295,7 @@ class QueryHandler(RosieDiscoService):

"""Serves a query of the database on the page of a given prefix."""

def get(self):
def get(self, *args):
"""Search database for rows with data matching the query string."""
q_args = self.get_query_arguments("q") # empty list if none given
all_revs = self.get_query_argument("all_revs", default=0)
Expand Down Expand Up @@ -462,8 +463,15 @@ def main():
_log_app_base(*app_info, "tornado.application", ".error")

tornado.log.gen_log.info("Started" + log_msg_end)
# Call print before IOLoop start() else it prints only on loop stop.
# Call to print before IOLoop start() else it prints only on loop stop.
print("Started" + user_msg_end)
append_url_root = ""
if app.service_root_mode:
append_url_root = "%s-%s/" % (app.NAMESPACE, app.UTIL)
# Also print the URL for quick access; 'http://' added so that the URL
# is hyperlinked in the terminal stdout, but it is not required.
print("Application root page available at http://%s:%s/%s" % (
app.props["host_name"], port, append_url_root))

IOLoop.current().start()
elif instruction == "stop" and (
Expand Down

0 comments on commit ace9155

Please sign in to comment.