예제 #1
0
 def _request(self, url_or_req, data):
     if isstringlike(url_or_req):
         req = Request(url_or_req, data)
     else:
         # already a urllib2.Request or ClientCookie.Request instance
         req = url_or_req
         if data is not None:
             req.add_data(data)
     return req
예제 #2
0
파일: _Opener.py 프로젝트: Bycacha/BYCACHA
 def _request(self, url_or_req, data):
     if isstringlike(url_or_req):
         req = Request(url_or_req, data)
     else:
         # already a urllib2.Request or ClientCookie.Request instance
         req = url_or_req
         if data is not None:
             req.add_data(data)
     return req
예제 #3
0
 def http_request(self, request):
     if not hasattr(request, "add_unredirected_header"):
         newrequest = Request(request._Request__original, request.data,
                              request.headers)
         try: newrequest.origin_req_host = request.origin_req_host
         except AttributeError: pass
         try: newrequest.unverifiable = request.unverifiable
         except AttributeError: pass
         request = newrequest
     return request
예제 #4
0
 def http_request(self, request):
     if not hasattr(request, "add_unredirected_header"):
         newrequest = Request(request._Request__original, request.data,
                              request.headers)
         try:
             newrequest.origin_req_host = request.origin_req_host
         except AttributeError:
             pass
         try:
             newrequest.unverifiable = request.unverifiable
         except AttributeError:
             pass
         request = newrequest
     return request
예제 #5
0
        def redirect_request(self, newurl, req, fp, code, msg, headers):
            """Return a Request or None in response to a redirect.

            This is called by the http_error_30x methods when a redirection
            response is received.  If a redirection should take place, return a
            new Request to allow http_error_30x to perform the redirect;
            otherwise, return None to indicate that an HTTPError should be
            raised.

            """
            if code in (301, 302, 303, "refresh") or \
                   (code == 307 and not req.has_data()):
                # Strictly (according to RFC 2616), 301 or 302 in response to
                # a POST MUST NOT cause a redirection without confirmation
                # from the user (of urllib2, in this case).  In practice,
                # essentially all clients do redirect in this case, so we do
                # the same.
                return Request(newurl,
                               headers=req.headers,
                               origin_req_host=req.get_origin_req_host(),
                               unverifiable=True)
            else:
                raise HTTPError(req.get_full_url(), code, msg, headers, fp)