(self, pyc, hdr, buf, *args, **kwargs)
return(output_file, filep)
Prepare curl command line according to invocation options
Prepare curl command line according to invocation options
Prepare curl command line according to invocation options
def _mkpycurl(self, pyc, hdr, buf, *args, **kwargs):
        """Prepare curl command line according to invocation options"""
        self._url = str(args[0])
        pyc.setopt(pycurl.URL, self._url)
        if "follow" in kwargs:
            pyc.setopt(pyc.FOLLOWLOCATION, kwargs["follow"])
        if "post" in kwargs:
            pyc.setopt(pyc.POST, 1)
            pyc.setopt(pyc.HTTPHEADER, ['Content-Type: application/json'])
            pyc.setopt(pyc.POSTFIELDS, json.dumps(kwargs["post"]))
        if "sizeonly" in kwargs:
            hdr.sizeonly = True
        if "proxy" in kwargs and kwargs["proxy"]:
            pyc.setopt(pyc.PROXY, pyc.USERAGENT, kwargs["proxy"])
        if "ctimeout" in kwargs:
            pyc.setopt(pyc.CONNECTTIMEOUT, kwargs["ctimeout"])
        if "header" in kwargs:  # avoid known pycurl bug
            clean_header_list = []
            for header_item in kwargs["header"]:
                if str(header_item).startswith("Authorization: Bearer"):
                    if "Signature=" in self._url:
                        continue
                    if "redirect" in kwargs:
                        continue
                clean_header_list.append(str(header_item))
            pyc.setopt(pyc.HTTPHEADER, clean_header_list)
        if "v" in kwargs:
            pyc.setopt(pyc.VERBOSE, kwargs["v"])
        if "nobody" in kwargs:
            pyc.setopt(pyc.NOBODY, kwargs["nobody"])  # header only no content
        if "timeout" in kwargs:
            pyc.setopt(pyc.TIMEOUT, kwargs["timeout"])
        if "ofile" in kwargs:
            output_file = kwargs["ofile"]
            pyc.setopt(pyc.TIMEOUT, self.download_timeout)
            openflags = "wb"
            if "resume" in kwargs and kwargs["resume"]:
                pyc.setopt(pyc.RESUME_FROM, FileUtil(output_file).size())
                openflags = "ab"
            try:
                filep = open(output_file, openflags)
            except(IOError, OSError):
                Msg().err("Error: opening download file: %s" % output_file)
                raise
            pyc.setopt(pyc.WRITEDATA, filep)
        else:
            filep = None
            output_file = ""
            pyc.setopt(pyc.WRITEFUNCTION, buf.write)
        hdr.data["X-ND-CURLSTATUS"] = 0
        return(output_file, filep)
def _mkpycurl ( self , pyc , hdr , buf , * args , * * kwargs ) : self . _url = str ( args [ 0 ] ) pyc . setopt ( pycurl . URL , self . _url ) if "follow" in kwargs : pyc . setopt ( pyc . FOLLOWLOCATION , kwargs [ "follow" ] ) if "post" in kwargs : pyc . setopt ( pyc . POST , 1 ) pyc . setopt ( pyc . HTTPHEADER , [ 'Content-Type: application/json' ] ) pyc . setopt ( pyc . POSTFIELDS , json . dumps ( kwargs [ "post" ] ) ) if "sizeonly" in kwargs : hdr . sizeonly = True if "proxy" in kwargs and kwargs [ "proxy" ] : pyc . setopt ( pyc . PROXY , pyc . USERAGENT , kwargs [ "proxy" ] ) if "ctimeout" in kwargs : pyc . setopt ( pyc . CONNECTTIMEOUT , kwargs [ "ctimeout" ] ) if "header" in kwargs : # avoid known pycurl bug clean_header_list = [ ] for header_item in kwargs [ "header" ] : if str ( header_item ) . startswith ( "Authorization: Bearer" ) : if "Signature=" in self . _url : continue if "redirect" in kwargs : continue clean_header_list . append ( str ( header_item ) ) pyc . setopt ( pyc . HTTPHEADER , clean_header_list ) if "v" in kwargs : pyc . setopt ( pyc . VERBOSE , kwargs [ "v" ] ) if "nobody" in kwargs : pyc . setopt ( pyc . NOBODY , kwargs [ "nobody" ] ) # header only no content if "timeout" in kwargs : pyc . setopt ( pyc . TIMEOUT , kwargs [ "timeout" ] ) if "ofile" in kwargs : output_file = kwargs [ "ofile" ] pyc . setopt ( pyc . TIMEOUT , self . download_timeout ) openflags = "wb" if "resume" in kwargs and kwargs [ "resume" ] : pyc . setopt ( pyc . RESUME_FROM , FileUtil ( output_file ) . size ( ) ) openflags = "ab" try : filep = open ( output_file , openflags ) except ( IOError , OSError ) : Msg ( ) . err ( "Error: opening download file: %s" % output_file ) raise pyc . setopt ( pyc . WRITEDATA , filep ) else : filep = None output_file = "" pyc . setopt ( pyc . WRITEFUNCTION , buf . write ) hdr . data [ "X-ND-CURLSTATUS" ] = 0 return ( output_file , filep )