From: Scott Burns Date: Wed, 23 Jan 2013 21:25:48 +0000 (-0600) Subject: Pass kwargs to json.loads X-Git-Tag: v1.2.0~72^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2bcc4a774a8ca1556bd95c32f044d818f3547a40;p=services%2Fpython-requests.git Pass kwargs to json.loads Not all JSON is created equally. This commit addresses when users want to take control of the json decode process. --- diff --git a/requests/models.py b/requests/models.py index 8885569..131bcd5 100644 --- a/requests/models.py +++ b/requests/models.py @@ -596,8 +596,11 @@ class Response(object): return content - def json(self): - """Returns the json-encoded content of a response, if any.""" + def json(self, **kwargs): + """Returns the json-encoded content of a response, if any. + + :param \*\*kwargs: Optional arguments that ``json.loads`` takes. + """ if not self.encoding and len(self.content) > 3: # No encoding set. JSON RFC 4627 section 3 states we should expect @@ -606,8 +609,8 @@ class Response(object): # a best guess). encoding = guess_json_utf(self.content) if encoding is not None: - return json.loads(self.content.decode(encoding)) - return json.loads(self.text or self.content) + return json.loads(self.content.decode(encoding), **kwargs) + return json.loads(self.text or self.content, **kwargs) @property def links(self):