@@ -341,23 +341,27 @@ def decode(self, s, _w=WHITESPACE.match):
341341 containing a JSON document).
342342
343343 """
344- obj , end = self .raw_decode (s , idx = _w ( s , 0 ). end () )
344+ obj , end = self .raw_decode (s )
345345 end = _w (s , end ).end ()
346346 if end != len (s ):
347347 raise JSONDecodeError ("Extra data" , s , end )
348348 return obj
349349
350- def raw_decode (self , s , idx = 0 ):
350+ def raw_decode (self , s , idx = 0 , _w = WHITESPACE . match ):
351351 """Decode a JSON document from ``s`` (a ``str`` beginning with
352352 a JSON document) and return a 2-tuple of the Python
353353 representation and the index in ``s`` where the document ended.
354+ Whitespace at the beginning of the document will be ignored.
355+
356+ Optionally, ``idx`` can be used to specify an offset in ``s``
357+ where the document begins.
354358
355359 This can be used to decode a JSON document from a string that may
356360 have extraneous data at the end.
357361
358362 """
359363 try :
360- obj , end = self .scan_once (s , idx )
364+ obj , end = self .scan_once (s , idx = _w ( s , idx ). end () )
361365 except StopIteration as err :
362366 raise JSONDecodeError ("Expecting value" , s , err .value ) from None
363367 return obj , end
0 commit comments