(self, *args, **kwargs)
return (hdr, buf)
http get implementation using the PyCurl
http get implementation using the PyCurl
http get implementation using the PyCurl
def get(self, *args, **kwargs):
        """http get implementation using the PyCurl"""
        hdr = CurlHeader()
        buf = strio()
        pyc = pycurl.Curl()
        self._set_defaults(pyc, hdr)
        try:
            (output_file, filep) = \
                    self._mkpycurl(pyc, hdr, buf, *args, **kwargs)
            Msg().out("curl url: ", self._url, l=Msg.DBG)
            Msg().out("curl arg: ", kwargs, l=Msg.DBG)
            pyc.perform()     # call pyculr
        except(IOError, OSError):
            return (None, None)
        except pycurl.error as error:
            # pylint: disable=unbalanced-tuple-unpacking
            errno, errstr = error.args
            hdr.data["X-ND-CURLSTATUS"] = errno
            if not hdr.data["X-ND-HTTPSTATUS"]:
                hdr.data["X-ND-HTTPSTATUS"] = errstr
        status_code = self.get_status_code(hdr.data["X-ND-HTTPSTATUS"])
        if "header" in kwargs:
            hdr.data["X-ND-HEADERS"] = kwargs["header"]
        if status_code == 401: # needs authentication
            pass
        elif 300 <= status_code <= 308: # redirect
            pass
        elif "ofile" in kwargs:
            filep.close()
            if status_code == 206 and "resume" in kwargs:
                pass
            elif status_code == 416 and "resume" in kwargs:
                kwargs["resume"] = False
                (hdr, buf) = self.get(self._url, **kwargs)
            elif status_code != 200:
                Msg().err("Error: in download: " + str(
                    hdr.data["X-ND-HTTPSTATUS"]))
                FileUtil(output_file).remove()
        return (hdr, buf)
def get ( self , * args , * * kwargs ) : hdr = CurlHeader ( ) buf = strio ( ) pyc = pycurl . Curl ( ) self . _set_defaults ( pyc , hdr ) try : ( output_file , filep ) = self . _mkpycurl ( pyc , hdr , buf , * args , * * kwargs ) Msg ( ) . out ( "curl url: " , self . _url , l = Msg . DBG ) Msg ( ) . out ( "curl arg: " , kwargs , l = Msg . DBG ) pyc . perform ( ) # call pyculr except ( IOError , OSError ) : return ( None , None ) except pycurl . error as error : # pylint: disable=unbalanced-tuple-unpacking errno , errstr = error . args hdr . data [ "X-ND-CURLSTATUS" ] = errno if not hdr . data [ "X-ND-HTTPSTATUS" ] : hdr . data [ "X-ND-HTTPSTATUS" ] = errstr status_code = self . get_status_code ( hdr . data [ "X-ND-HTTPSTATUS" ] ) if "header" in kwargs : hdr . data [ "X-ND-HEADERS" ] = kwargs [ "header" ] if status_code == 401 : # needs authentication pass elif 300 <= status_code <= 308 : # redirect pass elif "ofile" in kwargs : filep . close ( ) if status_code == 206 and "resume" in kwargs : pass elif status_code == 416 and "resume" in kwargs : kwargs [ "resume" ] = False ( hdr , buf ) = self . get ( self . _url , * * kwargs ) elif status_code != 200 : Msg ( ) . err ( "Error: in download: " + str ( hdr . data [ "X-ND-HTTPSTATUS" ] ) ) FileUtil ( output_file ) . remove ( ) return ( hdr , buf )