def application_factory(main_module_name, config_file=None): """ Create an application instance and register all routes. """ app = create_app_func(main_module_name, config_file) # Application convention: Every application route is set in a routes.py module under its related package. for loader, module_name, ispkg in pkgutil.iter_modules(path=[constants.APPLICATION_DIR]): if ispkg: try: importlib.import_module('.routes', package='api.' + module_name) except ImportError: continue # Register all application routes automatically. for route in Router.__subclasses__(): route(api) # Initialize Api and register blueprint after the routes registration. api_blueprint = Blueprint('api', main_module_name) api.init_app(api_blueprint) app.register_blueprint(api_blueprint, url_prefix='/api') return app
def show_videos(event_code): return [{ 'label': video.title + ' [COLOR mediumslateblue]' + video.presenter_names() + '[/COLOR]', 'path': video.url(), 'is_playable': True } for video in Router.videos(event_code) if video.is_available()]
def index(): return [{ 'label': event.name() + ' [COLOR mediumslateblue]' + event.pretty_range() + '[/COLOR]', 'path': plugin.url_for('show_videos', event_code=event.code()), #'icon': '' } for event in Router.events()]
import api.schema as s from api.exceptions import RequestParseError from api.spec import Spec, Response from api.views import ApiView, Method from api.router import Router from django.conf import settings from django.contrib.auth import authenticate, login, logout from django.db.models import Q from django.shortcuts import redirect from . import signals from .models import User from .utils import random_key import copy router = Router(namespace='api') Errors = s.Object(errors=s.Array(s.String()), ) UserDef = s.Definition( 'User', s.Object( id=s.Integer(), email=s.String(), first_name=s.String(), short_name=s.String(), avatar=s.Optional(s.String()), )) class Signin(ApiView):
from api.router import Router if __name__ == '__main__': rt = Router() rt.listen("127.0.0.1", port=6001, ws_port=6002) # rt.set_domain("example.com") # 如果在服务器上使用 # rt.enable_debug() # 启用 Flask 调试 rt.run()
import api.schema as s from api.router import Router from api.spec import Spec, Response from api.views import ApiView, Method router = Router() class GetMethod(ApiView): """sample view doc""" spec = Spec(Method.GET, s.Empty, Response(204, description='okay')) def handle(self, data): return 204 class PostMethod(ApiView): spec = Spec(Method.POST, s.Empty, Response(204)) def handle(self, data): return 204 class InContractView(ApiView): spec = Spec(Method.GET, s.Query(foo=s.Number()), Response(204)) def handle(self, data): return 204
import os import sys import webbrowser from threading import Timer from api.router import Router def open_index(): """打开浏览器""" index = "file://" + os.path.dirname(os.path.realpath( sys.argv[0])) + "/web/index.html" webbrowser.open(index) if __name__ == '__main__': rt = Router() rt.listen("127.0.0.1", 6001) rt.enable_debug() Timer(1, open_index).start() rt.run()
from operator import attrgetter from flask import Flask from api.db import (select_episode_by_season_and_episode_ids, select_episodes_by_season_id, select_ids_to_seasons) from api.decorators import jsonify, search, sortable from api.encoder import AppEncoder from api.router import Router app = Flask(__name__) app.json_encoder = AppEncoder router = Router(app) @router.route('/') @jsonify def index(): return router @router.route('/seasons') @jsonify @sortable('id', 'synopsis') @search('id') def index_seasons(): return list(select_ids_to_seasons().values()) @router.route('/seasons/<int:season_id>')