當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。