當前位置: 首頁>>代碼示例>>Python>>正文


Python pycurl.CUSTOMREQUEST屬性代碼示例

本文整理匯總了Python中pycurl.CUSTOMREQUEST屬性的典型用法代碼示例。如果您正苦於以下問題:Python pycurl.CUSTOMREQUEST屬性的具體用法?Python pycurl.CUSTOMREQUEST怎麽用?Python pycurl.CUSTOMREQUEST使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在pycurl的用法示例。


在下文中一共展示了pycurl.CUSTOMREQUEST屬性的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: url_put

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def url_put( url,          # GET URL
             params={},    # GET parameters
             data=None,    # Data for body
             content_type=None,  # Content type
             bind=None,    # Bind request to specified address
             json=True,    # Interpret result as JSON
             throw=True,   # Throw if status isn't 200
             timeout=None, # Seconds before giving up
             allow_redirects=True, #Allows URL to be redirected
             headers={},   # Hash of HTTP headers
             verify_keys=verify_keys_default  # Verify SSL keys
             ):
    """
    PUT to a URL, returning whatever came back.
    """

    content_type, data = __content_type_data(content_type, headers, data)
    headers["Content-Type"] = content_type

    curl = PycURLRunner(url, params, bind, timeout, allow_redirects, headers, verify_keys)

    curl.curl.setopt(pycurl.CUSTOMREQUEST, "PUT")
    curl.curl.setopt(pycurl.POSTFIELDS, data)

    return curl(json, throw) 
開發者ID:perfsonar,項目名稱:pscheduler,代碼行數:27,代碼來源:psurl.py

示例2: url_delete

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def url_delete( url,          # DELETE URL
                params={},    # DELETE parameters
                bind=None,    # Bind request to specified address
                throw=True,   # Throw if status isn't 200
                timeout=None, # Seconds before giving up
                allow_redirects=True, #Allows URL to be redirected
                headers=None, # Hash of HTTP headers
                verify_keys=verify_keys_default  # Verify SSL keys
             ):
    """
    Delete a URL.
    """

    curl = PycURLRunner(url, params, bind, timeout, allow_redirects, headers, verify_keys)

    curl.curl.setopt(pycurl.CUSTOMREQUEST, "DELETE")

    return curl(False, throw) 
開發者ID:perfsonar,項目名稱:pscheduler,代碼行數:20,代碼來源:psurl.py

示例3: get_deleter

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def get_deleter(self):
        """Initialze a Curl object for a single DELETE request.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(pycurl.CUSTOMREQUEST, "DELETE")
        c.setopt(c.URL, str(self._url))
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        c.setopt(c.HTTPHEADER, map(str, self._headers))
        self._set_common(c)
        return c, resp

    # sets options common to all operations 
開發者ID:kdart,項目名稱:pycopia,代碼行數:18,代碼來源:client.py

示例4: perform_fp

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def perform_fp(fp, method, url, header='', body=''):
    #logger.debug('perform: %s' % url)
    fp.setopt(pycurl.URL, url)

    if method == 'GET':
      fp.setopt(pycurl.HTTPGET, 1)

    elif method == 'POST':
      fp.setopt(pycurl.POST, 1)
      fp.setopt(pycurl.POSTFIELDS, body)

    elif method == 'HEAD':
      fp.setopt(pycurl.NOBODY, 1)

    else:
      fp.setopt(pycurl.CUSTOMREQUEST, method)

    headers = [h.strip('\r') for h in header.split('\n') if h]
    fp.setopt(pycurl.HTTPHEADER, headers)

    fp.perform() 
開發者ID:lanjelot,項目名稱:patator,代碼行數:23,代碼來源:patator.py

示例5: send_REST_request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def send_REST_request(ip, port, object, key, value, force=False):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/%s?%s=%s" %(
            ip, port, object, 
            urllib.quote_plus(key), 
            urllib.quote_plus(value))
        if force:
            url += "&force"
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.HTTPHEADER, headers)
        conn.setopt(pycurl.CUSTOMREQUEST, "delete")
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None
# end def send_REST_request 
開發者ID:Juniper,項目名稱:contrail-server-manager,代碼行數:22,代碼來源:smgr_delete.py

示例6: send_REST_request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def send_REST_request(ip, port, payload, file_name,
                      kickstart='', kickseed=''):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/image/upload" %(
            ip, port)
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.POST, 1)
        payload["file"] = (pycurl.FORM_FILE, file_name)
        if kickstart:
            payload["kickstart"] = (pycurl.FORM_FILE, kickstart)
        if kickseed:
            payload["kickseed"] = (pycurl.FORM_FILE, kickseed)
        conn.setopt(pycurl.HTTPPOST, payload.items())
        conn.setopt(pycurl.CUSTOMREQUEST, "PUT")
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None 
開發者ID:Juniper,項目名稱:contrail-server-manager,代碼行數:24,代碼來源:smgr_upload_image.py

示例7: send_REST_request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def send_REST_request(ip, port, object, payload):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/%s" %(
            ip, port, object)
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.HTTPHEADER, headers)
        conn.setopt(pycurl.POST, 1)
        conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
        conn.setopt(pycurl.CUSTOMREQUEST, "PUT")
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None 
開發者ID:Juniper,項目名稱:contrail-server-manager,代碼行數:19,代碼來源:server_pre_install.py

示例8: request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def request(self, method, url, body=None):
        def makeRequest(ignored):
            curl = CurlRequestDriver.curl
            curl.reset()

            curl.setopt(pycurl.URL, url)
            curl.setopt(pycurl.HEADERFUNCTION, self.receiveHeaders)
            curl.setopt(pycurl.WRITEFUNCTION, self.buffer.write)

            curl.setopt(pycurl.CUSTOMREQUEST, method)

            if body is not None:
                curl.setopt(pycurl.POSTFIELDS, body)

            headers = []
            for key, value in six.iteritems(self.headers):
                headers.append("{}: {}".format(key, value))
            curl.setopt(pycurl.HTTPHEADER, headers)

            d = threads.deferToThread(curl.perform)
            d.addCallback(self.receive)
            return d

        def releaseLock(result):
            CurlRequestDriver.lock.release()

            # Forward the result to the next handler.
            return result

        d = CurlRequestDriver.lock.acquire()

        # Make the request once we acquire the semaphore.
        d.addCallback(makeRequest)

        # Release the semaphore regardless of how the request goes.
        d.addBoth(releaseLock)
        return d 
開發者ID:ParadropLabs,項目名稱:Paradrop,代碼行數:39,代碼來源:http.py

示例9: request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def request(self, method, url, headers, post_data=None):
        s = util.StringIO.StringIO()
        curl = pycurl.Curl()

        if method == 'get':
            curl.setopt(pycurl.HTTPGET, 1)
        elif method == 'post':
            curl.setopt(pycurl.POST, 1)
            curl.setopt(pycurl.POSTFIELDS, post_data)
        else:
            curl.setopt(pycurl.CUSTOMREQUEST, method.upper())

        # pycurl doesn't like unicode URLs
        curl.setopt(pycurl.URL, util.utf8(url))

        curl.setopt(pycurl.WRITEFUNCTION, s.write)
        curl.setopt(pycurl.NOSIGNAL, 1)
        curl.setopt(pycurl.CONNECTTIMEOUT, 30)
        curl.setopt(pycurl.TIMEOUT, 80)
        curl.setopt(pycurl.HTTPHEADER, ['%s: %s' % (k, v)
                    for k, v in headers.iteritems()])
        if self._verify_ssl_certs:
            curl.setopt(pycurl.CAINFO, os.path.join(
                os.path.dirname(__file__), 'data/ca-certificates.crt'))
        else:
            curl.setopt(pycurl.SSL_VERIFYHOST, False)

        try:
            curl.perform()
        except pycurl.error, e:
            self._handle_request_error(e) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:33,代碼來源:http_client.py

示例10: set_binary_data

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def set_binary_data(self):
        """
        Set binary data to be transmitted attached to POST request.

        `binary_data` is either a bytes string, or a filename, or
        a list of key-value pairs of a multipart form.
        """

        if self.binary_data:

            if type(self.binary_data) is list:
                self.construct_binary_data()
            if type(self.binary_data) is bytes:
                self.binary_data_size = len(self.binary_data)
                self.binary_data_file = BytesIO()
                self.binary_data_file.write(self.binary_data)
                self.binary_data_file.seek(0)
            elif os.path.exists(self.binary_data):
                self.binary_data_size = os.path.getsize(self.binary_data)
                self.binary_data_file = open(self.binary_data, 'rb')

            self.curl.setopt(pycurl.POST, 1)
            self.curl.setopt(pycurl.POSTFIELDSIZE, self.binary_data_size)
            self.curl.setopt(pycurl.READFUNCTION, self.binary_data_file.read)
            self.curl.setopt(pycurl.CUSTOMREQUEST, 'POST')
            self.curl.setopt(pycurl.POSTREDIR, 3)
            self._log('Binary data added to query (not showing).') 
開發者ID:saezlab,項目名稱:pypath,代碼行數:29,代碼來源:curl.py

示例11: send_REST_request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def send_REST_request(self, ip, port, endpoint, payload,
                          method='POST', urlencode=False):
        try:
            response = StringIO()
            headers = ["Content-Type:application/json"]
            url = "http://%s:%s/%s" %(ip, port, endpoint)
            conn = pycurl.Curl()
            if method == "PUT":
                conn.setopt(pycurl.CUSTOMREQUEST, method)
                if urlencode == False:
                    first = True
                    for k,v in payload.iteritems():
                        if first:
                            url = url + '?'
                            first = False
                        else:
                            url = url + '&'
                        url = url + ("%s=%s" % (k,v))
                else:
                    url = url + '?' + payload
            if self.logger:
                self.logger.log(self.logger.INFO,
                                "Sending post request to %s" % url)
            conn.setopt(pycurl.URL, url)
            conn.setopt(pycurl.HTTPHEADER, headers)
            conn.setopt(pycurl.POST, 1)
            if urlencode == False:
                conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
            conn.setopt(pycurl.WRITEFUNCTION, response.write)
            conn.perform()
            return response.getvalue()
        except:
            return None 
開發者ID:Juniper,項目名稱:contrail-server-manager,代碼行數:35,代碼來源:sm_ansible_utils.py

示例12: send_REST_request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def send_REST_request(ip, port, object, payload, match_key=None,
                        match_value=None, detail=False, method="PUT"):
    try:
        args_str = ""
        response = StringIO()
        headers = ["Content-Type:application/json"]
        if method == "PUT":
            url = "http://%s:%s/%s" %(
                        ip, port, object)
        elif method == "GET":
            url = "http://%s:%s/%s" % (ip, port, object)
            if match_key:
                args_str += match_key + "=" + match_value
            if detail:
                args_str += "&detail"
            if args_str != '':
                url += "?" + args_str
        else:
            return None
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.HTTPHEADER, headers)
        if method == "PUT":
            conn.setopt(pycurl.POST, 1)
            conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
            conn.setopt(pycurl.CUSTOMREQUEST, "PUT")
        elif method == "GET":
            conn.setopt(pycurl.HTTPGET, 1)

        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None 
開發者ID:Juniper,項目名稱:contrail-server-manager,代碼行數:36,代碼來源:smgr_add.py

示例13: test_request_delete

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def test_request_delete(self):

        curl = pycurl.Curl()
        curl.setopt = MagicMock()
        curl.perform = MagicMock()
        curl.getinfo = MagicMock(return_value=200)
        curl.close = MagicMock()
        pycurl.Curl = MagicMock(return_value=curl)

        method = 'delete'
        url = 'http://localhost:4502/.cqactions.html'
        params = {'foo1': 'bar1', 'foo2': ['bar2a', 'bar2b']}
        handlers = {200: self._handler_dummy}

        result = pyaem.bagofrequests.request(method, url, params, handlers)

        curl.setopt.assert_any_call(pycurl.CUSTOMREQUEST, 'delete')
        curl.setopt.assert_any_call(pycurl.URL, 'http://localhost:4502/.cqactions.html')
        curl.setopt.assert_any_call(pycurl.FOLLOWLOCATION, 1)
        curl.setopt.assert_any_call(pycurl.FRESH_CONNECT, 1)

        # 5 calls including the one with pycurl.WRITEFUNCTION
        self.assertEqual(curl.setopt.call_count, 5)

        curl.perform.assert_called_once_with()
        curl.getinfo.assert_called_once_with(pycurl.HTTP_CODE)
        curl.close.assert_called_once_with()

        self.assertEqual(result.is_success(), True)
        self.assertEqual(result.message, 'some dummy message')
        self.assertEqual(result.response['request']['method'], 'delete')
        self.assertEqual(result.response['request']['url'], 'http://localhost:4502/.cqactions.html')
        self.assertEqual(result.response['request']['params'], params) 
開發者ID:Sensis,項目名稱:pyaem,代碼行數:35,代碼來源:test_bagofrequests.py

示例14: request

# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import CUSTOMREQUEST [as 別名]
def request(method, url, params, handlers, **kwargs):
    """Sends HTTP request to a specified URL.
    Parameters will be appended to URL automatically on HTTP get method.
    Response code will then be used to determine which handler should process the response.
    When response code does not match any handler, an exception will be raised.

    :param method: HTTP method (post, delete, get)
    :type method: str
    :param url: URL to send HTTP request to
    :type url: str
    :param params: Request parameters key-value pairs, use array value to represent multi parameters with the same name
    :type params: dict
    :param handlers: Response handlers key-value pairs, keys are response http code, values are callback methods
    :type handlers: dict
    :returns:  PyAemResult -- Result of the request containing status, response http code and body, and request info
    :raises: PyAemException
    """
    curl = pycurl.Curl()
    body_io = cStringIO.StringIO()

    if method == 'post':
        curl.setopt(pycurl.POST, 1)
        curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(params, True))
    elif method == 'delete':
        curl.setopt(pycurl.CUSTOMREQUEST, method)
    elif method == 'head':
        curl.setopt(pycurl.HEADER, True)
        curl.setopt(pycurl.NOBODY, True)
    else:
        url = '{0}?{1}'.format(url, urllib.urlencode(params, True))

    curl.setopt(pycurl.URL, url)
    curl.setopt(pycurl.FOLLOWLOCATION, 1)
    curl.setopt(pycurl.FRESH_CONNECT, 1)
    curl.setopt(pycurl.WRITEFUNCTION, body_io.write)

    curl.perform()

    response = {
        'http_code': curl.getinfo(pycurl.HTTP_CODE),
        'body': body_io.getvalue(),
        'request': {
            'method': method,
            'url': url,
            'params': params
        }
    }

    curl.close()

    if response['http_code'] in handlers:
        return handlers[response['http_code']](response, **kwargs)
    else:
        handle_unexpected(response, **kwargs) 
開發者ID:Sensis,項目名稱:pyaem,代碼行數:56,代碼來源:bagofrequests.py


注:本文中的pycurl.CUSTOMREQUEST屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。