This commit is contained in:
Kenneth Reitz
2012-08-21 01:06:33 +10:00
parent 0841940aea
commit d8dcd35316
+21 -3
View File
@@ -13,7 +13,7 @@ from datetime import datetime
from io import BytesIO
from .hooks import dispatch_hook, HOOKS
from .structures import CaseInsensitiveDict
from .structures import CaseInsensitiveDict, MultiDict
from .status_codes import codes
from .auth import HTTPBasicAuth, HTTPProxyAuth
@@ -31,7 +31,7 @@ from .exceptions import (
from .utils import (
get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,
stream_decode_response_unicode, get_netrc_auth, get_environ_proxies,
to_key_val_list, DEFAULT_CA_BUNDLE_PATH)
to_key_val_list, DEFAULT_CA_BUNDLE_PATH, parse_header_links)
from .compat import (
cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,
StringIO, is_py2, chardet, json, builtin_str, numeric_types)
@@ -833,12 +833,30 @@ class Response(object):
@property
def json(self):
"""Returns the json-encoded content of a request, if any."""
"""Returns the json-encoded content of a response, if any."""
try:
return json.loads(self.text or self.content)
except ValueError:
return None
@property
def links(self):
"""Returns the parsed header links of the response, if any."""
header = self.headers['link']
# l = MultiDict()
l = {}
if header:
links = parse_header_links(header)
for link in links:
key = link.get('rel') or link.get('url')
l[key] = link
return l
@property
def reason(self):
"""The HTTP Reason for the response."""