Example #1
0
class Compression:
    def __init__(self, level: int = 2, min_size: int = 500, mimetypes: List = None):
        self.compressor = Compress()
        self.level = level
        self.min_size = min_size
        self.mimetypes = mimetypes if mimetypes else ['text/plain', 'text/html', 'text/css', 'text/scss', 'text/xml', 'application/json', 'application/javascript']

    def init_app(self, app: Quart):
        app.config["COMPRESS_MIN_SIZE"] = self.min_size
        app.config["COMPRESS_LEVEL"] = self.level
        app.config["COMPRESS_MIMETYPES"] = self.mimetypes
        self.compressor.init_app(app)
def setup_with_cache_and_sizes():
    compress = Compress()

    app = Quart(__name__)
    app.testing = True

    cache = Cache(app, config={"CACHE_TYPE": "simple"})
    app.config["COMPRESS_CACHE_BACKEND"] = cache
    app.config["COMPRESS_CACHE_KEY"] = str

    small_path = _ROOT / "tests" / "templates" / "small.html"
    large_path = _ROOT / "tests" / "templates" / "large.html"

    small_size = os.path.getsize(small_path.as_posix()) - 1
    large_size = os.path.getsize(large_path.as_posix()) - 1

    @app.route("/small")
    @cache.cached(timeout=50)
    def small():
        return render_template("small.html")

    @app.route("/large")
    @cache.cached(timeout=50)
    def large():
        return render_template("large.html")

    return (app, compress, small_size, large_size)
def setup_two_applications():
    compress1 = Compress()
    compress2 = Compress()

    app1 = Quart(__name__)
    app1.testing = True

    app2 = Quart(__name__)
    app2.testing = True

    @app1.route("/small")
    @app2.route("/small")
    def small():
        return render_template("small.html")

    @app1.route("/large")
    @app2.route("/large")
    def large():
        return render_template("large.html")

    return (app1, compress1, app2, compress2)
Example #4
0
def create_app(config_object="lnbits.settings") -> Quart:
    """Create application factory.
    :param config_object: The configuration object to use.
    """
    app = Quart(__name__, static_folder="static")
    app.config.from_object(config_object)
    app.asgi_http_class = ASGIProxyFix

    cors(app)
    Compress(app)

    register_assets(app)
    register_blueprints(app)
    register_filters(app)
    register_commands(app)
    register_request_hooks(app)

    return app
Example #5
0
def create_app(config_object="lnbits.settings") -> QuartTrio:
    """Create application factory.
    :param config_object: The configuration object to use.
    """
    app = QuartTrio(__name__, static_folder="static")
    app.config.from_object(config_object)
    app.asgi_http_class = ASGIProxyFix

    cors(app)
    Compress(app)

    check_funding_source(app)
    register_assets(app)
    register_blueprints(app)
    register_filters(app)
    register_commands(app)
    register_async_tasks(app)
    register_exception_handlers(app)

    return app
    def setup(self):
        self.app = Quart(__name__)
        self.app.testing = True

        small_path = os.path.join(os.getcwd(), "tests", "templates", "small.html")

        large_path = os.path.join(os.getcwd(), "tests", "templates", "large.html")

        self.small_size = os.path.getsize(small_path) - 1
        self.large_size = os.path.getsize(large_path) - 1

        Compress(self.app)

        @self.app.route("/small/")
        async def small():
            return await render_template("small.html")

        @self.app.route("/large/")
        async def large():
            return await render_template("large.html")
def setup_with_sizes():
    app = Quart(__name__)
    app.testing = True
    Compress(app)

    small_path = _ROOT / "tests" / "templates" / "small.html"
    large_path = _ROOT / "tests" / "templates" / "large.html"

    small_size = os.path.getsize(small_path.as_posix()) - 1
    large_size = os.path.getsize(large_path.as_posix()) - 1

    @app.route("/small")
    def small():
        return render_template("small.html")

    @app.route("/large")
    def large():
        return render_template("large.html")

    return (app, small_size, large_size)
Example #8
0
from .url_converters import ListConverter

app = Quart(__name__)

app.config.from_pyfile('settings.py')

app.cache = Cache(app)

js_assets = Bundle('js/cookie.js',
                   'js/index.js',
                   filters='rjsmin',
                   output='gen/bundled.js')
css_assets = Bundle('css/index.css',
                    filters='cssmin',
                    output='gen/bundled.css')

assets = Environment(app)
assets.register('js_all', js_assets)
assets.register('css_all', css_assets)

# Minify HTML and any inline JS or CSS
Minify(app, js=True)

# gzip responses
Compress(app)

app.url_map.converters['list'] = ListConverter

from . import filters
from . import views
def test_constructor_init(setup_app):
    app, _ = setup_app
    Compress(app)
Example #10
0
 def __init__(self, level: int = 2, min_size: int = 500, mimetypes: List = None):
     self.compressor = Compress()
     self.level = level
     self.min_size = min_size
     self.mimetypes = mimetypes if mimetypes else ['text/plain', 'text/html', 'text/css', 'text/scss', 'text/xml', 'application/json', 'application/javascript']
    def setup(self):
        self.app = Quart(__name__)
        self.app.testing = True

        Compress(self.app)
 def test_delayed_init(self):
     compress = Compress()
     compress.init_app(self.app)
 def test_constructor_init(self):
     Compress(self.app)
Example #14
0
import nonebot
from quart import jsonify, request, websocket
from quart_compress import Compress

from . import decode, encode, get_clan
from .battleMaster import BattleMaster

bot = nonebot.get_bot()
battleObj = BattleMaster()

Compress(bot.server_app)


@bot.server_app.route('/recs')
async def get_recs():
    gid = request.args.get('g')
    uid = request.args.get('u')

    try:
        gid = decode(gid)
        if uid is not None:
            uid = decode(uid)

        recs = battleObj.get_rec(gid, uid)
        result = [
            {
                'uid': encode(rec['uid']),
                'time': rec['time'],
                'round': rec['round'],
                'boss': rec['boss'],
                'dmg': rec['dmg'],
Example #15
0
def setup_app():
    compress = Compress()
    app = Quart(__name__)
    app.testing = True

    return app, compress