How to use the muffin.plugins.BasePlugin function in muffin

To help you get started, we’ve selected a few muffin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github klen / muffin / tests / test_plugins.py View on Github external
def test_plugins():
    with pytest.raises(PluginException):
        BasePlugin()

    class Plugin(BasePlugin):
        name = 'plugin'
        defaults = {
            'debug': True
        }

    pl1 = Plugin(test=42)
    pl2 = Plugin(test=24)

    assert pl1 is pl2
    assert pl1.cfg.test == 42

    app = muffin.Application(__name__)
    app.install(pl1)
    assert pl1.name in app.ps
github klen / muffin / tests / test_plugins.py View on Github external
def test_plugins():
    with pytest.raises(PluginException):
        BasePlugin()

    class Plugin(BasePlugin):
        name = 'plugin'
        defaults = {
            'debug': True
        }

    pl1 = Plugin(test=42)
    pl2 = Plugin(test=24)

    assert pl1 is pl2
    assert pl1.cfg.test == 42

    app = muffin.Application(__name__)
    app.install(pl1)
    assert pl1.name in app.ps
github klen / muffin / muffin / plugins / peewee / __init__.py View on Github external
import asyncio
import concurrent
from functools import partial

import peewee
from playhouse.db_url import connect

from .migrate import Router, MigrateHistory
from .serialize import Serializer
from muffin.plugins import BasePlugin, PluginException
from muffin.utils import Structure


class PeeweePlugin(BasePlugin):

    """ Integrate peewee to bottle. """

    name = 'peewee'
    defaults = {
        'connection': 'sqlite:///db.sqlite',
        'max_connections': 2,
        'migrations_enabled': True,
        'migrations_path': 'migrations',
    }

    def __init__(self, **options):
        super().__init__(**options)

        self.database = peewee.Proxy()
        self.serializer = Serializer()
github klen / muffin-admin / muffin_admin / plugin.py View on Github external
from muffin_babel import Plugin as BPlugin

from .handler import AdminHandler


try:
    from .peewee import PWAdminHandler, pw
    PWModel = pw.Model
except Exception as exc:
    PWModel = None


PLUGIN_ROOT = op.dirname(op.abspath(__file__))


class Plugin(BasePlugin):

    """ Admin interface for Muffin Framework. """

    name = 'admin'
    defaults = {
        'prefix': '/admin',
        'name': None,
        'home': None,
        'i18n': False,

        'template_list': 'admin/list.html',
        'template_item': 'admin/item.html',
        'template_home': 'admin/home.html',
    }
    dependencies = {'jinja2': JPlugin}
github klen / muffin / muffin / plugins / jade.py View on Github external
""" Support Jade Template Engine. """
import asyncio
from os import path as op

from pyjade.ext.html import pyjade, Compiler, local_context_manager
from pyjade.nodes import Extends, CodeBlock

from muffin.plugins import BasePlugin
from muffin.utils import to_coroutine


class JadePlugin(BasePlugin):

    """ The class is used to control the pyjade integration to Muffin application. """

    name = 'jade'
    defaults = dict(
        cache_size=100,
        encoding='UTF-8',
        pretty=True,
        template_folder='templates',
    )

    def __init__(self, **options):
        """ Initialize the plugin. """
        super().__init__(**options)

        self.env = Environment()
github klen / muffin / muffin / plugins / session.py View on Github external
import asyncio
import base64
import functools
import time

import ujson as json

from muffin import HTTPFound
from muffin.plugins import BasePlugin
from muffin.utils import create_signature, check_signature, to_coroutine


FUNC = lambda x: x


class SessionPlugin(BasePlugin):

    """ Support sessions. """

    name = 'session'
    defaults = {
        'default_user_checker': lambda x: x,
        'login_url': '/login',
        'secret': 'InsecureSecret',
    }

    def setup(self, app):
        """ Initialize the application. """
        super().setup(app)

        if self.options['secret'] == 'InsecureSecret':
            app.logger.warn('Use insecure secret key. Change AUTH_SECRET option in configuration.')