本文整理汇总了Python中neubot.http.message.Message.body方法的典型用法代码示例。如果您正苦于以下问题:Python Message.body方法的具体用法?Python Message.body怎么用?Python Message.body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neubot.http.message.Message
的用法示例。
在下文中一共展示了Message.body方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connection_ready
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import body [as 别名]
def connection_ready(self, stream):
''' Invoked when the connection is ready '''
method = self.conf["http.client.method"]
stdout = self.conf["http.client.stdout"]
uri = self.conf["http.client.uri"]
request = Message()
if method == "PUT":
fpath = uri.split("/")[-1]
if not os.path.exists(fpath):
logging.error("* Local file does not exist: %s", fpath)
sys.exit(1)
request.compose(method=method, uri=uri, keepalive=False,
mimetype="text/plain", body=open(fpath, "rb"))
else:
request.compose(method=method, uri=uri, keepalive=False)
response = Message()
if method == "GET" and not stdout:
fpath = uri.split("/")[-1]
if os.path.exists(fpath):
logging.error("* Local file already exists: %s", fpath)
sys.exit(1)
response.body = open(fpath, "wb")
else:
response.body = sys.stdout
stream.send_request(request, response)
示例2: test_collect_successful
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import body [as 别名]
def test_collect_successful(self):
''' Make sure the response is OK when collect succeeds '''
server = NegotiateServer(None)
server.register_module('abc', NegotiateServerModule())
stream = MinimalHttpStream()
request = Message(uri='/collect/abc')
request.body = StringIO.StringIO('{}')
server.process_request(stream, request)
response = stream.response
self.assertEqual(response.code, '200')
self.assertEqual(response.reason, 'Ok')
self.assertEqual(response.body, '{}')
self.assertEqual(response['connection'], 'close')
self.assertEqual(response['content-type'], 'application/json')
示例3: test_negotiate_successful
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import body [as 别名]
def test_negotiate_successful(self):
''' Make sure the response is OK when negotiate succeeds '''
server = NegotiateServer(None)
server.register_module('abc', NegotiateServerModule())
# Want to check authorized and nonauthorized streams
for position in range(CONFIG['negotiate.parallelism'] + 3):
stream = MinimalHttpStream()
request = Message(uri='/negotiate/abc')
request.body = StringIO.StringIO('{}')
server.process_request(stream, request)
response = stream.response
self.assertEqual(response.code, '200')
self.assertEqual(response.reason, 'Ok')
self.assertNotEqual(response['connection'], 'close')
self.assertEqual(response['content-type'], 'application/json')
# Note: authorization is empty when you're choked
body = json.loads(response.body)
if position < CONFIG['negotiate.parallelism']:
self.assertEqual(body, {
u'unchoked': 1,
u'queue_pos': position,
u'real_address': u'abc',
u'authorization': unicode(hash(stream))
})
else:
self.assertEqual(body, {
u'unchoked': 0,
u'queue_pos': position,
u'real_address': u'abc',
u'authorization': u'',
})
示例4: test_negotiate_red
# 需要导入模块: from neubot.http.message import Message [as 别名]
# 或者: from neubot.http.message.Message import body [as 别名]
def test_negotiate_red(self):
''' Verify that random early discard works as expected '''
server = NegotiateServer(None)
server.register_module('abc', NegotiateServerModule())
red_accepted, red_rejected, red_discarded = 0, 0, 0
while True:
# Create request and stream
request = Message(uri='/negotiate/abc')
request.body = StringIO.StringIO('{}')
stream = MinimalHttpStream()
# Should ALWAYS accept
if len(server.queue) < CONFIG['negotiate.min_thresh']:
server.process_request(stream, request)
self.assertEquals(server.queue[-1], stream)
# MAY accept or reject
elif len(server.queue) < CONFIG['negotiate.max_thresh']:
server.process_request(stream, request)
if server.queue[-1] == stream:
red_accepted += 1
else:
red_rejected += 1
# MUST reject
else:
server.process_request(stream, request)
self.assertNotEqual(server.queue[-1], stream)
red_discarded += 1
if red_discarded == 64:
break
self.assertTrue(red_accepted > 0 and red_rejected > 0 and
red_discarded == 64)