Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(
"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
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(
"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
def __init__(self, msg, line, lineno):
msg = "{} (line {})".format(msg, lineno)
self.line = line.rstrip()
self.lineno = lineno
super(InvalidLineError, self).__init__(msg)