<commit_before># -*- coding: utf-8 -*-

__version__ = '0.1.1'

from flask.views import MethodView
from flask import Blueprint

AUTOREST_BLUEPRINT_NAME = 'autorest'
AUTOREST_URL_PREFIX = '/autorest'


class AutoRest(object):

    def __init__(self, app=None):
        """init with app

        :app: Flask instance

        """
        if app:
            self.init_app(app)

    def init_app(self, app):
        """
        安装到app上
        """

    def create_blueprint(self, app, sources):
        """
        生成一个blueprint
        """
        blueprint_name = app.config.get('AUTOREST_BLUEPRINT_NAME') or AUTOREST_BLUEPRINT_NAME
        url_prefix = app.config.get('AUTOREST_URL_PREFIX') or AUTOREST_URL_PREFIX
        sources = app.config.get('AUTOREST_SOURCES')

        bp = Blueprint(blueprint_name, __name__, url_prefix=url_prefix)


class ResourceView(MethodView):
    """
    /resource/<id>
    """
    pass


class ResourceListView(MethodView):
    """
    /resource/
    """<commit_msg>貌似框架写好了<commit_after># -*- coding: utf-8 -*-
"""
AUTOREST_SOURCES:
    {
        'test': {
            'uri': 'mysql://root:@localhost/flask_dpl',
            'tables': {
                'user': {
                    'pk': 'id',
                }
            }
        }
    }
AUTOREST_BLUEPRINT_NAME
AUTOREST_URL_PREFIX
"""

__version__ = '0.1.1'

from flask.views import MethodView
from flask import Blueprint

AUTOREST_BLUEPRINT_NAME = 'autorest'
AUTOREST_URL_PREFIX = '/autorest'


class AutoRest(object):

    def __init__(self, app=None):
        """init with app

        :app: Flask instance

        """
        if app:
            self.init_app(app)

    def init_app(self, app):
        """
        安装到app上
        """
        bp = self.create_blueprint(app)

        app.register_blueprint(bp)

    def create_blueprint(self, app):
        """
        生成一个blueprint
        """
        blueprint_name = app.config.get('AUTOREST_BLUEPRINT_NAME') or AUTOREST_BLUEPRINT_NAME
        url_prefix = app.config.get('AUTOREST_URL_PREFIX') or AUTOREST_URL_PREFIX
        sources = app.config.get('AUTOREST_SOURCES')

        bp = Blueprint(blueprint_name, __name__, url_prefix=url_prefix)

        for db_name, db_conf in sources.items():
            for tb_name, tb_conf in db_conf.items():
                pk_name = tb_conf.get('pk') or 'id'

                bp.add_url_rule('/%s/%s/<pk>' % (db_name, tb_name),
                                view_func=ResourceView.as_view('%s_%s' % (db_name, tb_name), pk_name=pk_name))

                bp.add_url_rule('/%s/%s' % (db_name, tb_name),
                                view_func=ResourceView.as_view('%s_%s_list' % (db_name, tb_name)))

        return bp


class ResourceView(MethodView):
    """
    /resource/<id>
    """
    def __init__(self, pk_name):
        self.pk_name = pk_name
        super(ResourceView, self).__init__()

    def get(self, pk):
        return str(pk)


class ResourceListView(MethodView):
    """
    /resource/
    """

    def get(self):
        return 'list'
{'fraction_non_alphanumeric': 0.12495889510029595, 'fraction_numerical': 0.0026307135810588623, 'mean_word_length': 2.1621621621621623, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5078744', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1014, 'n_words': 178}