How to use the jsonlines.jsonlines.InvalidLineError function in jsonlines

To help you get started, we’ve selected a few jsonlines examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wbolster / jsonlines / jsonlines / jsonlines.py View on Github external
except StopIteration:
            six.raise_from(EOFError, None)

        if isinstance(line, six.binary_type):
            try:
                line = line.decode('utf-8')
            except UnicodeDecodeError as orig_exc:
                exc = InvalidLineError(
                    "line is not valid utf-8: {}".format(orig_exc),
                    line, lineno)
                six.raise_from(exc, orig_exc)

        try:
            value = self._loads(line)
        except ValueError as orig_exc:
            exc = InvalidLineError(
                "line contains invalid json: {}".format(orig_exc),
                line, lineno)
            six.raise_from(exc, orig_exc)

        if value is None:
            if allow_none:
                return None
            raise InvalidLineError(
                "line contains null value", line, lineno)

        if type is not None:
            valid = isinstance(value, TYPE_MAPPING[type])
            if type in (int, numbers.Number):
                valid = valid and not isinstance(value, bool)
            if not valid:
                raise InvalidLineError(
github wbolster / jsonlines / jsonlines / jsonlines.py View on Github external
"line contains invalid json: {}".format(orig_exc),
                line, lineno)
            six.raise_from(exc, orig_exc)

        if value is None:
            if allow_none:
                return None
            raise InvalidLineError(
                "line contains null value", line, lineno)

        if type is not None:
            valid = isinstance(value, TYPE_MAPPING[type])
            if type in (int, numbers.Number):
                valid = valid and not isinstance(value, bool)
            if not valid:
                raise InvalidLineError(
                    "line does not match requested type", line, lineno)

        return value
github wbolster / jsonlines / jsonlines / jsonlines.py View on Github external
raise RuntimeError('reader is closed')
        if type is not None and type not in TYPE_MAPPING:
            raise ValueError("invalid type specified")

        try:
            lineno, line = next(self._line_iter)
            while skip_empty and not line.rstrip():
                lineno, line = next(self._line_iter)
        except StopIteration:
            six.raise_from(EOFError, None)

        if isinstance(line, six.binary_type):
            try:
                line = line.decode('utf-8')
            except UnicodeDecodeError as orig_exc:
                exc = InvalidLineError(
                    "line is not valid utf-8: {}".format(orig_exc),
                    line, lineno)
                six.raise_from(exc, orig_exc)

        try:
            value = self._loads(line)
        except ValueError as orig_exc:
            exc = InvalidLineError(
                "line contains invalid json: {}".format(orig_exc),
                line, lineno)
            six.raise_from(exc, orig_exc)

        if value is None:
            if allow_none:
                return None
            raise InvalidLineError(
github wbolster / jsonlines / jsonlines / jsonlines.py View on Github external
"line is not valid utf-8: {}".format(orig_exc),
                    line, lineno)
                six.raise_from(exc, orig_exc)

        try:
            value = self._loads(line)
        except ValueError as orig_exc:
            exc = InvalidLineError(
                "line contains invalid json: {}".format(orig_exc),
                line, lineno)
            six.raise_from(exc, orig_exc)

        if value is None:
            if allow_none:
                return None
            raise InvalidLineError(
                "line contains null value", line, lineno)

        if type is not None:
            valid = isinstance(value, TYPE_MAPPING[type])
            if type in (int, numbers.Number):
                valid = valid and not isinstance(value, bool)
            if not valid:
                raise InvalidLineError(
                    "line does not match requested type", line, lineno)

        return value
github wbolster / jsonlines / jsonlines / jsonlines.py View on Github external
def __init__(self, msg, line, lineno):
        msg = "{} (line {})".format(msg, lineno)
        self.line = line.rstrip()
        self.lineno = lineno
        super(InvalidLineError, self).__init__(msg)

jsonlines

Library with helpers for the jsonlines file format

BSD-2-Clause
Latest version published 1 year ago

Package Health Score

68 / 100
Full package analysis

Similar packages