From 6ed3e2b344cf01d4a3e342000cf6da8e735bab78 Mon Sep 17 00:00:00 2001 From: Nick Daly Date: Wed, 30 May 2012 16:29:03 -0500 Subject: [PATCH] Removed unnecessary test file. --- .../protocols/https/controller_test.py | 222 ------------------ 1 file changed, 222 deletions(-) delete mode 100644 ugly_hacks/santiago/protocols/https/controller_test.py diff --git a/ugly_hacks/santiago/protocols/https/controller_test.py b/ugly_hacks/santiago/protocols/https/controller_test.py deleted file mode 100644 index e30a69926..000000000 --- a/ugly_hacks/santiago/protocols/https/controller_test.py +++ /dev/null @@ -1,222 +0,0 @@ -"""The HTTPS Santiago listener and sender. - -TODO: Build out /consuming too. -TODO: build out the rest of the actions. - -""" - - -from Cheetah.Template import Template -import cherrypy -import httplib, urllib, urlparse -import sys -import logging -import wsgiref.handlers - - -mykey = str(8) -hosting_data = { mykey: { "santiago": set( ["https://localhost:8080"] )}} -consuming_data = { "santiago": { mykey: set( ["https://localhost:8080"] )}} - - -def setup(santiago): - # TODO call this bugger to prep the dispatcher, objects, etc. - pass - - -class RestController(object): - - def PUT(self, *args, **kwargs): - raise NotImplemented("RestController.PUT") - - def GET(self, *args, **kwargs): - raise NotImplemented("RestController.GET") - - def POST(self, *args, **kwargs): - raise NotImplemented("RestController.POST") - - def DELETE(self, *args, **kwargs): - raise NotImplemented("RestController.DELETE") - -class Root(RestController): - - def GET(self): - return """\ - - -

Welcome to FreedomBuddy!

-

You can:

- - - -""" - -class Consuming(RestController): - exposed = True - - def __init__(self, data): - self.consuming = data - - def GET(self): - services = self.consuming.iterkeys() - - return [str(Template( - file="templates/consuming-get.tmpl", - searchList=[{ - "services": services }]))] - -class ConsumedService(RestController): - exposed = True - - def __init__(self, data): - self.consuming = data - - def GET(self, service=""): - try: - hosts = self.consuming[service].iterkeys() - except KeyError: - hosts = [] - finally: - return [str(Template( - file="templates/consumedService-get.tmpl", - searchList=[{ - "service": service, - "hosts": hosts }]))] - -class ConsumedHost(RestController): - exposed = True - - def __init__(self, data): - self.consuming = data - - def GET(self, service="", host=""): - try: - locations = [x for x in self.consuming[service][host]] - except KeyError: - locations = [] - finally: - return [str(Template( - file="templates/consumedLocation-get.tmpl", - searchList=[{ - "service": service, - "host": host, - "locations": locations }]))] - -class Hosting(RestController): - exposed = True - - def __init__(self, data): - self.hosting = data - - def GET(self): - clients = self.hosting.keys() - - return [str(Template( - file="templates/hosting-get.tmpl", - searchList=[{ - "clients": clients, }]))] - -class Client(object): - exposed = True - - def __init__(self, data): - self.hosting = data - - def GET(self, client=0): - try: - services = [x for x in self.hosting[client]] - message = "success" - except KeyError: - services = [] - message = "Error." - finally: - return [str(Template( - file="templates/client-get.tmpl", - searchList=[{ - "client": client, - "services": services, - "message": message }]))] - -class HostedService(object): - exposed = True - - def __init__(self, data): - self.hosting = data - - def GET(self, client=0, service=""): - try: - locations = [x for x in self.hosting[client][service]] - message = "success" - except KeyError: - locations = [] - message = "Error." - finally: - return [str(Template( - file="templates/hostedService-get.tmpl", - searchList=[{ - "client": client, - "service": service, - "locations": locations, - "message": message }]))] - -class Location(object): - exposed = True - - def __init__(self, data): - self.hosting = data - - def GET(self, client=0, service=0, location=0): - try: - location = self.hosting[client][service].find(location) - message = "success" - except KeyError: - location = "" - message = "error" - return [str(Template( - file="templates/location-get.tmpl", - searchList=[{ - "client": client, - "service": service, - "location": location, - "message": message, }]))] - -def rest_connect(dispatcher, location, controller, trailing_slash=True): - """Simple REST connector for object/location mapping.""" - - if trailing_slash: - location = location.rstrip("/") - location = [location, location + "/"] - else: - location = [location] - - for place in location: - for a_method in ("PUT", "GET", "POST", "DELETE"): - dispatcher.connect(controller.__class__.__name__ + a_method, - place, controller=controller, action=a_method, - conditions={ "method": [a_method] }) - - return dispatcher - - -if __name__ == "__main__": - - d = cherrypy.dispatch.RoutesDispatcher() - - routing_pairs = (('/hosting/:client/:service/:location', Location(hosting_data)), - ('/hosting/:client/:service', HostedService(hosting_data)), - ('/hosting/:client', Client(hosting_data)), - ('/hosting', Hosting(hosting_data)), - ('/consuming/:service/:host', ConsumedHost(consuming_data)), - ('/consuming/:service', ConsumedService(consuming_data)), - ('/consuming', Consuming(consuming_data)), - ("/", Root()), ) - - for location, handler in routing_pairs: - rest_connect(d, location, handler) - - cherrypy.config.update({"server.socket_host": "0.0.0.0"}) - - cherrypy.quickstart(root, "/", { "/": {'request.dispatch': d, }})