当前位置: 首页>>代码示例>>Python>>正文


Python strings.truncatechars函数代码示例

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


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

示例1: validate_data

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

    if not data.get('message'):
        data['message'] = '<no message value>'
    elif not isinstance(data['message'], basestring):
        raise APIError('Invalid value for message')
    elif len(data['message']) > MAX_MESSAGE_LENGTH:
        logger.info('Truncated value for message due to length (%d chars)', len(data['message']),
            **client_metadata(client))
        data['message'] = truncatechars(data['message'], MAX_MESSAGE_LENGTH)

    if data.get('culprit') and len(data['culprit']) > MAX_CULPRIT_LENGTH:
        logger.info('Truncated value for culprit due to length (%d chars)', len(data['culprit']),
            **client_metadata(client))
        data['culprit'] = truncatechars(data['culprit'], MAX_CULPRIT_LENGTH)

    if not data.get('event_id'):
        data['event_id'] = uuid.uuid4().hex
    if len(data['event_id']) > 32:
        logger.info('Discarded value for event_id due to length (%d chars)', len(data['event_id']),
            **client_metadata(client))
        data['event_id'] = uuid.uuid4().hex

    if 'timestamp' in data:
        try:
            process_data_timestamp(data)
        except InvalidTimestamp, e:
            # Log the error, remove the timestamp, and continue
            logger.info('Discarded invalid value for timestamp: %r', data['timestamp'],
                **client_metadata(client, exception=e))
            del data['timestamp']
开发者ID:755,项目名称:sentry,代码行数:32,代码来源:coreapi.py

示例2: message_short

 def message_short(self):
     message = strip(self.message)
     if not message:
         message = '<unlabeled message>'
     else:
         message = truncatechars(message.splitlines()[0], 100)
     return message
开发者ID:JJediny,项目名称:sentry,代码行数:7,代码来源:group.py

示例3: generate_culprit

def generate_culprit(data):
    platform = data.get('platform')
    exceptions = get_path(data, 'exception', 'values', filter=True)
    if exceptions:
        # Synthetic events no longer get a culprit
        last_exception = get_path(exceptions, -1)
        if get_path(last_exception, 'mechanism', 'synthetic'):
            return ''

        stacktraces = [e['stacktrace'] for e in exceptions if get_path(e, 'stacktrace', 'frames')]
    else:
        stacktrace = data.get('stacktrace')
        if stacktrace and stacktrace.get('frames'):
            stacktraces = [stacktrace]
        else:
            stacktraces = None

    culprit = None

    if not culprit and stacktraces:
        culprit = get_stacktrace_culprit(get_path(stacktraces, -1), platform=platform)

    if not culprit and data.get('request'):
        culprit = get_path(data, 'request', 'url')

    return truncatechars(culprit or '', MAX_CULPRIT_LENGTH)
开发者ID:getsentry,项目名称:sentry,代码行数:26,代码来源:culprit.py

示例4: to_string

 def to_string(self, metadata):
     if not metadata['value']:
         return metadata['type']
     return u'{}: {}'.format(
         metadata['type'],
         truncatechars(metadata['value'].splitlines()[0], 100),
     )
开发者ID:NuttasitBoonwat,项目名称:sentry,代码行数:7,代码来源:error.py

示例5: error

 def error(self):
     message = strip(self.message)
     if message:
         message = truncatechars(message, 100)
     else:
         message = '<unlabeled message>'
     return message
开发者ID:gaojiashenghim,项目名称:sentry,代码行数:7,代码来源:models.py

示例6: error

 def error(self):
     message = strip(self.get_legacy_message())
     if not message:
         message = '<unlabeled message>'
     else:
         message = truncatechars(message.splitlines()[0], 100)
     return message
开发者ID:Akashguharoy,项目名称:sentry,代码行数:7,代码来源:event.py

示例7: test_truncated

    def test_truncated(self):
        url = truncatechars('http://example.com', 3)
        with pytest.raises(CannotFetchSource) as exc:
            fetch_file(url)

        assert exc.value.data['type'] == EventError.JS_MISSING_SOURCE
        assert exc.value.data['url'] == url
开发者ID:pythorn,项目名称:sentry,代码行数:7,代码来源:test_processor.py

示例8: generate_culprit

def generate_culprit(data, platform=None):
    culprit = ''

    try:
        stacktraces = [
            e['stacktrace'] for e in data['sentry.interfaces.Exception']['values']
            if e.get('stacktrace')
        ]
    except KeyError:
        stacktrace = data.get('sentry.interfaces.Stacktrace')
        if stacktrace:
            stacktraces = [stacktrace]
        else:
            stacktraces = None

    if not stacktraces:
        if 'sentry.interfaces.Http' in data:
            culprit = data['sentry.interfaces.Http'].get('url', '')
    else:
        from sentry.interfaces.stacktrace import Stacktrace
        culprit = Stacktrace.to_python(stacktraces[-1]).get_culprit_string(
            platform=platform,
        )

    return truncatechars(culprit, MAX_CULPRIT_LENGTH)
开发者ID:alshopov,项目名称:sentry,代码行数:25,代码来源:event_manager.py

示例9: message_top

 def message_top(self):
     culprit = strip(self.culprit)
     if culprit:
         return culprit
     message = strip(self.message)
     if not strip(message):
         return '<unlabeled message>'
     return truncatechars(message.splitlines()[0], 100)
开发者ID:gaojiashenghim,项目名称:sentry,代码行数:8,代码来源:models.py

示例10: expose_url

def expose_url(url):
    if url is None:
        return u'<unknown>'
    if url[:5] == 'data:':
        return u'<data url>'
    url = truncatechars(url, MAX_URL_LENGTH)
    if isinstance(url, bytes):
        url = url.decode('utf-8', 'replace')
    return url
开发者ID:bsergean,项目名称:sentry,代码行数:9,代码来源:processor.py

示例11: get_metadata

 def get_metadata(self):
     message = strip(self.data.get('message'))
     if not message:
         title = '<unlabeled event>'
     else:
         title = truncatechars(message.splitlines()[0], 100)
     return {
         'title': title,
     }
开发者ID:280185386,项目名称:sentry,代码行数:9,代码来源:base.py

示例12: validate_data

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

    if not data.get("message"):
        data["message"] = "<no message value>"
    elif not isinstance(data["message"], basestring):
        raise APIError("Invalid value for message")
    elif len(data["message"]) > settings.SENTRY_MAX_MESSAGE_LENGTH:
        logger.info(
            "Truncated value for message due to length (%d chars)",
            len(data["message"]),
            **client_metadata(client, project)
        )
        data["message"] = truncatechars(data["message"], settings.SENTRY_MAX_MESSAGE_LENGTH)

    if data.get("culprit") and len(data["culprit"]) > MAX_CULPRIT_LENGTH:
        logger.info(
            "Truncated value for culprit due to length (%d chars)",
            len(data["culprit"]),
            **client_metadata(client, project)
        )
        data["culprit"] = truncatechars(data["culprit"], MAX_CULPRIT_LENGTH)

    if not data.get("event_id"):
        data["event_id"] = uuid.uuid4().hex
    if len(data["event_id"]) > 32:
        logger.info(
            "Discarded value for event_id due to length (%d chars)",
            len(data["event_id"]),
            **client_metadata(client, project)
        )
        data["event_id"] = uuid.uuid4().hex

    if "timestamp" in data:
        try:
            process_data_timestamp(data)
        except InvalidTimestamp, e:
            # Log the error, remove the timestamp, and continue
            logger.info(
                "Discarded invalid value for timestamp: %r",
                data["timestamp"],
                **client_metadata(client, project, exception=e)
            )
            del data["timestamp"]
开发者ID:BlaShadow,项目名称:sentry,代码行数:44,代码来源:coreapi.py

示例13: trim

def trim(
    value,
    max_size=settings.SENTRY_MAX_VARIABLE_SIZE,
    max_depth=6,
    object_hook=None,
    _depth=0,
    _size=0,
    **kwargs
):
    """
    Truncates a value to ```MAX_VARIABLE_SIZE```.

    The method of truncation depends on the type of value.
    """
    options = {
        'max_depth': max_depth,
        'max_size': max_size,
        'object_hook': object_hook,
        '_depth': _depth + 1,
    }

    if _depth > max_depth:
        if not isinstance(value, six.string_types):
            value = json.dumps(value)
        return trim(value, _size=_size, max_size=max_size)

    elif isinstance(value, dict):
        result = {}
        _size += 2
        for k in sorted(value.keys()):
            v = value[k]
            trim_v = trim(v, _size=_size, **options)
            result[k] = trim_v
            _size += len(force_text(trim_v)) + 1
            if _size >= max_size:
                break

    elif isinstance(value, (list, tuple)):
        result = []
        _size += 2
        for v in value:
            trim_v = trim(v, _size=_size, **options)
            result.append(trim_v)
            _size += len(force_text(trim_v))
            if _size >= max_size:
                break

    elif isinstance(value, six.string_types):
        result = truncatechars(value, max_size - _size)

    else:
        result = value

    if object_hook is None:
        return result
    return object_hook(result)
开发者ID:alexandrul,项目名称:sentry,代码行数:56,代码来源:safe.py

示例14: fix_culprit

    def fix_culprit(self, data, stacktraces):
        # This is a bit weird, since the original culprit we get
        # will be wrong, so we want to touch it up after we've processed
        # a stack trace.

        # In this case, we have a list of all stacktraces as a tuple
        # (stacktrace as dict, stacktrace class)
        # So we need to take the [1] index to get the Stacktrace class,
        # then extract the culprit string from that.
        data["culprit"] = truncatechars(stacktraces[-1][1].get_culprit_string(), MAX_CULPRIT_LENGTH)
开发者ID:jasonbeverage,项目名称:sentry,代码行数:10,代码来源:processor.py

示例15: get_title

 def get_title(self, metadata):
     ty = metadata.get('type')
     if ty is None:
         return metadata.get('function') or '<unknown>'
     if not metadata.get('value'):
         return ty
     return u'{}: {}'.format(
         ty,
         truncatechars(metadata['value'].splitlines()[0], 100),
     )
开发者ID:getsentry,项目名称:sentry,代码行数:10,代码来源:error.py


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