• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python imports.import_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sentry.utils.imports.import_string函数的典型用法代码示例。如果您正苦于以下问题:Python import_string函数的具体用法?Python import_string怎么用?Python import_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了import_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: validate_dependency

def validate_dependency(settings, dependency_type, dependency, package):
    try:
        import_string(package)
    except ImportError:
        msg = ConfigurationError.get_error_message(
            "%s %s" % (dependency_type, dependency), package)
        reraise_as(ConfigurationError(msg))
开发者ID:yaoqi,项目名称:sentry,代码行数:7,代码来源:settings.py


示例2: start

def start(ctx, service, bind, workers, debug, upgrade, noinput):
    "Start running a service."
    if bind:
        if ':' in bind:
            host, port = bind.split(':', 1)
            port = int(port)
        else:
            host = bind
            port = None
    else:
        host, port = None, None

    if upgrade:
        click.echo('Performing upgrade before service startup...')
        from sentry.runner import call_command
        call_command(
            'sentry.runner.commands.upgrade.upgrade',
            verbosity=0, noinput=noinput,
        )

    click.echo('Running service: %r' % service)

    # remove command line arguments to avoid optparse failures with service code
    # that calls call_command which reparses the command line, and if --noupgrade is supplied
    # a parse error is thrown
    import sys
    sys.argv = sys.argv[:1]

    from sentry.utils.imports import import_string
    import_string(SERVICES[service])(
        debug=debug,
        host=host,
        port=port,
        workers=workers,
    ).run()
开发者ID:AyrtonRicardo,项目名称:sentry,代码行数:35,代码来源:start.py


示例3: process

    def process(self, key):
        client = self.cluster.get_routing_client()
        lock_key = self._make_lock_key(key)
        # prevent a stampede due to the way we use celery etas + duplicate
        # tasks
        if not client.set(lock_key, '1', nx=True, ex=10):
            return

        with self.cluster.map() as conn:
            values = conn.hgetall(key)
            conn.delete(key)

        if not values.value:
            return

        model = import_string(values.value['m'])
        filters = pickle.loads(values.value['f'])
        incr_values = {}
        extra_values = {}
        for k, v in values.value.iteritems():
            if k.startswith('i+'):
                incr_values[k[2:]] = int(v)
            elif k.startswith('e+'):
                extra_values[k[2:]] = pickle.loads(v)

        super(RedisBuffer, self).process(model, incr_values, filters, extra_values)
开发者ID:pauloschilling,项目名称:sentry,代码行数:26,代码来源:redis.py


示例4: process

    def process(self, key):
        client = self.cluster.get_routing_client()
        lock_key = self._make_lock_key(key)
        # prevent a stampede due to the way we use celery etas + duplicate
        # tasks
        if not client.set(lock_key, '1', nx=True, ex=10):
            metrics.incr('buffer.revoked', tags={'reason': 'locked'})
            self.logger.info('Skipped process on %s; unable to get lock', key)
            return

        conn = self.cluster.get_local_client_for_key(key)
        pipe = conn.pipeline()
        pipe.hgetall(key)
        pipe.zrem(self.pending_key, key)
        pipe.delete(key)
        values = pipe.execute()[0]

        if not values:
            metrics.incr('buffer.revoked', tags={'reason': 'empty'})
            self.logger.info('Skipped process on %s; no values found', key)
            return

        model = import_string(values['m'])
        filters = pickle.loads(values['f'])
        incr_values = {}
        extra_values = {}
        for k, v in values.iteritems():
            if k.startswith('i+'):
                incr_values[k[2:]] = int(v)
            elif k.startswith('e+'):
                extra_values[k[2:]] = pickle.loads(v)

        super(RedisBuffer, self).process(model, incr_values, filters, extra_values)
开发者ID:daevaorn,项目名称:sentry,代码行数:33,代码来源:redis.py


示例5: __init__

 def __init__(self, target, callback):
     target, attr = target.rsplit('.', 1)
     target = import_string(target)
     self.func = getattr(target, attr)
     self.target = target
     self.attr = attr
     self.callback = callback
开发者ID:280185386,项目名称:sentry,代码行数:7,代码来源:patch_context.py


示例6: process

    def process(self, key):
        lock_key = self._make_lock_key(key)
        # prevent a stampede due to the way we use celery etas + duplicate
        # tasks
        if not self.conn.setnx(lock_key, '1'):
            return
        self.conn.expire(lock_key, 10)

        with self.conn.map() as conn:
            values = conn.hgetall(key)
            conn.delete(key)

        if not values:
            return

        model = import_string(values['m'])
        filters = pickle.loads(values['f'])
        incr_values = {}
        extra_values = {}
        for k, v in values.iteritems():
            if k.startswith('i+'):
                incr_values[k[2:]] = int(v)
            elif k.startswith('e+'):
                extra_values[k[2:]] = pickle.loads(v)

        super(RedisBuffer, self).process(model, incr_values, filters, extra_values)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:26,代码来源:redis.py


示例7: validate_data

def validate_data(project, data, client=None):
    ensure_valid_project_id(project, data)

    if not data.get('message'):
        data['message'] = '<no message value>'
    elif len(data['message']) > MAX_MESSAGE_LENGTH:
        raise InvalidData('Value \'message\' is too long. Input is %d chars, max is %s.' % (
            len(data['message']), MAX_MESSAGE_LENGTH))

    if data.get('culprit') and len(data['culprit']) > 200:
        raise InvalidData('Value \'culprit\' is too long. Input is %d chars, max is %s.' % (
            len(data['culprit']), MAX_CULPRIT_LENGTH))

    if not data.get('event_id'):
        data['event_id'] = uuid.uuid4().hex
    elif len(data['event_id']) > 32:
        raise InvalidData('Invalid value for \'event_id\': must be a 32 character identifier')

    if 'timestamp' in data:
        try:
            process_data_timestamp(data)
        except InvalidTimestamp:
            # Log the error, remove the timestamp, and continue
            logger.info('Client %r passed an invalid value for timestamp %r',
                client or '<unknown client>', data['timestamp'], extra={'request': env.request})
            del data['timestamp']

    if data.get('modules') and type(data['modules']) != dict:
        raise InvalidData('Invalid type for \'modules\': must be a mapping')

    for k in data.keys():
        if k in RESERVED_FIELDS:
            continue

        if not data[k]:
            logger.info('Ignoring empty interface %r passed by client %r',
                k, client or '<unknown client>', extra={'request': env.request})
            del data[k]
            continue

        import_path = INTERFACE_ALIASES.get(k, k)

        if '.' not in import_path:
            logger.info('Ignoring unknown attribute %r passed by client %r',
                k, client or '<unknown client>', extra={'request': env.request})
            del data[k]
            continue

        try:
            interface = import_string(import_path)
        except (ImportError, AttributeError), e:
            raise InvalidInterface('%r is not a valid interface name: %s' % (k, e))

        try:
            inst = interface(**data.pop(k))
            inst.validate()
            data[import_path] = inst.serialize()
        except AssertionError, e:
            raise InvalidData('Unable to validate interface, %r: %s' % (k, e))
开发者ID:andrewsmedina,项目名称:sentry,代码行数:59,代码来源:coreapi.py


示例8: multiprocess_worker

def multiprocess_worker(task_queue):
    # Configure within each Process
    import logging
    from sentry.utils.imports import import_string

    logger = logging.getLogger('sentry.cleanup')

    configured = False

    while True:
        j = task_queue.get()
        if j == _STOP_WORKER:
            task_queue.task_done()
            return

        # On first task, configure Sentry environment
        if not configured:
            from sentry.runner import configure
            configure()

            from sentry import models
            from sentry import deletions
            from sentry import similarity

            skip_models = [
                # Handled by other parts of cleanup
                models.Event,
                models.EventMapping,
                models.EventAttachment,
                models.UserReport,
                models.Group,
                models.GroupEmailThread,
                models.GroupRuleStatus,
                models.GroupHashTombstone,
                # Handled by TTL
                similarity.features,
            ] + [b[0] for b in EXTRA_BULK_QUERY_DELETES]

            configured = True

        model, chunk = j
        model = import_string(model)

        try:
            task = deletions.get(
                model=model,
                query={'id__in': chunk},
                skip_models=skip_models,
                transaction_id=uuid4().hex,
            )

            while True:
                if not task.chunk():
                    break
        except Exception as e:
            logger.exception(e)
        finally:
            task_queue.task_done()
开发者ID:alexandrul,项目名称:sentry,代码行数:58,代码来源:cleanup.py


示例9: start

def start(ctx, service, bind, workers, upgrade, noinput):
    "DEPRECATED see `sentry run` instead."

    from sentry.runner.initializer import show_big_error
    show_big_error(
        [
            '`sentry start%s` is deprecated.' % (' ' + service if 'http' in sys.argv else ''),
            'Use `sentry run %s` instead.' % {
                'http': 'web'
            }.get(service, service),
        ]
    )

    if bind:
        if ':' in bind:
            host, port = bind.split(':', 1)
            port = int(port)
        else:
            host = bind
            port = None
    else:
        host, port = None, None

    if upgrade:
        click.echo('Performing upgrade before service startup...')
        from sentry.runner import call_command
        call_command(
            'sentry.runner.commands.upgrade.upgrade',
            verbosity=0,
            noinput=noinput,
        )

    click.echo('Running service: %r' % service)

    # remove command line arguments to avoid optparse failures with service code
    # that calls call_command which reparses the command line, and if --noupgrade is supplied
    # a parse error is thrown
    sys.argv = sys.argv[:1]

    from sentry.utils.imports import import_string
    import_string(SERVICES[service])(
        host=host,
        port=port,
        workers=workers,
    ).run()
开发者ID:Kayle009,项目名称:sentry,代码行数:45,代码来源:start.py


示例10: iter_interfaces

def iter_interfaces():
    rv = {}

    for name, import_path in six.iteritems(settings.SENTRY_INTERFACES):
        rv.setdefault(import_path, []).append(name)

    for import_path, keys in six.iteritems(rv):
        iface = import_string(import_path)
        yield iface, keys
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:9,代码来源:base.py


示例11: init_registry

def init_registry():
    from sentry.constants import SENTRY_RULES
    from sentry.utils.imports import import_string

    registry = RuleRegistry()
    for rule in SENTRY_RULES:
        cls = import_string(rule)
        registry.add(cls)
    return registry
开发者ID:CrazyLionHeart,项目名称:sentry,代码行数:9,代码来源:__init__.py


示例12: get_interface

def get_interface(name):
    if name not in settings.SENTRY_ALLOWED_INTERFACES:
        raise ValueError

    try:
        interface = import_string(name)
    except Exception:
        raise ValueError('Unable to load interface: %s' % (name,))

    return interface
开发者ID:Irrelon,项目名称:sentry,代码行数:10,代码来源:coreapi.py


示例13: __init__

    def __init__(self, backends, read_selector=random.choice, **kwargs):
        assert backends, "you should provide at least one backend"

        self.backends = []
        for backend, backend_options in backends:
            if isinstance(backend, six.string_types):
                backend = import_string(backend)
            self.backends.append(backend(**backend_options))
        self.read_selector = read_selector
        super(MultiNodeStorage, self).__init__(**kwargs)
开发者ID:BlueMoebius,项目名称:sentry,代码行数:10,代码来源:backend.py


示例14: get_password_validators

def get_password_validators(validator_config):
    validators = []
    for validator in validator_config:
        try:
            klass = import_string(validator['NAME'])
        except ImportError:
            msg = "The module in NAME could not be imported: %s. Check your AUTH_PASSWORD_VALIDATORS setting."
            raise ImproperlyConfigured(msg % validator['NAME'])
        validators.append(klass(**validator.get('OPTIONS', {})))

    return validators
开发者ID:duanshuaimin,项目名称:sentry,代码行数:11,代码来源:password_validation.py


示例15: get_interface

def get_interface(name):
    try:
        import_path = settings.SENTRY_INTERFACES[name]
    except KeyError:
        raise ValueError('Invalid interface name: %s' % (name, ))

    try:
        interface = import_string(import_path)
    except Exception:
        raise ValueError('Unable to load interface: %s' % (name, ))

    return interface
开发者ID:binlee1990,项目名称:sentry,代码行数:12,代码来源:base.py


示例16: call_command

def call_command(name, obj=None, **kwargs):
    try:
        command = import_string(name)
    except (ImportError, AttributeError):
        raise UnknownCommand(name)

    with command.make_context('sentry', [], obj=obj or {}) as ctx:
        ctx.params.update(kwargs)
        try:
            command.invoke(ctx)
        except click.Abort:
            click.echo('Aborted!', err=True)
开发者ID:faulkner,项目名称:sentry,代码行数:12,代码来源:__init__.py


示例17: interfaces

    def interfaces(self):
        result = []
        for key, data in self.data.iteritems():
            if '.' not in key:
                continue

            try:
                cls = import_string(key)
            except ImportError:
                pass  # suppress invalid interfaces
            value = cls(**data)
            result.append((value.score, key, value))
        return SortedDict((k, v) for _, k, v in sorted(result, key=lambda x: x[0], reverse=True))
开发者ID:fusionbox,项目名称:sentry,代码行数:13,代码来源:models.py


示例18: get_instance

def get_instance(attribute, options, dangerous=()):
    value = getattr(settings, attribute)

    cls = import_string(value)
    if cls in dangerous:
        warnings.warn(
            warnings.UnsupportedBackend(
                u'The {!r} backend for {} is not recommended '
                'for production use.'.format(value, attribute)
            )
        )

    return cls(**options)
开发者ID:faulkner,项目名称:sentry,代码行数:13,代码来源:app.py


示例19: init_registry

def init_registry():
    from sentry.constants import SENTRY_RULES
    from sentry.plugins import plugins
    from sentry.utils.imports import import_string
    from sentry.utils.safe import safe_execute

    registry = RuleRegistry()
    for rule in SENTRY_RULES:
        cls = import_string(rule)
        registry.add(cls)
    for plugin in plugins.all(version=2):
        for cls in (safe_execute(plugin.get_rules) or ()):
            register.add(cls)

    return registry
开发者ID:AyrtonRicardo,项目名称:sentry,代码行数:15,代码来源:__init__.py


示例20: test_process_pending_one_batch

    def test_process_pending_one_batch(self, cluster_get):
        attachment_cache = import_string('sentry.attachments.redis.RbAttachmentCache')(hosts=[])
        cluster_get.assert_any_call('SENTRY_CACHE_OPTIONS', {'hosts': []})
        assert isinstance(attachment_cache.inner, RbCache)
        assert attachment_cache.inner.client is CLIENT

        rv = attachment_cache.get('foo')
        assert len(rv) == 1
        attachment = rv[0]
        assert attachment.meta() == {
            'type': 'event.attachment',
            'name': 'foo.txt',
            'content_type': 'text/plain'
        }
        assert attachment.data == b'Hello World!'
开发者ID:Kayle009,项目名称:sentry,代码行数:15,代码来源:test_redis.py



注:本文中的sentry.utils.imports.import_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python javascript.to_json函数代码示例发布时间:2022-05-27
下一篇:
Python http.is_valid_origin函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap