diff --git a/lib/util.py b/lib/util.py index 7c2fca5..43a54c6 100644 --- a/lib/util.py +++ b/lib/util.py @@ -4,3 +4,11 @@ import json def parse_anchor_from_message(message): message_json = json.loads(message) return message_json['anchor'] + + +def create_source_code_response_data(filename, content, language): + return { + 'filename': filename, + 'content': content, + 'language': language + } \ No newline at end of file diff --git a/src/event_handlers/event_handler_main.py b/src/event_handlers/event_handler_main.py index e7ca7e3..8ef9f1d 100644 --- a/src/event_handlers/event_handler_main.py +++ b/src/event_handlers/event_handler_main.py @@ -1,12 +1,19 @@ import codecs import sqlite3 +from functools import partial import source_code from event_handler import EventHandler +from source_code_event_handler import SourceCodeEventHandler from stateful_event_handler import StatefulEventHandler from tornado.ioloop import IOLoop from login_component import authorize_login +from util import create_source_code_response_data + +login_component_py_response = partial( + create_source_code_response_data, filename='login_component.py', language='python' +) def echo_handler(data): @@ -38,7 +45,7 @@ def login_handler(data): ) yield ('anchor_webide', - source_code.get_source_code(authorize_login, strip_comments=False)) + login_component_py_response(content=source_code.get_source_code(authorize_login, strip_comments=False))) sql_statement_with_values = sql_statement.format(email, password) yield ( @@ -70,16 +77,11 @@ def login_handler(data): yield ('anchor_login', '# Login page\n' + response) -def source_code_handler(data): - yield (data['anchor'], - source_code.get_source_code(authorize_login, strip_comments=True)) - - if __name__ == '__main__': anchor_a = EventHandler('anchor_a', change_case_handler) anchor_b = EventHandler('anchor_b', rot13_handler) anchor_c = EventHandler('anchor_c', reverse_handler) anchor_login = StatefulEventHandler('anchor_login', login_handler) - anchor_webide = StatefulEventHandler('anchor_webide', source_code_handler) + anchor_webide = SourceCodeEventHandler('anchor_webide', 'login_component.py', 'login') IOLoop.instance().start()