def get_file(self, url, local_file, headers={}):
        logger.info('httplibcurl -X GET "%s" > %s ', url, local_file)
        response = self.send_request('GET', url, '', headers)
        fout = open(local_file, 'wb')
        CHUNK = 1024*256
        while  True:
            data = response.read(CHUNK)
            if not data:
                break
            fout.write(data)
        fout.close()
        response_headers = dict(response.getheaders())

        rst = { 'status':  response.status, 
                'header' : response_headers, 
                'body':    None, 
                'body_file': local_file, 
                }

        #check if read all response
        bytes_readed = os.path.getsize(local_file)
        bytes_expected = int(response_headers['content-length'])
        bytes_remaining = bytes_expected - bytes_readed
        if bytes_remaining:
            raise HTTPException(rst, 'transfer closed with bytes remaining to read!!! %d bytes readed, %d bytes remained ' % (bytes_readed, bytes_remaining))

        if (response.status in [200, 206]): 
            return rst
        else:
            raise HTTPException(rst)
 def put_file(self, url, local_file, headers={}):
     logger.info('pycurl -X PUT -T"%s" "%s" ', local_file, url)
     self._init_curl('PUT', url, headers)
     filesize = os.path.getsize(local_file) 
     self.c.setopt(pycurl.INFILESIZE, filesize) 
     self.c.setopt(pycurl.INFILE, open(local_file, 'rb')) 
     return self._do_request()
Esempio n. 3
0
    def send_request(self, verb, url, data, data_size, headers={}):
        logger.info('ll httplibcurl -X "%s" "%s" ', verb, url)
        for (k, v) in headers.items():
            logger.debug('> %s: %s' % (k, v))
        logger.debug('\n')
#logger.debug('> ' + shorten(data, 1024))
        o = urlparse(url)
        host = o.netloc
        path = o.path
        if o.query: 
            path+='?'
            path+=o.query

        if o.scheme == 'https':
            conn = httplib.HTTPSConnection(host)
        else:
            conn = httplib.HTTPConnection(host)

        conn.putrequest ( verb, path )
        if 'content-length' not in headers:
            headers['content-length'] = data_size

        for key in headers.keys ( ):
            conn.putheader ( str ( key ), str ( headers[key] ) )

        conn.endheaders ( )
        return conn
 def put(self, url, body='', headers={}):
     headers = copy.deepcopy(headers)
     logger.info('pycurl -X PUT -d "%s" "%s" ', shorten(body, 100), url)
     self._init_curl('PUT', url, headers)
     req_buf =  StringIO(body)
     self.c.setopt(pycurl.INFILESIZE, len(body)) 
     self.c.setopt(pycurl.READFUNCTION, req_buf.read)
     return self._do_request()
    def put_file_part(self, url, local_file, start, length, headers={}):
        logger.info('pycurl -X PUT -T"%s[%d->%d]" "%s" ', local_file, start, length, url)
        self._init_curl('PUT', url, headers)
        filesize = os.path.getsize(local_file) 

        self.c.setopt(pycurl.INFILESIZE, length) 
        self.c.setopt(pycurl.READFUNCTION, FilePartReader(open(local_file, 'rb'), start, length).read_callback)

        return self._do_request()
 def post(self, url, body='', headers={}, log=True):
     headers = copy.deepcopy(headers)
     if log: 
         logger.info('pycurl -X POST "%s" ', url)
     headersnew = { 'Content-Length': str(len(body))}
     headers.update(headersnew)
     self._init_curl('POST', url, headers)
     req_buf =  StringIO(body)
     self.c.setopt(pycurl.READFUNCTION, req_buf.read)
     return self._do_request()
 def post_multipart(self, url, local_file, filename='file1', fields={}, headers={}):
     post_info = ' '.join( ['-F "%s=%s"' % (k,urllib.quote(v)) for (k,v) in fields.items()])
     if local_file: 
         post_info += ' -F "%s=@%s" ' % (filename, local_file)
     logger.info('pycurl -X POST %s "%s" ', post_info, url)
     self._init_curl('POST', url, headers)
     values = fields.items()
     if filename:
         values.append( (filename, (pycurl.FORM_FILE, local_file)) )
     self.c.setopt(pycurl.HTTPPOST, values)
     return self._do_request()
 def post_multipart(self, url, local_file, filename='file1', fields={}, headers={}):
     logger.info('httplibcurl -X POST -F "%s" %s with fields: %s',  local_file, url, str(fields))
     headers = copy.deepcopy(headers)
     if local_file and filename:
         f = (filename, os.path.basename(local_file), open(local_file, 'rb').read())
         f_list = [f]
     else:
         f_list = []
     content_type, body = encode_multipart_formdata(fields.items(), f_list)
     headersnew = { 'Content-Type' : content_type,
             'Content-Length': str(len(body))}
     headers.update(headersnew)
     #req = urllib2.Request(url, body, headers)
     return self.post(url, body, headers) 
Esempio n. 9
0
    def send_request(self, verb, url, data, headers={}):
        logging.info("(%s): (%s)\n" % (verb, url))
        o = urlparse(url)
        host = o.netloc
        path = o.path
        if o.query:
            path += "?"
            path += o.query

        if o.scheme == "https":
            conn = httplib.HTTPSConnection(host)
        else:
            conn = httplib.HTTPConnection(host)
        conn.request(verb, path, data, headers)
        response = conn.getresponse()
        return response
Esempio n. 10
0
 def get_file(self, url, local_file, headers={}):
     logger.info('httplibcurl -X GET "%s" > %s ', url, local_file)
     response = self.send_request('GET', url, '', headers)
     fout = open(local_file, 'wb')
     CHUNK = 1024*256
     while  True:
         data = response.read(CHUNK)
         if not data:
             break
         fout.write(data)
     fout.close()
     rst = { 'status':  response.status, 
             'header' : dict(response.getheaders()), 
             'body':    None, 
             'body_file': local_file, 
             }
     if (response.status in [200, 206]): 
         return rst
     else:
         raise HTTPException(rst)
    def send_request(self, verb, url, data, headers={}):
        logger.info('ll httplibcurl -X "%s" "%s" ', verb, url)
        for (k, v) in headers.items():
            logger.debug('> %s: %s' % (k, v))
        logger.debug('\n')
        logger.debug('> ' + shorten(data, 1024))
        o = urlparse(url)
        host = o.netloc
        path = o.path
        if o.query: 
            path+='?'
            path+=o.query

        if o.scheme == 'https':
            conn = httplib.HTTPSConnection(host)
        else:
            conn = httplib.HTTPConnection(host)
        conn.request(verb, path, data, headers)
        response = conn.getresponse()
        return response
 def get(self, url, headers={}):
     logger.info('pycurl -X GET "%s" ', url)
     self._init_curl('GET', url, headers)
     return self._do_request()
Esempio n. 13
0
 def put_file(self, url, local_file, headers={}, upload_callback=None):
     logger.info('httplibcurl -X PUT -T "%s" %s ', local_file, url)
     return self.put(url, open(local_file, 'rb'), headers, upload_callback)
Esempio n. 14
0
def index(request):
	logging.info('info log')
	return contact(request)
Esempio n. 15
0
 def delete(self, url, headers={}):
     logger.info('pycurl -X DELETE "%s" ', url)
     self._init_curl('DELETE', url, headers)
     return self._do_request()
Esempio n. 16
0
 def get_file(self, url, local_file, headers={}):
     logger.info('pycurl -X GET "%s" > %s', url, local_file)
     self._init_curl('GET', url, headers, local_file)
     return self._do_request()
Esempio n. 17
0
 def put_file(self, url, local_file, headers={}):
     logger.info('httplibcurl -X PUT -T "%s" %s ', local_file, url)
     return self.put(url, open(local_file, 'rb').read(), headers)
Esempio n. 18
0
 def put_file(self, url, local_file, headers={}, upload_callback = None ):
     logger.info('httplibcurl -X PUT -T "%s" %s ',  local_file, url)
     return self.put(url, open(local_file, 'rb'), headers, upload_callback )
Esempio n. 19
0
 def get(self, url, headers={}):
     logger.info('pycurl -X GET "%s" ', url)
     self._init_curl('GET', url, headers)
     return self._do_request()
 def put_file(self, url, local_file, headers={}):
     logger.info('httplibcurl -X PUT -T "%s" %s ',  local_file, url)
     return self.put(url, open(local_file, 'rb').read(), headers)
 def head(self, url, headers={}):
     logger.info('pycurl -X HEAD "%s" ', url)
     self._init_curl('HEAD', url, headers)
     return self._do_request()
Esempio n. 22
0
def log(str):
    if 'SERVER_SOFTWARE' in os.environ:
        from bae.api import logging
        logging.info(str)
    else:
        print str
 def delete(self, url, headers={}):
     logger.info('pycurl -X DELETE "%s" ', url)
     self._init_curl('DELETE', url, headers)
     return self._do_request()
Esempio n. 24
0
 def head(self, url, headers={}):
     logger.info('pycurl -X HEAD "%s" ', url)
     self._init_curl('HEAD', url, headers)
     return self._do_request()
 def get_file(self, url, local_file, headers={}):
     logger.info('pycurl -X GET "%s" > %s', url, local_file)
     self._init_curl('GET', url, headers, local_file)
     return self._do_request()