def engine_from_config(config): """ A wrapper around :func:`sqlalchemy.engine_from_config`, that converts certain configuration values. Currently, the following configurations are processed: - ``sqlalchemy.echo`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.echo_pool`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.case_sensitive`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.module`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.poolclass`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.pool`` (using :func:`score.init.parse_call`) - ``sqlalchemy.pool_size`` (converted to `int`) - ``sqlalchemy.pool_recycle`` (converted to `int`) """ global _registered_utf8mb4 conf = dict() for key in config: if key in ('sqlalchemy.echo', 'sqlalchemy.echo_pool', 'sqlalchemy.case_sensitive'): conf[key] = parse_bool(config[key]) elif key in ('sqlalchemy.module', 'sqlalchemy.poolclass'): conf[key] = parse_dotted_path(config[key]) elif key == 'sqlalchemy.pool': conf[key] = parse_call(config[key]) elif key in ('sqlalchemy.pool_size', 'sqlalchemy.pool_recycle'): conf[key] = int(config[key]) else: conf[key] = config[key] if not _registered_utf8mb4 and 'utf8mb4' in conf.get('sqlalchemy.url', ''): import codecs codecs.register(lambda name: codecs.lookup('utf8') if name == 'utf8mb4' else None) _registered_utf8mb4 = True return sa.engine_from_config(conf)
def engine_from_config(config): """ A wrapper around :func:`sqlalchemy.engine_from_config`, that converts certain configuration values. Currently, the following configurations are processed: - ``sqlalchemy.case_sensitive`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.connect_args.cursorclass`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.echo`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.echo_pool`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.module`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.poolclass`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.pool`` (using :func:`score.init.parse_call`) - ``sqlalchemy.pool_size`` (converted to `int`) - ``sqlalchemy.pool_recycle`` (converted to `int`) Any other keys are used without conversion. """ conf = dict() for key in config: if key in ('sqlalchemy.echo', 'sqlalchemy.echo_pool', 'sqlalchemy.case_sensitive'): conf[key] = parse_bool(config[key]) elif key in ('sqlalchemy.module', 'sqlalchemy.poolclass'): conf[key] = parse_dotted_path(config[key]) elif key.startswith('sqlalchemy.connect_args.'): if 'sqlalchemy.connect_args' not in conf: conf['sqlalchemy.connect_args'] = {} value = config[key] key = key[len('sqlalchemy.connect_args.'):] if key == 'cursorclass': value = parse_dotted_path(value) conf['sqlalchemy.connect_args'][key] = value elif key == 'sqlalchemy.pool': conf[key] = parse_call(config[key]) elif key in ('sqlalchemy.pool_size', 'sqlalchemy.pool_recycle'): conf[key] = int(config[key]) else: conf[key] = config[key] return sa.engine_from_config(conf)
def init(confdict, ctx): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`ruleset` :confdefault:`RuleSet()` A dotted path to an instance of :class:`RuleSet` in your project. This module will be initialized without any rules, if this configuration key is omitted, resulting in denial of every operation. :confkey:`authenticators` :confdefault:`list()` List of :class:`Authenticators` capable of determining the current actor. :confkey:`ctx.member` :confdefault:`actor` The :term:`context member` under which the current actor should be made available. Leaving this at its default will allow you to access the current actor as the following: >>> ctx.actor """ conf = defaults.copy() conf.update(confdict) if conf['ruleset'] in (None, 'None'): ruleset = RuleSet() else: ruleset = parse_dotted_path(conf['ruleset']) if 'authenticator' in conf: assert not conf['authenticators'] conf['authenticators'] = [conf['authenticator']] del conf['authenticator'] auth = ConfiguredAuthModule(ruleset, conf['ctx.member']) authenticator = NullAuthenticator() for line in reversed(parse_list(conf['authenticators'])): authenticator = parse_call(line, (auth, authenticator)) auth.authenticator = authenticator _register_ctx_actor(conf, ctx, auth) _register_ctx_permits(conf, ctx, auth) return auth
def init(confdict, ctx): """ Initializes this module acoording to :ref:`our module initialization guidelines <module_initialization>` with the following configuration keys: :confkey:`ruleset` :faint:`[default=RuleSet()]` A dotted path to an instance of :class:`RuleSet` in your project. This module will be initialized without any rules, if this configuration key is omitted, resulting in denial of every operation. :confkey:`authenticators` :faint:`[default=list()]` List of :class:`Authenticators` capable of determining the current actor. :confkey:`ctx.member` :faint:`[default=actor]` The :term:`context member` under which the current actor should be made available. Leaving this at its default will allow you to access the current actor as the following: >>> ctx.actor """ conf = defaults.copy() conf.update(confdict) if conf['ruleset'] in (None, 'None'): ruleset = RuleSet() else: ruleset = parse_dotted_path(conf['ruleset']) if 'authenticator' in conf: assert not conf['authenticators'] conf['authenticators'] = [conf['authenticator']] del conf['authenticator'] auth = ConfiguredAuthModule(ruleset, conf['ctx.member']) authenticator = NullAuthenticator() for line in reversed(parse_list(conf['authenticators'])): authenticator = parse_call(line, (auth, authenticator)) auth.authenticator = authenticator _register_ctx_actor(conf, ctx, auth) _register_ctx_permits(conf, ctx, auth) return auth
def engine_from_config(config): """ A wrapper around :func:`sqlalchemy.engine_from_config`, that converts certain configuration values. Currently, the following configurations are processed: - ``sqlalchemy.echo`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.echo_pool`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.case_sensitive`` (using :func:`score.init.parse_bool`) - ``sqlalchemy.module`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.poolclass`` (using :func:`score.init.parse_dotted_path`) - ``sqlalchemy.pool`` (using :func:`score.init.parse_call`) - ``sqlalchemy.pool_size`` (converted to `int`) - ``sqlalchemy.pool_recycle`` (converted to `int`) """ if 'sqlalchemy.echo' in config: config['sqlalchemy.echo'] = parse_bool(config['sqlalchemy.echo']) if 'sqlalchemy.echo_pool' in config: config['sqlalchemy.echo_pool'] = \ parse_bool(config['sqlalchemy.echo_pool']) if 'sqlalchemy.case_sensitive' in config: config['sqlalchemy.case_sensitive'] = \ parse_bool(config['sqlalchemy.case_sensitive']) if 'sqlalchemy.module' in config: config['sqlalchemy.module'] = \ parse_dotted_path(config['sqlalchemy.module']) if 'sqlalchemy.poolclass' in config: config['sqlalchemy.poolclass'] = \ parse_dotted_path(config['sqlalchemy.poolclass']) if 'sqlalchemy.pool' in config: config['sqlalchemy.pool'] = parse_call(config['sqlalchemy.pool']) if 'sqlalchemy.pool_size' in config: config['sqlalchemy.pool_size'] = \ int(config['sqlalchemy.pool_size']) if 'sqlalchemy.pool_recycle' in config: config['sqlalchemy.pool_recycle'] = \ int(config['sqlalchemy.pool_recycle']) return sa.engine_from_config(config)