From c75eaec8527b32a5b1bdf95c1c70f34a33f508d6 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Fri, 19 Aug 2011 20:12:33 -0400 Subject: [PATCH] integrate codes into models.py --- requests/models.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/requests/models.py b/requests/models.py index 7e8d51b6..2d7fc8fe 100644 --- a/requests/models.py +++ b/requests/models.py @@ -22,9 +22,11 @@ from .packages.poster.encode import multipart_encode from .packages.poster.streaminghttp import register_openers, get_handlers from .utils import dict_from_cookiejar from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects +from .status_codes import codes -REDIRECT_STATI = (301, 302, 303, 307) +REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved) + class Request(object): @@ -202,13 +204,13 @@ class Request(object): while ( ('location' in r.headers) and ((self.method in ('GET', 'HEAD')) or - (r.status_code is 303) or + (r.status_code is codes.see_other) or (self.allow_redirects)) ): r.close() - if not len(history) < 30: + if not len(history) < settings.max_redirects: raise TooManyRedirects() history.append(r) @@ -226,7 +228,7 @@ class Request(object): url = urljoin(r.url, urllib.quote(urllib.unquote(url))) # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 - if r.status_code is 303: + if r.status_code is codes.see_other: method = 'GET' else: method = self.method