示例#1
0
    def __init__(self, detail=None, code=None):  # noqa pylint: disable=W0231
        if detail is None:
            detail = self.default_detail
        elif isinstance(detail, ValidationError):
            detail = [
                ValidationErrorData(item.messages[0], item.code.upper())
                for item in detail.error_list
            ]
        if code is None:
            code = self.default_code

        if isinstance(detail, list):
            self.detail = _get_error_details(detail, code)
        else:
            self.detail = [_get_error_details(detail, code)]
示例#2
0
    def __init__(self, detail, code=None, docs=None):
        if detail is None:
            detail = self.default_detail
        if code is None:
            code = self.default_code

        self.detail = _get_error_details(detail, code)
示例#3
0
    def to_internal_value(self, data):
        """Parse and validate collection filename."""
        data = super().to_internal_value(data)

        errors = {}

        filename = data["file"].name

        try:
            filename_tuple = parse_collection_filename(filename)
        except ValueError as exc:
            errors['filename'] = _get_error_details(exc,
                                                    default_code='invalid')
            log.error(
                'CollectionUploadSerializer validation of filename failed: %s',
                errors['filename'])
            raise ValidationError(errors)

        data.update({
            "filename":
            filename_tuple,
            "expected_namespace":
            filename_tuple.namespace,
            "expected_name":
            filename_tuple.name,
            "expected_version":
            filename_tuple.version,
            "mimetype": (mimetypes.guess_type(filename)[0]
                         or 'application/octet-stream')
        })
        return data
示例#4
0
    def __init__(self, detail, code=None):
        if code is None:
            code = self.default_code

        self.code = code
        self.detail = _get_error_details(detail, code)
        super(FieldError, self).__init__(self.detail)
示例#5
0
    def __init__(self, detail, code=None, status_code=500):
        if status_code is not None:
            self.status_code = status_code
        if code is not None:
            detail = {code: force_text(detail)}

        self.detail = _get_error_details(detail, code)
 def __init__(self, detail=None, code=None, status_code=None):
     if detail is None:
         detail = self.default_detail
     if code is None:
         code = self.default_code
     if status_code:
         self.status_code = status_code
     self.detail = _get_error_details(detail, code)
    def __init__(self, detail=None, code=None, url=None):
        if url is None:
            raise ValueError('APIException requires an url')

        if detail is None:
            detail = "{} {}".format(self.default_detail, url)
        if code is None:
            code = self.default_code

        self.detail = _get_error_details(detail, code)
示例#8
0
    def __init__(self, detail=None, code=None, error=None):
        if not error and detail is None:
            detail = self.default_detail
        elif error is not None:
            detail = error
        if code is None:
            code = self.default_code

        if isinstance(detail, list) or isinstance(detail, dict):
            detail = mark_safe(json.dumps(detail))

        self.detail = _get_error_details(detail, code)
示例#9
0
    def __init__(self, detail, code=None):
        if detail is None:
            detail = self.default_detail
        if code is None:
            code = self.default_code

        # For validation failures, we may collect may errors together, so the
        # details should always be coerced to a list if not already.
        if not isinstance(detail, dict) and not isinstance(detail, list):
            detail = [detail]

        self.detail = _get_error_details(detail, code)
示例#10
0
    def test_get_error_details(self):

        example = "string"
        lazy_example = _(example)

        assert _get_error_details(lazy_example) == example

        assert isinstance(
            _get_error_details(lazy_example),
            ErrorDetail
        )

        assert _get_error_details({'nested': lazy_example})['nested'] == example

        assert isinstance(
            _get_error_details({'nested': lazy_example})['nested'],
            ErrorDetail
        )

        assert _get_error_details([[lazy_example]])[0][0] == example

        assert isinstance(
            _get_error_details([[lazy_example]])[0][0],
            ErrorDetail
        )
    def test_get_error_details(self):

        example = "string"
        lazy_example = _(example)

        assert _get_error_details(lazy_example) == example

        assert isinstance(
            _get_error_details(lazy_example),
            ErrorDetail
        )

        assert _get_error_details({'nested': lazy_example})['nested'] == example

        assert isinstance(
            _get_error_details({'nested': lazy_example})['nested'],
            ErrorDetail
        )

        assert _get_error_details([[lazy_example]])[0][0] == example

        assert isinstance(
            _get_error_details([[lazy_example]])[0][0],
            ErrorDetail
        )
    def __init__(self, detail=None, code=None, url=None, field_name=None):
        if url is None:
            raise ValueError('APIException requires an url')
        if field_name is None:
            raise ValueError('APIException requires a field name')

        if detail is None:
            detail = {
                'reasone':
                "Couln't scrapped ! May be your Regex pattern Invalid or something else",
                'url': url,
                'field_name': field_name
            }
        if code is None:
            code = self.default_code

        self.detail = _get_error_details(detail, code)
示例#13
0
 def __str__(self):
     return _get_error_details(self.message, self.status)
示例#14
0
    def __init__(self, detail=None, code=None, message=None):  # noqa: D107
        detail = detail or message or self.default_detail
        code = code or self.default_code

        self.detail = _get_error_details(detail, code)
示例#15
0
 def __init__(self, detail=None, code=None, extra=None):  # noqa: D107
     self.code = code or self.default_code
     self.extra = extra
     self.detail = _get_error_details(detail, code)
示例#16
0
文件: license.py 项目: BElluu/posthog
 def __init__(self, code, detail):
     self.code = code
     self.detail = exceptions._get_error_details(detail, code)
示例#17
0
 def __init__(self, name, *args, **kwargs):
     super().__init__(*args, **kwargs)
     detail = {name: ['This field is required.']}
     self.detail = _get_error_details(detail)
示例#18
0
 def __init__(self):
     super().__init__()
     detail = {'shop': ['Invalid input. Object already exists']}
     self.detail = _get_error_details(detail)
示例#19
0
 def __init__(self):
     super().__init__()
     detail = {'open': ['Invalid input. Possible values are 0 or 1']}
     self.detail = _get_error_details(detail)
示例#20
0
 def __init__(self, name, *args, **kwargs):
     super().__init__(*args, **kwargs)
     detail = {name: 'not found.'}
     self.detail = _get_error_details(detail)
示例#21
0
 def add(self, code, detail):
     if code is not None:
         self.detail[code] = force_text(detail)
         self.detail = _get_error_details(self.detail, code)