def sql_app(global_conf, name, url, zcml_file=None, **kwargs): """A factory used to bootstrap the TrajectApplication. As the TrajectApplication will use SQL, we use this 'once and for all' kind of factory to configure the SQL connection and inject the demo datas. """ # We register our SQLengine under a given name if zcml_file: load_zcml(zcml_file) engine = create_and_register_engine(url, name) # We bind out SQLAlchemy definition to the engine engine.bind(Library) # We now instanciate the TrajectApplication # The name and engine are passed, to be used for the querying. app = TrajectApplication(name, engine) # We register our Traject patterns. # As we have 2 models, we register 2 resolvers. #PATTERNS.register(Site, author_req, author_resolve(name)) #PATTERNS.register(Site, book_req, book_resolve(name)) # To finish the initialization process, we inject # some test data, to start with something concrete. try: with transaction.manager: with SQLAlchemySession(engine): Library.metadata.create_all() #inject_data(app) except IntegrityError: # data already exists, skipping. pass return app
def router(conf, session_key, zcml, dsn, name): allowed = ('de',) register_allowed_languages(allowed) config.ALLOWED_LANGUAGES = None load_zcml(zcml) setSecurityPolicy(GenericSecurityPolicy) # We register our SQLengine under a given name engine = create_engine(dsn, name) # We use a declarative base, if it exists we bind it and create engine.bind(Base) metadata = Base.metadata metadata.create_all(engine.engine, checkfirst=True) # Router root = URLMap() admin_app = Admin(session_key, engine, name) root['/admin'] = localize(admin_app) root['/'] = localize(User(session_key, engine, name)) root.__runner__ = admin_app.__runner__ return root
def configuration(global_conf, zcml_file, langs): """A factory for the configuration middleware. It's usually used to initialize some parameters, register components and possibly wrap the requested apps. """ # Read the ZCML # ------------- # We make sure it's called only once. # There's no builtin safeguard to verify that. load_zcml(zcml_file) # Register the i18n preferences # ----------------------------- # Needed by the templating system to resolve the # translation by retrieving the active language # from the request. All this system lives in `cromlech.i18n`. allowed = langs.strip().replace(',', ' ').split() register_allowed_languages(allowed) def app_wrapper(app): """The effective middleware. Here, we do not make use of the wrapping capabilities, but it can be used to add other explicit middlewares. """ return app return app_wrapper
def manager(accesses, zcml_file, users, clients, grants, tokens): # Read users config = ConfigParser.ConfigParser() config.read(accesses) admin_accesses = config.items('admin') # load crom monkey.incompat() implicit.initialize() # Grokking trigger load_zcml(zcml_file) @cooper.basicauth(users=admin_accesses, realm='TrilithAdmin') def admin_ui(environ, start_response): locale = get_environ_language(environ) or 'fr_FR' localizer = get_localizer(locale) with Locale(locale, localizer): request = Request(environ) root = Admin(users, clients, grants, tokens) response = PUBLISHER.publish(request, root, handle_errors=False) return response(environ, start_response) return admin_ui
def zcml_loader(*args, **kwargs): if arg_name in kwargs: filename = getattr(kwargs, method)(arg_name) assert filename and isinstance(filename, (str, unicode)) load_zcml(filename) else: logger.warning('No zcml argument %r found.' % arg_name) return func(*args, **kwargs)
def setup_test(): eventtesting.setUp() load_zcml(os.path.join( os.path.dirname(dolmen.relations.__file__), 'configure.zcml')) load_zcml(os.path.join( os.path.dirname(dolmen.relations.__file__), 'subscribers.zcml')) sm = component.getGlobalSiteManager() sm.registerUtility(IntIds(), IIntIds) sm.registerAdapter(connectionOfPersistent, (IPersistent,), IConnection) sm.registerAdapter(KeyReferenceToPersistent, (IPersistent,), IKeyReference)
def app_factory(global_conf, url, zcml, langs): # load the ZCML load_zcml(zcml) # register the allowed languages register_allowed_languages([lang.strip() for lang in langs.split(',')]) # create, register and populate the base DB/Engine engine = create_and_register_engine(url, DB_KEY) engine.bind(Base) Base.metadata.create_all() return Application(engine)
def routing(conf, files, **kwargs): languages = kwargs['langs'] allowed = languages.strip().replace(',', ' ').split() allowed = ('de',) register_allowed_languages(allowed) load_zcml(kwargs['zcml']) setSecurityPolicy(GenericSecurityPolicy) name = kwargs.get('name', 'school') # We register our SQLengine under a given name if not 'engine' in kwargs: dsn = kwargs['dsn'] engine = create_engine(dsn, name) else: engine = EngineServer(kwargs['engine'], name) # We use a declarative base, if it exists we bind it and create engine.bind(Base) metadata = Base.metadata metadata.create_all(engine.engine, checkfirst=True) # Extract possible layer layer = kwargs.get('layer') if layer is not None: layer_iface = eval_loader(layer) else: layer_iface = None title = kwargs.get('title', 'BG ETEM') # We create the session wrappper session_key = "session" key = key_from_file(path.join(kwargs['root'], 'jwt.key')) session_wrapper = Session(key, 60, environ_key=session_key) # Applications configuration smtp = kwargs.get('smtp', '10.33.115.55') setup = Configuration( title, session_key, engine, name, None, layer_iface, smtp) # Router root = URLMap() quizz = localize(anonymous.Application(setup)) root['/'] = localize(company.Application(setup)) root['/register'] = localize(company.Registration(setup)) root['/quizz'] = quizz root['/befragung'] = quizz root['/json'] = localize(remote.Application(setup)) return session_wrapper(root.__call__)
def keeper(global_conf, pubkey, dburl, zcml_file=None, portals=None, session_key="gatekeeper.session", langs="en,de,fr", **kwargs): engine = create_engine(dburl, "admin") engine.bind(Admin) """A factory used to bootstrap the TrajectApplication. As the TrajectApplication will use SQL, we use this 'once and for all' kind of factory to configure the SQL connection and inject the demo datas. """ if zcml_file is not None: load_zcml(zcml_file) if portals is not None: pconfig = ConfigParser.ConfigParser() pconfig.read(portals) for name in pconfig.sections(): portal = dict(pconfig.items(name)) xmlutil = XMLRPCPortal( portal['inner'], portal['title'], portal['outer']) getGlobalSiteManager().registerUtility(xmlutil, IPortal, name=name) allowed = langs.strip().replace(',', ' ').split() register_allowed_languages(allowed) site = GateKeeper(engine) def publisher(environ, start_response): @tlib.signed_cookie(pubkey) def publish(request, root): view = uvclight.query_view(request, site, name=u'index') if view is not None: return view return uvclight.query_view(request, site, name=u'notfound'), None session = environ[session_key].session setSession(session) request = Request(environ) view, error = publish(request, site) if error is not None: view = uvclight.query_view(request, site, name=u'unauthorized') view.set_message(error.title) response = view() return response(environ, start_response) return publisher
def app(global_conf, name, zcml_file=None, **kwargs): """A factory used to bootstrap the TrajectApplication. As the TrajectApplication will use SQL, we use this 'once and for all' kind of factory to configure the SQL connection and inject the demo datas. """ if zcml_file: load_zcml(zcml_file) def publisher(environ, start_response): request = Request(environ) site = Site(name) setSite(site) notify(PublicationBeginsEvent(site, request)) publisher = DawnlightPublisher(view_lookup=view_lookup) response = publisher.publish(request, site, handle_errors=True) notify(PublicationEndsEvent(request, response)) setSite() return response(environ, start_response) return publisher
def app_factory(global_conf, name, zcml_file, langs='en'): load_zcml(zcml_file) allowed = langs.strip().replace(',', ' ').split() register_allowed_languages(allowed) return WSGIApplication(name)
def zcml_decorated(*args, **kwargs): filename = kwargs.pop('zcml_file', None) if filename is not None: load_zcml(filename) print kwargs return func(*args, **kwargs)
template_cache = os.path.join(HERE, 'cache') if not os.path.exists(template_cache): os.makedirs(template_cache) os.environ["CHAMELEON_CACHE"] = template_cache # Bootstrapping the Crom registry from crom import monkey, implicit monkey.incompat() implicit.initialize() # Read the ZCML # This is not a mandatory stage. # Actually, what the ZCML loading does is grok the packages # This can be done manually, using `crom.configure` from cromlech.configuration.utils import load_zcml load_zcml(os.path.join(HERE, 'app.zcml')) # Load translation # This is needed only if we want internationalization from cromlech.i18n import load_translations_directories load_translations_directories() # Adding the event dispatcher # Use only if you have event handlers or plan to have some. from cromlech.events import setup_dispatcher setup_dispatcher() def populate_db(db): """We create two leaves here.. We get the DB connection object. We need to open and to close it. It doesn't need to return anything.
def testapp(global_conf, zcml_file): load_zcml(zcml_file) return Application()
from loader import Configuration with Configuration('config.json') as config: # We setup the cache for Chameleon templates os.environ["CHAMELEON_CACHE"] = config['templates']['cache'] # Bootstrapping the Crom registry from crom import monkey, implicit monkey.incompat() implicit.initialize() # Getting the crypto key and creating the JWT service from cromlech.sessions.jwt import key_from_file from cromlech.sessions.jwt import JWTCookieSession key = key_from_file(config['session']['jwt_key']) session_wrapper = JWTCookieSession(key, int(config['session']['timeout'])) # read the ZCML from cromlech.configuration.utils import load_zcml load_zcml(config['app']['zcml']) # load translation from cromlech.i18n import load_translations_directories load_translations_directories() # Create the application, including the middlewares. from cromdemo.wsgi import demo_application application = session_wrapper(demo_application)
template_cache = os.path.join(HERE, 'cache') if not os.path.exists(template_cache): os.makedirs(template_cache) os.environ["CHAMELEON_CACHE"] = template_cache # Bootstrapping the Crom registry from crom import monkey, implicit monkey.incompat() implicit.initialize() # Read the ZCML # This is not a mandatory stage. # Actually, what the ZCML loading does is grok the packages # This can be done manually, using `crom.configure` from cromlech.configuration.utils import load_zcml load_zcml(os.path.join(HERE, 'app.zcml')) # Load translation # This is needed only if we want internationalization from cromlech.i18n import load_translations_directories load_translations_directories() # Adding the event dispatcher # Use only if you have event handlers or plan to have some. from cromlech.events import setup_dispatcher setup_dispatcher() # Getting the crypto key and creating the JWT service # We chose the JWT signed cookie for the demo # `cromlech.sessions` proposed different backends. # Or you can use the WSGI session middleware of your choice.
def zcml_loader(*args, **kwargs): filename = getattr(kwargs, method)(arg_name) assert filename and isinstance(filename, (str, unicode)) load_zcml(filename) return func(*args, **kwargs)