From: Kenneth Reitz Date: Mon, 20 Aug 2012 15:06:33 +0000 (+1000) Subject: Fixes #711! X-Git-Tag: v0.13.9~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8dcd35316621df0691ab5fc3fe1d5f3d76f71bb;p=services%2Fpython-requests.git Fixes #711! --- diff --git a/requests/models.py b/requests/models.py index 02713dd..8565760 100644 --- a/requests/models.py +++ b/requests/models.py @@ -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."""