Skip to content

Commit

Permalink
integrate codes into models.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Reitz committed Aug 20, 2011
1 parent d9a349c commit c75eaec
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions requests/models.py
Expand Up @@ -22,9 +22,11 @@
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):
Expand Down Expand Up @@ -202,13 +204,13 @@ def build(resp):
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)
Expand All @@ -226,7 +228,7 @@ def build(resp):
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
Expand Down

0 comments on commit c75eaec

Please sign in to comment.