Aestate
errors.py
Go to the documentation of this file.
1 """Error classes used by simplejson
2 """
3 __all__ = ['JSONDecodeError']
4 
5 
6 def linecol(doc, pos):
7  lineno = doc.count('\n', 0, pos) + 1
8  if lineno == 1:
9  colno = pos + 1
10  else:
11  colno = pos - doc.rindex('\n', 0, pos)
12  return lineno, colno
13 
14 
15 def errmsg(msg, doc, pos, end=None):
16  lineno, colno = linecol(doc, pos)
17  msg = msg.replace('%r', repr(doc[pos:pos + 1]))
18  if end is None:
19  fmt = '%s: line %d column %d (char %d)'
20  return fmt % (msg, lineno, colno, pos)
21  endlineno, endcolno = linecol(doc, end)
22  fmt = '%s: line %d column %d - line %d column %d (char %d - %d)'
23  return fmt % (msg, lineno, colno, endlineno, endcolno, pos, end)
24 
25 
26 class JSONDecodeError(ValueError):
27  """Subclass of ValueError with the following additional properties:
28 
29  msg: The unformatted error message
30  doc: The JSON document being parsed
31  pos: The start index of doc where parsing failed
32  end: The end index of doc where parsing failed (may be None)
33  lineno: The line corresponding to pos
34  colno: The column corresponding to pos
35  endlineno: The line corresponding to end (may be None)
36  endcolno: The column corresponding to end (may be None)
37 
38  """
39 
40  # Note that this exception is used from _speedups
41  def __init__(self, msg, doc, pos, end=None):
42  ValueError.__init__(self, errmsg(msg, doc, pos, end=end))
43  self.msg = msg
44  self.doc = doc
45  self.pos = pos
46  self.end = end
47  self.lineno, self.colno = linecol(doc, pos)
48  if end is not None:
49  self.endlineno, self.endcolno = linecol(doc, end)
50  else:
51  self.endlineno, self.endcolno = None, None
52 
53  def __reduce__(self):
54  return self.__class__, (self.msg, self.doc, self.pos, self.end)
aestate.ajson.sim.errors.JSONDecodeError.__reduce__
def __reduce__(self)
Definition: errors.py:53
aestate.ajson.sim.errors.JSONDecodeError.pos
pos
Definition: errors.py:45
aestate.ajson.sim.errors.JSONDecodeError.msg
msg
Definition: errors.py:43
aestate.ajson.sim.errors.JSONDecodeError.doc
doc
Definition: errors.py:44
aestate.ajson.sim.errors.errmsg
def errmsg(msg, doc, pos, end=None)
Definition: errors.py:15
aestate.ajson.sim.errors.JSONDecodeError.__init__
def __init__(self, msg, doc, pos, end=None)
Definition: errors.py:41
aestate.ajson.sim.errors.JSONDecodeError.end
end
Definition: errors.py:46
aestate.ajson.sim.errors.linecol
def linecol(doc, pos)
Definition: errors.py:6
aestate.ajson.sim.errors.JSONDecodeError.colno
colno
Definition: errors.py:47
aestate.ajson.sim.errors.JSONDecodeError.endcolno
endcolno
Definition: errors.py:49
aestate.ajson.sim.errors.JSONDecodeError
Definition: errors.py:26