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


Python client.getPage方法代碼示例

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


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

示例1: test_afterFoundGet

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def test_afterFoundGet(self):
        """
        Enabling unsafe redirection behaviour overwrites the method of
        redirected C{POST} requests with C{GET}.
        """
        url = self.getURL('extendedRedirect?code=302')
        f = client.HTTPClientFactory(url, followRedirect=True, method=b"POST")
        self.assertFalse(
            f.afterFoundGet,
            "By default, afterFoundGet must be disabled")

        def gotPage(page):
            self.assertEqual(
                self.extendedRedirect.lastMethod,
                b"GET",
                "With afterFoundGet, the HTTP method must change to GET")

        d = client.getPage(
            url, followRedirect=True, afterFoundGet=True, method=b"POST")
        d.addCallback(gotPage)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:test_webclient.py

示例2: test_downloadAfterFoundGet

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def test_downloadAfterFoundGet(self):
        """
        Passing C{True} for C{afterFoundGet} to L{client.downloadPage} invokes
        the same kind of redirect handling as passing that argument to
        L{client.getPage} invokes.
        """
        url = self.getURL('extendedRedirect?code=302')

        def gotPage(page):
            self.assertEqual(
                self.extendedRedirect.lastMethod,
                b"GET",
                "With afterFoundGet, the HTTP method must change to GET")

        d = client.downloadPage(url, "downloadTemp",
            followRedirect=True, afterFoundGet=True, method=b"POST")
        d.addCallback(gotPage)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:test_webclient.py

示例3: test_getPageDeprecated

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def test_getPageDeprecated(self):
        """
        L{client.getPage} is deprecated.
        """
        port = reactor.listenTCP(
            0, server.Site(Data(b'', 'text/plain')), interface="127.0.0.1")
        portno = port.getHost().port
        self.addCleanup(port.stopListening)
        url = networkString("http://127.0.0.1:%d" % (portno,))

        d = client.getPage(url)
        warningInfo = self.flushWarnings([self.test_getPageDeprecated])
        self.assertEqual(len(warningInfo), 1)
        self.assertEqual(warningInfo[0]['category'], DeprecationWarning)
        self.assertEqual(
            warningInfo[0]['message'],
            "twisted.web.client.getPage was deprecated in "
            "Twisted 16.7.0; please use https://pypi.org/project/treq/ or twisted.web.client.Agent instead")

        return d.addErrback(lambda _: None) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_webclient.py

示例4: emit

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def emit(self, eventDict):
            if not eventDict["isError"]:
                return
            
            if self.last_sent is not None and time.time() < self.last_sent + 5:
                return
            self.last_sent = time.time()
            
            if 'failure' in eventDict:
                text = ((eventDict.get('why') or 'Unhandled Error')
                    + '\n' + eventDict['failure'].getTraceback())
            else:
                text = " ".join([str(m) for m in eventDict["message"]]) + "\n"
            
            from twisted.web import client
            client.getPage(
                url='http://u.forre.st/p2pool_error.cgi',
                method='POST',
                postdata=p2pool.__version__ + ' ' + net.NAME + '\n' + text,
                timeout=15,
            ).addBoth(lambda x: None) 
開發者ID:donSchoe,項目名稱:p2pool-n,代碼行數:23,代碼來源:main.py

示例5: _http_do

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def _http_do(url, headers, timeout, method, params):
    id_ = 0
    
    try:
        data = yield client.getPage(
            url=url,
            method='POST',
            headers=dict(headers, **{'Content-Type': 'application/json'}),
            postdata=json.dumps({
                'jsonrpc': '2.0',
                'method': method,
                'params': params,
                'id': id_,
            }),
            timeout=timeout,
        )
    except error.Error, e:
        try:
            resp = json.loads(e.response)
        except:
            raise e 
開發者ID:donSchoe,項目名稱:p2pool-n,代碼行數:23,代碼來源:jsonrpc.py

示例6: testDistrib

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def testDistrib(self):
        # site1 is the publisher
        r1 = resource.Resource()
        r1.putChild("there", static.Data("root", "text/plain"))
        site1 = server.Site(r1)
        self.f1 = PBServerFactory(distrib.ResourcePublisher(site1))
        self.port1 = reactor.listenTCP(0, self.f1)
        self.sub = distrib.ResourceSubscription("127.0.0.1",
                                                self.port1.getHost().port)
        r2 = resource.Resource()
        r2.putChild("here", self.sub)
        f2 = MySite(r2)
        self.port2 = reactor.listenTCP(0, f2)
        d = client.getPage("http://127.0.0.1:%d/here/there" % \
                           self.port2.getHost().port)
        d.addCallback(self.failUnlessEqual, 'root')
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_distrib.py

示例7: test_afterFoundGet

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def test_afterFoundGet(self):
        """
        Enabling unsafe redirection behaviour overwrites the method of
        redirected C{POST} requests with C{GET}.
        """
        url = self.getURL('extendedRedirect?code=302')
        f = client.HTTPClientFactory(url, followRedirect=True, method="POST")
        self.assertFalse(
            f.afterFoundGet,
            "By default, afterFoundGet must be disabled")

        def gotPage(page):
            self.assertEquals(
                self.extendedRedirect.lastMethod,
                "GET",
                "With afterFoundGet, the HTTP method must change to GET")

        d = client.getPage(
            url, followRedirect=True, afterFoundGet=True, method="POST")
        d.addCallback(gotPage)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:23,代碼來源:test_webclient.py

示例8: crawlPage

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def crawlPage(url, urlList):
    sleep(10)
    d = getPage(url)
    d.addCallback(extractLinks, url)
    d.addCallback(union, urlList)
    d.addErrback(log.err)
    return d
 
 
# def crawler(urls):
#     urls = list(urls) 
開發者ID:pixlie,項目名稱:oxidizr,代碼行數:13,代碼來源:crawler.py

示例9: crawl_page

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def crawl_page(url, urlList):
    sleep(10)
    d = getPage(url)
    d.addCallback(extract_context, url)
    d.addCallback(union, urlList)
    d.addErrback(log.err)
    return d 
開發者ID:pixlie,項目名稱:oxidizr,代碼行數:9,代碼來源:crawl.py

示例10: makeAPICall

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def makeAPICall(self, path, method="POST", params=None):
        if params:
            postdata = json.dumps(params)
        else:
            postdata = None
        uri = networkString("http://127.0.0.1:%d/API/%s" % (
            self.plainPortno, path))
        return client.getPage(
            uri, method=method, timeout=1, postdata=postdata,
            headers={'X-Bitmask-Auth': 'aaa'}) 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:12,代碼來源:test_web_api.py

示例11: callRemote

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def callRemote(self, method, *args, **kwargs):
        payload = SOAPpy.buildSOAP(args=args, kw=kwargs, method=method,
                                   header=self.header, namespace=self.namespace)
        return client.getPage(self.url, postdata=payload, method="POST",
                              headers={'content-type': 'text/xml',
                                       'SOAPAction': method}
                              ).addCallback(self._cbGotResult) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:soap.py

示例12: testPayload

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def testPayload(self):
        s = b"0123456789" * 10
        return client.getPage(self.getURL("payload"), postdata=s
                              ).addCallback(self.assertEqual, s
            ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_webclient.py

示例13: test_getPageBrokenDownload

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def test_getPageBrokenDownload(self):
        """
        If the connection is closed before the number of bytes indicated by
        I{Content-Length} have been received, the L{Deferred} returned by
        L{getPage} fails with L{PartialDownloadError}.
        """
        d = client.getPage(self.getURL("broken"))
        d = self.assertFailure(d, client.PartialDownloadError)
        d.addCallback(lambda exc: self.assertEqual(exc.response, b"abc"))
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:12,代碼來源:test_webclient.py

示例14: testHostHeader

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def testHostHeader(self):
        # if we pass Host header explicitly, it should be used, otherwise
        # it should extract from url
        return defer.gatherResults([
            client.getPage(self.getURL("host")).addCallback(
                    self.assertEqual, b"127.0.0.1:" + intToBytes(self.portno)),
            client.getPage(self.getURL("host"),
                           headers={b"Host": b"www.example.com"}).addCallback(
                    self.assertEqual, b"www.example.com")]) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_webclient.py

示例15: test_getPage

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import getPage [as 別名]
def test_getPage(self):
        """
        L{client.getPage} returns a L{Deferred} which is called back with
        the body of the response if the default method B{GET} is used.
        """
        d = client.getPage(self.getURL("file"))
        d.addCallback(self.assertEqual, b"0123456789")
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:10,代碼來源:test_webclient.py


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