#NEWLINE# def resolve_redirects( self , resp , req , stream = False , timeout = None , verify = True , cert = None , proxies = None , **adapter_kwargs ) : #NEWLINE# #INDENT# 'Receives a Response. Returns a generator of Responses.' #NEWLINE# i = 0 #NEWLINE# hist = [ ] #NEWLINE# while resp . is_redirect : #NEWLINE# #INDENT# prepared_request = req . copy ( ) #NEWLINE# if ( i > 0 ) : #NEWLINE# #INDENT# hist . append ( resp ) #NEWLINE# new_hist = list ( hist ) #NEWLINE# resp . history = new_hist #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# resp . content #NEWLINE# #UNINDENT# except ( ChunkedEncodingError , ContentDecodingError , RuntimeError ) : #NEWLINE# #INDENT# resp . raw . read ( decode_content = False ) #NEWLINE# #UNINDENT# if ( i >= self . max_redirects ) : #NEWLINE# #INDENT# raise TooManyRedirects ( ( 'Exceeded %s redirects.' % self . max_redirects ) ) #NEWLINE# #UNINDENT# resp . close ( ) #NEWLINE# url = resp . headers [ 'location' ] #NEWLINE# method = req . method #NEWLINE# if url . startswith ( '//' ) : #NEWLINE# #INDENT# parsed_rurl = urlparse ( resp . url ) #NEWLINE# url = ( '%s:%s' % ( parsed_rurl . scheme , url ) ) #NEWLINE# #UNINDENT# parsed = urlparse ( url ) #NEWLINE# url = parsed . geturl ( ) #NEWLINE# if ( not parsed . netloc ) : #NEWLINE# #INDENT# url = urljoin ( resp . url , requote_uri ( url ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# url = requote_uri ( url ) #NEWLINE# #UNINDENT# prepared_request . url = to_native_string ( url ) #NEWLINE# if ( resp . is_permanent_redirect and ( req . url != prepared_request . url ) ) : #NEWLINE# #INDENT# self . redirect_cache [ req . url ] = prepared_request . url #NEWLINE# #UNINDENT# if ( ( resp . status_code == codes . see_other ) and ( method != 'HEAD' ) ) : #NEWLINE# #INDENT# method = 'GET' #NEWLINE# #UNINDENT# if ( ( resp . status_code == codes . found ) and ( method != 'HEAD' ) ) : #NEWLINE# #INDENT# method = 'GET' #NEWLINE# #UNINDENT# if ( ( resp . status_code == codes . moved ) and ( method == 'POST' ) ) : #NEWLINE# #INDENT# method = 'GET' #NEWLINE# #UNINDENT# prepared_request . method = method #NEWLINE# if ( resp . status_code not in ( codes . temporary_redirect , codes . permanent_redirect ) ) : #NEWLINE# #INDENT# if ( 'Content-Length' in prepared_request . headers ) : #NEWLINE# #INDENT# del prepared_request . headers [ 'Content-Length' ] #NEWLINE# #UNINDENT# prepared_request . body = None #NEWLINE# #UNINDENT# headers = prepared_request . headers #NEWLINE# try : #NEWLINE# #INDENT# del headers [ 'Cookie' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# extract_cookies_to_jar ( prepared_request . _cookies , req , resp . raw ) #NEWLINE# prepared_request . _cookies . update ( self . cookies ) #NEWLINE# prepared_request . prepare_cookies ( prepared_request . _cookies ) #NEWLINE# proxies = self . rebuild_proxies ( prepared_request , proxies ) #NEWLINE# self . rebuild_auth ( prepared_request , resp ) #NEWLINE# req = prepared_request #NEWLINE# resp = self . send ( req , stream = stream , timeout = timeout , verify = verify , cert = cert , proxies = proxies , allow_redirects = False , ** adapter_kwargs ) #NEWLINE# extract_cookies_to_jar ( self . cookies , prepared_request , resp . raw ) #NEWLINE# i += 1 #NEWLINE# ( yield resp )