当前位置: 首页>>代码示例>>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;未经允许,请勿转载。