Initialize Flask application.
970392
def init_app(self, app):
        """"""
        # Ensure SECRET_KEY is set.
        SECRET_KEY = app.config.get('SECRET_KEY')

        if SECRET_KEY is None:
            app.config['SECRET_KEY'] = 'CHANGE_ME'
            warnings.warn(
                'Set configuration variable SECRET_KEY with random string',
                UserWarning)
281884
def init(self, app):
        
        cfg = app.config
        self.welcome_message = cfg.get('USER_SEND_WELCOME_MESSAGE')
        self.require_confirmation = cfg.get(
            'USER_ACCOUNTS_REQUIRE_CONFIRMATION'
        )

        subjects = cfg.get('USER_EMAIL_SUBJECTS')
        self.email_subjects = subjects if subjects else dict()

        self.jwt_secret = cfg.get('USER_JWT_SECRET')
        self.jwt_algo = cfg.get('USER_JWT_ALGO')
        self.jwt_lifetime = cfg.get('USER_JWT_LIFETIME_SECONDS')
        self.jwt_implementation = cfg.get('USER_JWT_IMPLEMENTATION')
        self.jwt_loader_implementation = cfg.get(
            'USER_JWT_LOADER_IMPLEMENTATION'
        )
112331
def init(scope, app, settings):
    """"""
    cfg = settings.get('rw.static', {})
    static = Static()
    scope['static'] = static
    scope['template_env'].globals['static'] = static
    for base_uri, sources in cfg.items():
        full_paths = []
        for source in sources:
            if isinstance(source, dict):
                full_path = source['path']
                full_paths.append(full_path.format(**os.environ))
                continue
            elif ',' in source:
                module_name, path = [part.strip()
                                     for part in source.split(',')]
            else:
                module_name = source
                path = 'static'
            full_path = pkg_resources.resource_filename(module_name, path)
            full_paths.append(full_path)

        app.root.mount('/' + base_uri + '/<h>/<path:path>',
                       StaticHandler, {'path': full_paths},
                       name='static_' + base_uri.replace('.', '_'))

        static.handlers.append((base_uri, StaticHandler, full_paths))
    static.setup()
536575
def init_config(self, app):
        
        app.config.setdefault('REQUIREJS_BASEURL', app.static_folder)
        app.config.setdefault('COLLECT_STATIC_ROOT', app.static_folder)
        app.config.setdefault('COLLECT_STORAGE', 'flask_collect.storage.link')
        app.config.setdefault(
            'COLLECT_FILTER', partial(collect_staticroot_removal, app))
        app.config.setdefault(
            'WEBPACKEXT_PROJECT', 'invenio_assets.webpack:project')
177948
def init_app(self, app):
        
        app.config.setdefault('PRETTIFY', False)

        if app.config['PRETTIFY']:
            app.after_request(self._prettify_response)
660849
def init_app(self, app):
        

        # Setup a few sane defaults.
        app.config.setdefault('WEBPACK_MANIFEST_PATH',
                              '/tmp/themostridiculousimpossiblepathtonotexist')
        app.config.setdefault('WEBPACK_ASSETS_URL', None)

        self._set_asset_paths(app)

        # We only want to refresh the webpack stats in development mode,
        # not everyone sets this setting, so let's assume it's production.
        if app.config.get('DEBUG', False):
            app.before_request(self._refresh_webpack_stats)

        if hasattr(app, 'add_template_global'):
            app.add_template_global(self.javascript_tag)
            app.add_template_global(self.stylesheet_tag)
            app.add_template_global(self.asset_url_for)
        else:
            # Flask < 0.10
            ctx = {
                'javascript_tag': self.javascript_tag,
                'stylesheet_tag': self.stylesheet_tag,
                'asset_url_for': self.asset_url_for
            }
            app.context_processor(lambda: ctx)
1138029
def init_app(self, app, config=None, statsd=None):
        """"""
        if config is not None:
            self.config = config
        elif self.config is None:
            self.config = app.config

        self.messages = self.config.get('EXCEPTION_MESSAGE', True)
        self.prefix = self.config.get('EXCEPTION_PREFIX', DEFAULT_PREFIX)
        self.statsd = statsd
976621
def init_app(self, app):
        
        config_log_level = app.config.get('FLASK_LOG_LEVEL', None)

        # Set up format for default logging
        hostname = platform.node().split('.')[0]
        formatter = (
            '[%(asctime)s] %(levelname)s %(process)d [%(name)s] '
            '%(filename)s:%(lineno)d - '
            '[{hostname}] - %(message)s'
        ).format(hostname=hostname)

        config_log_int = None
        set_level = None

        if config_log_level:
            config_log_int = getattr(logging, config_log_level.upper(), None)
            if not isinstance(config_log_int, int):
                raise ValueError(
                    'Invalid log level: {0}'.format(config_log_level)
                )
            set_level = config_log_int

        # Set to NotSet if we still aren't set yet
        if not set_level:
            set_level = config_log_int = logging.NOTSET
        self.log_level = set_level

        # Setup basic StreamHandler logging with format and level (do
        # setup in case we are main, or change root logger if we aren't.
        logging.basicConfig(format=formatter)
        root_logger = logging.getLogger()
        root_logger.setLevel(set_level)

        # Get everything ready to setup the syslog handlers
        address = None
        if os.path.exists('/dev/log'):
            address = '/dev/log'
        elif os.path.exists('/var/run/syslog'):
            address = '/var/run/syslog'
        else:
            address = ('127.0.0.1', 514)
        # Add syslog handler before adding formatters
        root_logger.addHandler(
            SysLogHandler(address=address, facility=SysLogHandler.LOG_LOCAL0)
        )
        self.set_formatter(formatter)

        return config_log_int
675491
def init_app(self, app):
        # type: (Flask) -> None
        """"""
        self.client_id = app.config.get("MQTT_CLIENT_ID", "")

        if isinstance(self.client_id, unicode):
            self.client._client_id = self.client_id.encode('utf-8')
        else:
            self.client._client_id = self.client_id

        self.client._transport = app.config.get("MQTT_TRANSPORT", "tcp").lower()
        self.client._protocol = app.config.get("MQTT_PROTOCOL_VERSION", MQTTv311)

        self.client.on_connect = self._handle_connect
        self.client.on_disconnect = self._handle_disconnect
        self.username = app.config.get("MQTT_USERNAME")
        self.password = app.config.get("MQTT_PASSWORD")
        self.broker_url = app.config.get("MQTT_BROKER_URL", "localhost")
        self.broker_port = app.config.get("MQTT_BROKER_PORT", 1883)
        self.tls_enabled = app.config.get("MQTT_TLS_ENABLED", False)
        self.keepalive = app.config.get("MQTT_KEEPALIVE", 60)
        self.last_will_topic = app.config.get("MQTT_LAST_WILL_TOPIC")
        self.last_will_message = app.config.get("MQTT_LAST_WILL_MESSAGE")
        self.last_will_qos = app.config.get("MQTT_LAST_WILL_QOS", 0)
        self.last_will_retain = app.config.get("MQTT_LAST_WILL_RETAIN", False)

        if self.tls_enabled:
            self.tls_ca_certs = app.config["MQTT_TLS_CA_CERTS"]
            self.tls_certfile = app.config.get("MQTT_TLS_CERTFILE")
            self.tls_keyfile = app.config.get("MQTT_TLS_KEYFILE")
            self.tls_cert_reqs = app.config.get("MQTT_TLS_CERT_REQS",
                                                ssl.CERT_REQUIRED)
            self.tls_version = app.config.get("MQTT_TLS_VERSION",
                                              ssl.PROTOCOL_TLSv1)
            self.tls_ciphers = app.config.get("MQTT_TLS_CIPHERS")
            self.tls_insecure = app.config.get("MQTT_TLS_INSECURE", False)

        # set last will message
        if self.last_will_topic is not None:
            self.client.will_set(
                self.last_will_topic,
                self.last_will_message,
                self.last_will_qos,
                self.last_will_retain,
            )

        self._connect()
55799
def init_app(self, app, env_file=None, verbose_mode=False):
        """"""
        if self.app is None:
            self.app = app
        self.verbose_mode = verbose_mode

        if env_file is None:
            env_file = os.path.join(os.getcwd(), ".env")
        if not os.path.exists(env_file):
            warnings.warn("can't read {0} - it doesn't exist".format(env_file))
        else:
            self.__import_vars(env_file)
282657
def init_app(self, app, database=None):
        """"""

        # Register application
        if not app:
            raise RuntimeError('Invalid application.')
        self.app = app
        if not hasattr(app, 'extensions'):
            app.extensions = {}
        app.extensions['peewee'] = self

        app.config.setdefault('PEEWEE_CONNECTION_PARAMS', {})
        app.config.setdefault('PEEWEE_DATABASE_URI', 'sqlite:///peewee.sqlite')
        app.config.setdefault('PEEWEE_MANUAL', False)
        app.config.setdefault('PEEWEE_MIGRATE_DIR', 'migrations')
        app.config.setdefault('PEEWEE_MIGRATE_TABLE', 'migratehistory')
        app.config.setdefault('PEEWEE_MODELS_CLASS', Model)
        app.config.setdefault('PEEWEE_MODELS_IGNORE', [])
        app.config.setdefault('PEEWEE_MODELS_MODULE', '')
        app.config.setdefault('PEEWEE_READ_SLAVES', '')
        app.config.setdefault('PEEWEE_USE_READ_SLAVES', True)

        # Initialize database
        params = app.config['PEEWEE_CONNECTION_PARAMS']
        database = database or app.config.get('PEEWEE_DATABASE_URI')
        if not database:
            raise RuntimeError('Invalid database.')
        database = get_database(database, **params)

        slaves = app.config['PEEWEE_READ_SLAVES']
        if isinstance(slaves, string_types):
            slaves = slaves.split(',')
        self.slaves = [get_database(slave, **params) for slave in slaves if slave]

        self.database.initialize(database)
        if self.database.database == ':memory:':
            app.config['PEEWEE_MANUAL'] = True

        if not app.config['PEEWEE_MANUAL']:
            app.before_request(self.connect)
            app.teardown_request(self.close)
189285
def initialize_api(flask_app):
    """"""
    if not flask_restplus:
        return

    api = flask_restplus.Api(version="1.0", title="My Example API")
    api.add_resource(HelloWorld, "/hello")

    blueprint = flask.Blueprint("api", __name__, url_prefix="/api")
    api.init_app(blueprint)
    flask_app.register_blueprint(blueprint)
1300586
def before_init_app(self, app: FlaskUnchained):
        
        from .templates import (UnchainedJinjaEnvironment,
                                UnchainedJinjaLoader)
        app.jinja_environment = UnchainedJinjaEnvironment
        app.jinja_options = {**app.jinja_options,
                             'loader': UnchainedJinjaLoader(app)}
        app.jinja_env.globals['url_for'] = url_for

        for name in ['string', 'str']:
            app.url_map.converters[name] = StringConverter
713758
def init_app(self, app):
        '''
        '''
        self.app = app
        self._session_conf = app.config.get('BEAKER_SESSION', {
            'session.type': 'file',
            'session.data_dir': '/tmp/session/data',
            'session.lock_dir': '/tmp/session/lock'
        })
        app.wsgi_app = SessionMiddleware(app.wsgi_app, self._session_conf)
        app.session_interface = BeakerSessionInterface()
797209
def init_app(self, app):
        """"""
        app.extensions['invenio-documents'] = self
        app.cli.add_command(cmd)
1103340
def initialize(self, app: Flask, app_config):
        
        debug = app_config["debug"]
        port = app_config["http.port"]
        if debug:
            self.started_on_port = port
            app.run(host="0.0.0.0", debug=True, port=port)
        else:
            for port in range(port, port + 50):
                self.http_server = WSGIServer(('0.0.0.0', port), app)
                try:
                    self.http_server.start()
                except OSError:
                    # try next port
                    continue
                self.started_on_port = port
                break
762749
def init():
    
    global _users, _names
    _configure_app(app)
    _users, _names = _init_login_manager(app)
    _configure_logger()
    init_scheduler(app.config.get('SQLALCHEMY_DATABASE_URI'))
    db.init(app.config.get('SQLALCHEMY_DATABASE_URI'))