#!/usr/bin/env python # import tornado.httpserver import tornado.ioloop import tornado.web import os import re import time import calendar import base64 import traceback import logging import cStringIO import json import cgi from urlparse import urlparse import server_config from storage_base import WeaveStorageException from weave_handler import WeaveHandler ################################################################## # Trivial Main Handler ################################################################## class MainHandler(WeaveHandler): def get(self): self.render("main.html", errorMessage=None) ################################################################## # Main Application Setup ################################################################## settings = { "static_path": os.path.join(os.path.dirname(__file__), "static"), "cookie_secret": "dfaDSGSLJGfsdlfselrfg532rsf24552ksgslkfjllj=", "login_url": "/login" # "xsrf_cookies": True, } ApplicationHandlers = [ (r"/", MainHandler) ] if server_config.host_functions_user: import weave_user_handlers ApplicationHandlers += [ (r"/user/1/([a-zA-Z0-9-_]+)/?", weave_user_handlers.UsernameRootHandler),# TODO note ambiguity about trailing slash (r"/user/1/([a-zA-Z0-9-_]+)/node/weave", weave_user_handlers.GetStorageNodeHandler), (r"/user/1/([a-zA-Z0-9-_]+)/email", weave_user_handlers.SetEmailHandler), (r"/user/1/([a-zA-Z0-9-_]+)/password", weave_user_handlers.SetPasswordHandler) ] if server_config.host_functions_storage: import weave_storage_handlers ApplicationHandlers += [ (r"/1.0/([a-zA-Z0-9-_]+)/info/collections", weave_storage_handlers.CollectionTimestampsHandler), (r"/1.0/([a-zA-Z0-9-_]+)/info/collection_counts", weave_storage_handlers.CollectionCountsHandler), (r"/1.0/([a-zA-Z0-9-_]+)/storage", weave_storage_handlers.StorageHandler), (r"/1.0/([a-zA-Z0-9-_]+)/storage/([a-zA-Z0-9_-]+)", weave_storage_handlers.CollectionHandler), (r"/1.0/([a-zA-Z0-9-_]+)/storage/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)", weave_storage_handlers.CollectionHandler) # with an ID... ] if server_config.host_functions_openid: import openid_handlers ApplicationHandlers += [ (r"/openid", openid_handlers.OpenIDServerEndpoint), (r"/openid/allow", openid_handlers.OpenIDAllowEndpoint), (r"/openid/([a-zA-Z0-9-_]+)", openid_handlers.OpenIDUserEndpoint) ] if server_config.host_functions_opensocial: import opensocial_handlers ApplicationHandlers += [ (r"/opensocial/rest/people/([a-zA-Z0-9-_]+)/(.*)", opensocial_handlers.OpenSocialPeopleHandler) ] if server_config.host_functions_webfinger: import webfinger_handlers ApplicationHandlers += [ (r"/([a-zA-Z0-9-_]+)/xrd", webfinger_handlers.XRDPageHandler) ] # Fire it up: application = tornado.web.Application(ApplicationHandlers, **settings) def run(): http_server = tornado.httpserver.HTTPServer(application) http_server.listen(80) tornado.ioloop.IOLoop.instance().start() import logging import sys if __name__ == '__main__': if '-test' in sys.argv: import doctest doctest.testmod() else: logging.basicConfig(level = logging.DEBUG) run()