def app(): rv = App(__name__) rv.config.mailer.sender = '*****@*****.**' rv.config.auth.single_template = True rv.config.auth.hmac_key = "foobar" rv.pipeline = [SessionManager.cookies('foobar')] return rv
def app(): app = App(__name__) app.languages = ['en', 'it'] app.language_default = 'en' app.language_force_on_url = True @app.route() def test_route(): return 'Test Router' @app.route() def test_404(): abort(404, 'Not found, dude') @app.route('/test2/<int:a>/<str:b>') def test_route2(a, b): return 'Test Router' @app.route('/test3/<int:a>/foo(/<str:b>)?(.<str:c>)?') def test_route3(a, b, c): return 'Test Router' @app.route('/test_int/<int:a>') def test_route_int(a): return 'Test Router' @app.route('/test_float/<float:a>') def test_route_float(a): return 'Test Router' @app.route('/test_date/<date:a>') def test_route_date(a): return 'Test Router' @app.route('/test_alpha/<alpha:a>') def test_route_alpha(a): return 'Test Router' @app.route('/test_str/<str:a>') def test_route_str(a): return 'Test Router' @app.route('/test_any/<any:a>') def test_route_any(a): return 'Test Router' @app.route('/test_complex' '/<int:a>' '/<float:b>' '/<date:c>' '/<alpha:d>' '/<str:e>' '/<any:f>') def test_route_complex(a, b, c, d, e, f): return 'Test Router' return app
def db(): app = App(__name__) db = Database(app, config=sdict(uri='sqlite:memory', auto_migrate=True, auto_connect=False)) return db
def app(event_loop): rv = App(__name__) rv.config.db.adapter = 'mongodb' rv.config.db.host = os.environ.get('MONGO_HOST', 'localhost') rv.config.db.port = int(os.environ.get('MONGO_PORT', '27017')) rv.config.db.database = os.environ.get('MONGO_DB', 'test') return rv
def db(): app = App(__name__) db = Database( app, config=sdict( uri='sqlite:memory', auto_migrate=True, auto_connect=True)) db.define_models(Register) return db
def db(): app = App(__name__) db = Database(app, config=sdict(uri='sqlite://validators.db', auto_connect=True, auto_migrate=True)) db.define_models([ A, AA, AAA, B, Consist, Len, Inside, Num, Eq, Match, Anyone, Proc, Person, Thing, Allowed, Mixed ]) return db
def db(): app = App(__name__) db = Database(app, config=sdict(uri='sqlite://dal.db', auto_connect=True, auto_migrate=True)) db.define_models([ Stuff, Person, Thing, Feature, Price, Doctor, Patient, Appointment, User, Organization, Membership, House, Mouse, NeedSplit, Zoo, Animal, Elephant, Dog, Subscription ]) return db
def app(): app = App(__name__) app.pipeline = [Pipe1(), Pipe2(), Pipe3()] @app.route() def ok(): return "ok" @app.route() def http_error(): abort(422) @app.route() def error(): raise Exception @app.route(pipeline=[ExcPipeOpen(), Pipe4()]) def open_error(): return '' @app.route(pipeline=[ExcPipeClose(), Pipe4()]) def close_error(): return '' @app.route(pipeline=[Pipe4()]) def pipe4(): return "4" mod = app.module(__name__, 'mod', url_prefix='mod') mod.pipeline = [Pipe5()] @mod.route() def pipe5(): return "5" @mod.route(pipeline=[Pipe6()]) def pipe6(): return "6" return app
async def test_diskcache(): App(__name__) disk_cache = DiskCache() assert disk_cache._threshold == 500 assert disk_cache('test', lambda: 2) == 2 assert disk_cache('test', lambda: 3, 300) == 2 assert await disk_cache('test_loop', _await_2) == 2 assert await disk_cache('test_loop', _await_3, 300) == 2 disk_cache.set('test', 3) assert disk_cache.get('test') == 3 disk_cache.set('test', 4, 300) assert disk_cache.get('test') == 4 disk_cache.clear() assert disk_cache.get('test') is None
# -*- coding: utf-8 -*- from emmett import App, session, now, url, redirect, abort from emmett.orm import Database, Model, Field, belongs_to, has_many from emmett.tools import requires from emmett.tools.auth import Auth, AuthUser from emmett.sessions import SessionManager app = App(__name__) app.config.auth.single_template = True app.config.auth.registration_verification = False app.config.auth.hmac_key = "MassiveDynamicRules" #: define models class User(AuthUser): # will create "auth_user" table and groups/permissions ones has_many('posts', 'comments') class Post(Model): belongs_to('user') has_many('comments') title = Field() text = Field.text() date = Field.datetime() default_values = { 'user': lambda: session.auth.user.id,
# -*- coding: utf-8 -*- from emmett import App, session, now, url, redirect, abort from emmett.orm import Database, Model, Field, belongs_to, has_many from emmett.tools import requires from emmett.tools.auth import Auth, AuthUser from emmett.sessions import SessionManager app = App(__name__) app.config.auth.single_template = True app.config.auth.registration_verification = False app.config.auth.hmac_key = "november.5.1955" #: define models class User(AuthUser): # will create "auth_user" table and groups/permissions ones has_many('posts', 'comments') class Post(Model): belongs_to('user') has_many('comments') title = Field() text = Field.text() date = Field.datetime() default_values = { 'user': lambda: session.auth.user.id,
def app(): rv = App(__name__) rv.config.db.uri = 'sqlite:memory' return rv
def app(): app = App(__name__) app.config.templates_escape = 'all' app.config.templates_prettify = True app.config.templates_auto_reload = True return app
# coding: utf8 from emmett import App from emmett.orm import Database from emmett.tools.auth import Auth # from emmett.tools import Mailer from emmett.sessions import SessionManager from .models.users import User from .models.posts import Post from .models.subscriptions import Subscription from emmett_rest import REST app = App(__name__) app.use_extension(REST) app.config.REST.default_pagesize = 200 app.config.REST.min_pagesize = 10 app.config.REST.max_pagesize = 5000 # Config # app.config_from_yaml('app.yml') # app.config_from_yaml('db.yml', 'db') # app.config_from_yaml('mailer.yml', 'mailer') # app.config_from_yaml('auth.yml', 'auth') app.config.db.uri = 'sqlite://database.sqlite' db = Database(app, auto_migrate=False) # mailer = Mailer(app) auth = Auth(app, db, user_model=User)
def app(): return App(__name__)
def test_user_no_assign_level(): app = App(__name__) app.config.logging.pytest = sdict() result = _call_create_logger(app) assert result.handlers[-1].level == logging.WARNING
def app(): app = App(__name__) app.pipeline = [Pipe1(), Pipe2(), Pipe3()] @app.route() def ok(): return "ok" @app.route() def http_error(): abort(422) @app.route() def error(): raise Exception @app.route(pipeline=[ExcPipeOpen(), Pipe4()]) def open_error(): return '' @app.route(pipeline=[ExcPipeClose(), Pipe4()]) def close_error(): return '' @app.route(pipeline=[Pipe4()]) def pipe4(): return "4" @app.websocket() async def ws_ok(): await websocket.send('ok') @app.websocket() def ws_error(): raise Exception @app.websocket(pipeline=[ExcPipeOpen(), Pipe4()]) def ws_open_error(): return @app.websocket(pipeline=[ExcPipeClose(), Pipe4()]) def ws_close_error(): return @app.websocket(pipeline=[Pipe4()]) def ws_pipe4(): return @app.websocket(pipeline=[PipeSR1(), PipeSR2()]) async def ws_inject(): data = await websocket.receive() current._receive_storage.append(data) await websocket.send(data) mod = app.module(__name__, 'mod', url_prefix='mod') mod.pipeline = [Pipe5()] @mod.route() def pipe5(): return "5" @mod.route(pipeline=[Pipe6()]) def pipe6(): return "6" @mod.websocket() def ws_pipe5(): return @mod.websocket(pipeline=[Pipe6()]) def ws_pipe6(): return inj = app.module(__name__, 'inj', url_prefix='inj') inj.pipeline = [GlobalInjector(), ScopedInjector()] @inj.route(template='test.html') def injpipe(): return {'posts': []} return app
# Disable all logging features import logging logging.disable() from emmett import App app = App(__name__) app.config.handle_static = False @app.route("/", output="bytes") async def index(): return b"" @app.route("/user/<any:id>", output="str") async def user_info(id): return id @app.route("/user", methods="post", output="bytes") async def user(): return b""
def app(event_loop, db_config): rv = App(__name__) rv.config.db = db_config rv.use_extension(REST) return rv
def app(db_config): rv = App(__name__) rv.config.db = db_config rv.use_extension(MongoREST) return rv
def test_user_assign_valid_level(): app = App(__name__) app.config.logging.pytest = sdict(level='info') result = _call_create_logger(app) assert result.handlers[-1].level == logging.INFO
def app(): app = App(__name__) app.config.templates_escape = 'all' app.config.templates_adjust_indent = True app.config.templates_auto_reload = True return app
def app(): rv = App(__name__) rv.config.mailer.sender = '*****@*****.**' return rv
def app(): app = App(__name__) app.language_write = True delattr(Tinstance, '_t') return app