Overhaul to work with Highway

create_routes now doesn't launch them automatically because routes are put together before the socket actually becomes avaliable.
create_exchange_map previously used the wrong index for the route list.
There is now a universal Route class from which ServerRoute and ClientRoute inherit.
This commit is contained in:
Philip Trauner 2016-09-18 19:49:53 +02:00
parent 058bc81b99
commit ab6444f118

View file

@ -13,13 +13,7 @@ class InvalidRouteLength(AttributeError):
super(AttributeError, self).__init__(msg) super(AttributeError, self).__init__(msg)
class ServerRoute: class Route:
REQUIRED = []
PATCHED = False
def __init__(self, **kwargs):
pass
def run(self, data, handler): def run(self, data, handler):
pass pass
@ -27,9 +21,13 @@ class ServerRoute:
pass pass
class ClientRoute: class ServerRoute(Route):
def run(self, data, handler): REQUIRED = []
pass PATCHED = False
class ClientRoute(Route):
pass
def create_routes(routes, handler): def create_routes(routes, handler):
@ -48,12 +46,25 @@ def create_routes(routes, handler):
elif required == ROUTE: elif required == ROUTE:
routes[prefix].route = reverse_routes[routes[prefix]] routes[prefix].route = reverse_routes[routes[prefix]]
routes[prefix].PATCHED = True routes[prefix].PATCHED = True
routes[prefix].start(handler)
return routes return routes
def launch_routes(created_routes, handler):
for prefix in created_routes:
created_routes[prefix].start(handler)
def create_exchange_map(routes): def create_exchange_map(routes):
exchange_map = {"meta" : -1} exchange_map = {-1 : "meta"}
for route in range(len(routes)): exchange_id = 0
exchange_map[route] = routes[route] for route in routes:
exchange_map[exchange_id] = route
exchange_id += 1
return exchange_map return exchange_map
def validate_exchange_map(routes):
for key in routes:
if not type(key) is int and type(routes[key]) is str:
return False
return True