Example #1
0
    def __init__(self, bot):
        self.bot = bot

        self.cfg = PluginConfig(self)
        self.db = FileBackend(self.cfg.get('main_db'))

        mtt = MessageRetargeter(bot)
        self.msg = mtt.msg

        web = Flask(__name__, template_folder=tmpl_dir)
        mako = MakoTemplates()
        mako.init_app(web)

        # Add routes here
        web.add_url_rule('/edit_web/<args>', 'edit_web', self.edit_web, methods=['GET', 'POST'])

        _thread.start_new_thread(web.run, (), {'host': '0.0.0.0'})
Example #2
0
    def create_lookup(app):
        lookup = Base.create_lookup(app)
        lookup.default_filters = ['unicode_safe']
        
        get_template = lookup.get_template
        def new_get_template(name):
            g._mako_template_name = name
            return get_template(name)
        lookup.get_template = new_get_template
        
        lookup.template_args['preprocessor'] = preprocessor

        return lookup
class MustInheritFromStatdatabase(Exception):
    pass

if __name__ == "__main__":
    import ssl

    app.config.from_pyfile("settings.cfg")
    LOGGER = logging.getLogger("alservice")
    hdlr = logging.FileHandler(app.config["LOG_FILE"])
    base_formatter = logging.Formatter("[%(asctime)-19.19s] [%(levelname)-5.5s]: %(message)s")
    hdlr.setLevel(app.config["LOG_LEVEL"])
    hdlr.setFormatter(base_formatter)
    LOGGER.addHandler(hdlr)
    LOGGER.setLevel(logging.DEBUG)
    mako = MakoTemplates()
    mako.init_app(app)
    app._mako_lookup = TemplateLookup(directories=["templates"],
                                      input_encoding='utf-8', output_encoding='utf-8',
                                      imports=["from flask.ext.babel import gettext as _"])
    context = None
    if app.config['SSL']:
        context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
        context.load_cert_chain(app.config["SERVER_CERT"], app.config["SERVER_KEY"])
    global keys
    global stat_service
    global base
    keys = []
    for key in app.config["JWT_PUB_KEY"]:
        _bkey = rsa_load(key)
        pub_key = RSAKey().load_key(_bkey)