def main(): logger.debug("router begining...") while True: router = Router() router.run() time.sleep(5) logger.debug("router end.") os._exit(0) # fix :there are threads, not exit properly
def test_model_router(self): router = Router() handler_name = 'handler' router.register(handler_name, TestRestHandler) self.assertItemsEqual( [('^/{}/$'.format(handler_name), TestRestHandler), ('^/{}$'.format(handler_name), TestRestHandler), ('^/{}/(?P<key>[^/]+)/$'.format(handler_name), TestRestHandler), ('^/{}/(?P<key>[^/]+)$'.format(handler_name), TestRestHandler)], router.urls)
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() ndb.get_context().clear_cache() router = Router() router.register('user', APIUserHandler) app = webapp3.WSGIApplication(router.urls) self.testapp = webtest.TestApp(app)
def test_set_route_grouping(self): with Router(group='/prefix') as routes: routes.register('/test1') for route in routes: self.assertEqual('/prefix/test1', route[0])
def setUp(self): self.testbed = testbed.Testbed() self.testbed.activate() self.testbed.init_datastore_v3_stub() self.testbed.init_memcache_stub() ndb.get_context().clear_cache() router = Router() router.register('user', UserApi) app = webapp3.WSGIApplication(router.urls) self.testapp = webtest.TestApp(app) self.entity = User(email='*****@*****.**', first_name='admin', last_name='test', age=28) self.entity.put()
def test_set_route_no_group(self): with Router() as routes: routes.register('/test1') self.assertTrue(len(routes) == 1) for route in routes: self.assertEqual('/test1', route[0]) self.assertEqual(None, route[1])
def index(): params = request.args.to_dict() if 'updateFunction' in params: state = Store().getState(params['updateFunction']) state.value = state.modifier(state.value) return (str(state.value)) elif 'router' in params and 'path' in params: router = params['router'] routeName = params['path'] response = { "path": "/" + router + routeName, "body": str(Router().render(router, routeName)) } return (json.dumps(response)) return warnings.warn( "PizzaPy Virtual DOM does not implement the given parameters")
from core.router import Router from server.apps.comments.views import IndexView, CommentAddView, StatisticView, CommentView, RegionView, DeleteComment router = Router(__file__) router.add_route(r'^/$', IndexView()) router.add_route(r'^/index$', IndexView()) router.add_route(r'^/comment$', CommentAddView()) router.add_route(r'^/stat$', StatisticView()) router.add_route(r'^/stat?id=\d*', StatisticView()) router.add_route(r'^/view$', CommentView()) router.add_route(r'^/comment/delete$', DeleteComment()) router.add_route(r'^/region$', RegionView())
from aiohttp import web from core.helpers.loader import import_modules from core.router import Router import core.settings as settings app = web.Application( router=Router(middlewares=import_modules(settings.route_middlewares)), middlewares=import_modules(settings.middlewares), ) loop = app.loop
from src.controller.category import * from core.router import Router category_router = Router() category_router.get("", get_all_categories) category_router.get("/<int:category_id>", get_category_by_id)
def counterPage(route=None): return Div(className="container", children=[Router().render("counter", route)])
# 'middleware.authRequest.AuthRequest', 'middleware.registerRequest.RegisterRequest', 'middleware.cors.CORSRequest', ) def applyMiddleware(app): modules = [('.'.join(module.split('.')[:-1]), '.'.join(module.split('.')[-1:])) for module in middleware] for module, f in modules: module = __import__(module, fromlist=[f]) app = getattr(module, f)(app) return app hello_world = Router() hello_world.add_route('/hello/{name:\w*}', controller=Hello) hello_world = applyMiddleware(hello_world) if __name__ == '__main__': import doctest from wsgiref.simple_server import make_server doctest.testmod() print('serving') server = make_server('127.0.0.1', 8080, hello_world) server.serve_forever()
from core.router import Router from src.route.user import user_router from src.route.category import category_router from src.route.routine import routine_router from src.route.event import event_router from src.route.activity import activity_router from src.route.location import location_router from src.route.schedule import schedule_router group_router = Router() group_router.group("/user", user_router) group_router.group("/category", category_router) group_router.group("/routine", routine_router) group_router.group("/event", event_router) group_router.group("/activity", activity_router) group_router.group("/location", location_router) group_router.group("/schedule", schedule_router) __all__ = [group_router]
from src.controller.user import * from src.middleware.auth import AuthMiddleware from core.router import Router # Normal user for sano user_router = Router() user_router.post("/login", login) user_router.post("/register", register) user_router.get("/profile", AuthMiddleware(), get_profile)
from src.controller.activity import * from core.router import Router activity_router = Router() activity_router.get("", get_all_activities)
import os import sys from wsgiref.simple_server import make_server from core.router import Router base = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(base) class Application(object): def __init__(self, router): self.router = router def __call__(self, env, start_response): return self.router.handle(env, start_response) router = Router() app = Application(router) http = make_server('localhost', 8000, app) http.serve_forever()
def test_empty_routes(self): r = Router() self.assertTrue(len(r) == 0) with self.assertRaises(StopIteration): r.next()
from core.router import Router from src.controller.routine import * routine_router = Router() routine_router.get("", get_routines) routine_router.get("/<int:routine_id>", get_routine_by_id)
from handler.scholar import routes as scholar_routes from handler.scholar_app import routes as scholar_app_routes from handler.sponsor_app import routes as sponsor_app_routes from handler.board import routes as board_routes from core.router import Router from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app) router = Router(app) router.get('/', lambda: 'Hello World!') router.group('/scholar', scholar_routes) router.group('/scholar_app', scholar_app_routes) router.group('/sponsor_app', sponsor_app_routes) router.group('/board', board_routes) if __name__ == '__main__': router.execute() app.run(port=8888)
middleware = ( # 'middleware.authRequest.AuthRequest', 'middleware.registerRequest.RegisterRequest', 'middleware.cors.CORSRequest', ) def applyMiddleware(app): modules = [('.'.join(module.split('.')[:-1]), '.'.join(module.split('.')[-1:])) for module in middleware] for module, f in modules: module = __import__(module, fromlist=[f]) app = getattr(module, f)(app) return app hello_world = Router() hello_world.add_route('/hello/{name:\w*}', controller=Hello) hello_world = applyMiddleware(hello_world) if __name__ == '__main__': import doctest from wsgiref.simple_server import make_server doctest.testmod() print('serving') server = make_server('127.0.0.1', 8080, hello_world) server.serve_forever()
from core.router import Router from src.controller.location import * from src.controller.marathon import * location_router = Router() location_router.post("/marathon", add_marathon) location_router.get("/<int:location_id>", get_location_by_id) location_router.get("/search", search_location)
from flask import Flask from dotenv import load_dotenv from flask_cors import CORS from threading import Thread from core.router import Router from model import db from endpoint import endpoints from chat_socket.chat import chat_server_start app = Flask(__name__) CORS(app) router = Router(app) load_dotenv() @app.before_request def before(): if db.is_closed(): db.connect() @app.after_request def after(req): if not db.is_closed(): db.close() return req for group_name, group_endpoints in endpoints.items():
from pages.counter import counterPage from pages.matplotlib_page import matplotlibPage from core.singletons.store import Store from window import Window from flask import Flask, render_template, request app = Flask(__name__, template_folder='static') app.register_blueprint(handleDOM) counterRoutes = [ SingleRoute("/", HomeComponent), SingleRoute("/pag1", CounterComponent, [1, True]), SingleRoute("/pag2", CounterComponent, [50, False]) ] Router().createRouter("counter", counterRoutes) @app.route("/") def index(): page = indexPage() return repr(Window(page)) # Window(component) # return render_template('index.html') @app.route("/counter/", defaults={"path": None}) @app.route("/counter/<path>") def counter(path): if path is not None: path = "/" + path
from core import Response from core.router import Router from core.template import render def hello(request, name=None): return render('index.html', {}) routes = Router() routes.add_route(r'/$', hello)
from core.router import Router from src.controller.event import * event_router = Router() event_router.get("", get_available_events) event_router.get("/<int:event_id>", get_event_by_id)
def tima(cmd, args): tima = Tima() from core.router import Router Router.command_route(tima, cmd, args)
from core.router import Router from src.controller.schedule import * schedule_router = Router() schedule_router.get("/<int:schedule_id>", get_schedule_by_id)
from flask import Flask from core.router import Router from flask_cors import CORS, cross_origin app = Flask(__name__) cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) Router.run(app)
def routes(self): with Router(handler=MongoHandler) as routes: routes.register(r"/mongo") return routes