当前位置: 首页>>代码示例>>Python>>正文


Python pycurl.Curl方法代码示例

本文整理汇总了Python中pycurl.Curl方法的典型用法代码示例。如果您正苦于以下问题:Python pycurl.Curl方法的具体用法?Python pycurl.Curl怎么用?Python pycurl.Curl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycurl的用法示例。


在下文中一共展示了pycurl.Curl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_curl_conn

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def _create_curl_conn(self, url):
        """
        Create a cURL connection object with useful default settings.
        """
        headers = []
        if self.user is not None and self.secret is not None:
            b64cred = base64.b64encode("{}:{}".format(self.user, self.secret))
            headers.append("Authorization: Basic {}".format(b64cred))

        conn = pycurl.Curl()

        if len(headers) > 0:
            conn.setopt(pycurl.HTTPHEADER, headers)

        conn.setopt(pycurl.URL, url)

        # github often redirects
        conn.setopt(pycurl.FOLLOWLOCATION, 1)

        return conn 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:22,代码来源:downloader.py

示例2: query

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def query(url):
  """
  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  """

  output = StringIO.StringIO()

  query = pycurl.Curl()
  query.setopt(pycurl.URL, url)
  query.setopt(pycurl.PROXY, 'localhost')
  query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  query.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
  query.setopt(pycurl.WRITEFUNCTION, output.write)

  try:
    query.perform()
    return output.getvalue()
  except pycurl.error as exc:
    raise ValueError("Unable to reach %s (%s)" % (url, exc)) 
开发者ID:torproject,项目名称:stem,代码行数:22,代码来源:custom_path_selection.py

示例3: query

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def query(url):
  """
  Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
  """

  output = io.BytesIO()

  query = pycurl.Curl()
  query.setopt(pycurl.URL, url)
  query.setopt(pycurl.PROXY, 'localhost')
  query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
  query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
  query.setopt(pycurl.WRITEFUNCTION, output.write)

  try:
    query.perform()
    return output.getvalue()
  except pycurl.error as exc:
    return "Unable to reach %s (%s)" % (url, exc)


# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running. 
开发者ID:torproject,项目名称:stem,代码行数:26,代码来源:client_usage_using_pycurl.py

示例4: _check_status

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def _check_status(self):
        """
        For internal use only. Only members of :class:`Tunnel`
        """
        try:
            output = io.BytesIO()

            query = pycurl.Curl()
            query.setopt(pycurl.URL, "%s:%s" % (self.addr, self.status_server.port))
            query.setopt(pycurl.PROXY, "127.0.0.1")
            query.setopt(pycurl.PROXYPORT, config.tor_proxy_port)
            query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
            query.setopt(pycurl.WRITEFUNCTION, output.write)
            query.perform()

            return "ONIONGROK_CLIENT_STATUS_SUCCESS" in output.getvalue().decode("utf8")
        except Exception as e:
            return False 
开发者ID:ethan2-0,项目名称:onion-expose,代码行数:20,代码来源:torutil.py

示例5: get_getter

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def get_getter(self):
        """Initialze a Curl object for a single GET request.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(pycurl.HTTPGET, 1)
        if self._query:
            self._url.query.update(self._query)
            self._query = None
        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 
开发者ID:kdart,项目名称:pycopia,代码行数:19,代码来源:client.py

示例6: get_URLencoded_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def get_URLencoded_poster(self):
        """Initialze a Curl object for a single POST request.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        data = urlparse.urlencode(self._data, True)
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.POST, 1)
        c.setopt(pycurl.POSTFIELDS, data)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        headers = self._headers[:]
        headers.append(httputils.ContentType("application/x-www-form-urlencoded"))
        headers.append(httputils.ContentLength(str(len(data))))
        c.setopt(c.HTTPHEADER, map(str, headers))
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:21,代码来源:client.py

示例7: get_form_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def get_form_poster(self):
        """Initialze a Curl object for a single POST request.

        This sends a multipart/form-data, which allows you to upload files.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        data = self._data.items()
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.HTTPPOST, data)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:18,代码来源:client.py

示例8: get_raw_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def get_raw_poster(self):
        """Initialze a Curl object for a single POST request.

        This sends whatever data you give it, without specifying the content
        type.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        ld = len(self._data)
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.POST, 1)
        c.setopt(c.READFUNCTION, DataWrapper(self._data).read)
        c.setopt(c.POSTFIELDSIZE, ld)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        headers = self._headers[:]
        headers.append(httputils.ContentType("")) # removes libcurl internal header
        headers.append(httputils.ContentLength(str(ld)))
        c.setopt(c.HTTPHEADER, map(str, headers))
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:25,代码来源:client.py

示例9: get_deleter

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [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

示例10: put

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def put(url, data, encoding, headers=None):
    """Make a PUT request to the url, using data in the message body,
    with the additional headers, if any"""

    if headers is None:
        headers = {}
    reply = -1  # default, non-http response

    curl = pycurl.Curl()
    curl.setopt(pycurl.URL, url)
    if len(headers) > 0:
        curl.setopt(pycurl.HTTPHEADER, [k + ': ' + v for k, v in list(headers.items())])
    curl.setopt(pycurl.PUT, 1)
    curl.setopt(pycurl.INFILESIZE, len(data))
    databuffer = BytesIO(data.encode(encoding))
    curl.setopt(pycurl.READDATA, databuffer)
    try:
        curl.perform()
        reply = curl.getinfo(pycurl.HTTP_CODE)
    except Exception:
        pass
    curl.close()

    return reply 
开发者ID:dpapathanasiou,项目名称:recipebook,代码行数:26,代码来源:restClient.py

示例11: _curl

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def _curl(self, payload, computer_id, exchange_token, message_api):
        # There are a few "if _PY3" checks below, because for Python 3 we
        # want to convert a number of values from bytes to string, before
        # assigning them to the headers.
        if _PY3 and isinstance(message_api, bytes):
            message_api = message_api.decode("ascii")
        headers = {"X-Message-API": message_api,
                   "User-Agent": "landscape-client/%s" % VERSION,
                   "Content-Type": "application/octet-stream"}
        if computer_id:
            if _PY3 and isinstance(computer_id, bytes):
                computer_id = computer_id.decode("ascii")
            headers["X-Computer-ID"] = computer_id
        if exchange_token:
            if _PY3 and isinstance(exchange_token, bytes):
                exchange_token = exchange_token.decode("ascii")
            headers["X-Exchange-Token"] = str(exchange_token)
        curl = pycurl.Curl()
        return (curl, fetch(self._url, post=True, data=payload,
                            headers=headers, cainfo=self._pubkey, curl=curl)) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:22,代码来源:transport.py

示例12: curl_init

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def curl_init(self, url = False):

        self.curl = pycurl.Curl()
        self.set_url(url = url)
        self.curl.setopt(self.curl.SSL_VERIFYPEER, False)

        if DEBUG:

            self._log(
                'Following HTTP redirects: %s' % (
                    str(self.follow_http_redirect)
                )
            )

        self.curl.setopt(self.curl.FOLLOWLOCATION, self.follow_http_redirect)
        self.curl.setopt(self.curl.CONNECTTIMEOUT, self.connect_timeout)
        self.curl.setopt(self.curl.TIMEOUT, self.timeout)
        self.curl.setopt(self.curl.TCP_KEEPALIVE, 1)
        self.curl.setopt(self.curl.TCP_KEEPIDLE, 2)

        if self.ignore_content_length:

            self.curl.setopt(self.curl.IGNORE_CONTENT_LENGTH, 136) 
开发者ID:saezlab,项目名称:pypath,代码行数:25,代码来源:curl.py

示例13: init_request

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def init_request(self):

        if self.init_url is not None:

            if self.progress is not None:

                self.progress.set_status('requesting cookie')

            self.init_curl = Curl(
                self.init_url,
                silent = True,
                debug = self.debug,
                cache = self.init_use_cache,
                req_headers = self.req_headers,
                follow = False,
            )
            headers = getattr(self.init_curl, self.init_fun)()
            self.req_headers.extend(headers)


    # caching: 
开发者ID:saezlab,项目名称:pypath,代码行数:23,代码来源:curl.py

示例14: perform

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def perform(self):
        self.__performHead = ""
        self.__performBody = ""
        self.__headersSent = ""

        try:
            conn = Request.to_pycurl_object(pycurl.Curl(), self)
            conn.perform()
            self.response_from_conn_object(conn, self.__performHead, self.__performBody)
        except pycurl.error as error:
            errno, errstr = error
            raise ReqRespException(ReqRespException.FATAL, errstr)
        finally:
            conn.close()

    # ######## ESTE conjunto de funciones no es necesario para el uso habitual de la clase 
开发者ID:xmendez,项目名称:wfuzz,代码行数:18,代码来源:Request.py

示例15: _initialize

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import Curl [as 别名]
def _initialize(self):
        # pycurl Connection pool
        self.m = pycurl.CurlMulti()
        self.handles = []

        for i in range(self.options.get("concurrent")):
            curl_h = pycurl.Curl()
            self.handles.append(curl_h)
            self.curlh_freelist.append(curl_h)

        # create threads
        self.ths = []

        for fn in ("_read_multi_stack",):
            th = Thread(target=getattr(self, fn))
            th.setName(fn)
            self.ths.append(th)
            th.start() 
开发者ID:xmendez,项目名称:wfuzz,代码行数:20,代码来源:myhttp.py


注:本文中的pycurl.Curl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。