本文整理汇总了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
示例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
示例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)
示例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)
示例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
示例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
示例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
示例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)
示例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
示例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'})
示例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)
示例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
)
示例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
示例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")])
示例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