Example #1
0
 def http_response(self, request, response):
     if not hasattr(response, "seek"):
         response = seek_wrapper(response)
     _debug(response.read())
     _debug("*****************************************************")
     response.seek(0)
     return response
Example #2
0
 def http_response(self, request, response):
     if not hasattr(response, "seek"):
         response = seek_wrapper(response)
     _debug(response.read())
     _debug("*****************************************************")
     response.seek(0)
     return response
Example #3
0
        def http_error_302(self, req, fp, code, msg, headers):
            if headers.has_key('location'):
                newurl = headers['location']
            elif headers.has_key('uri'):
                newurl = headers['uri']
            else:
                return
            newurl = urlparse.urljoin(req.get_full_url(), newurl)

            # XXX Probably want to forget about the state of the current
            # request, although that might interact poorly with other
            # handlers that also use handler-specific request attributes
            new = self.redirect_request(newurl, req, fp, code, msg, headers)
            if new is None:
                return

            # remember where we started from
            if hasattr(req, "original_url"):
                new.original_url = req.original_url
            else:
                new.original_url = req.get_full_url()

            # loop detection
            # .error_302_dict[(url, code)] is number of times url
            # previously visited as a result of a redirection with this
            # code (error_30x_dict would be a better name).
            new.origin_req_host = req.origin_req_host
            if not hasattr(req, 'error_302_dict'):
                new.error_302_dict = req.error_302_dict = {(newurl, code): 1}
            else:
                ed = new.error_302_dict = req.error_302_dict
                nr_visits = ed.get((newurl, code), 0)
                # Refreshes generate fake 302s, so we can hit the same URL as
                # a result of the same redirection code twice without
                # necessarily being in a loop!  So, allow two visits to each
                # URL as a result of each redirection code.
                if len(ed) < self.max_redirections and nr_visits < 2:
                    ed[(newurl, code)] = nr_visits + 1
                else:
                    raise HTTPError(req.get_full_url(), code,
                                    self.inf_msg + msg, headers, fp)

            if ClientCookie.REDIRECT_DEBUG:
                _debug("redirecting to %s", newurl)

            # Don't close the fp until we are sure that we won't use it
            # with HTTPError.
            fp.read()
            fp.close()

            return self.parent.open(new)
Example #4
0
        def http_error_302(self, req, fp, code, msg, headers):
            if headers.has_key('location'):
                newurl = headers['location']
            elif headers.has_key('uri'):
                newurl = headers['uri']
            else:
                return
            newurl = urlparse.urljoin(req.get_full_url(), newurl)

            # XXX Probably want to forget about the state of the current
            # request, although that might interact poorly with other
            # handlers that also use handler-specific request attributes
            new = self.redirect_request(newurl, req, fp, code, msg, headers)
            if new is None:
                return

            # remember where we started from
            if hasattr(req, "original_url"):
                new.original_url = req.original_url
            else:
                new.original_url = req.get_full_url()

            # loop detection
            # .error_302_dict[(url, code)] is number of times url
            # previously visited as a result of a redirection with this
            # code (error_30x_dict would be a better name).
            new.origin_req_host = req.origin_req_host
            if not hasattr(req, 'error_302_dict'):
                new.error_302_dict = req.error_302_dict = {(newurl, code): 1}
            else:
                ed = new.error_302_dict = req.error_302_dict
                nr_visits = ed.get((newurl, code), 0)
                # Refreshes generate fake 302s, so we can hit the same URL as
                # a result of the same redirection code twice without
                # necessarily being in a loop!  So, allow two visits to each
                # URL as a result of each redirection code.
                if len(ed) < self.max_redirections and nr_visits < 2:
                    ed[(newurl, code)] = nr_visits + 1
                else:
                    raise HTTPError(req.get_full_url(), code,
                                    self.inf_msg + msg, headers, fp)

            if ClientCookie.REDIRECT_DEBUG:
                _debug("redirecting to %s", newurl)

            # Don't close the fp until we are sure that we won't use it
            # with HTTPError.  
            fp.read()
            fp.close()

            return self.parent.open(new)