本文整理汇总了Python中kombu.messaging.Producer._prepare方法的典型用法代码示例。如果您正苦于以下问题:Python Producer._prepare方法的具体用法?Python Producer._prepare怎么用?Python Producer._prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kombu.messaging.Producer
的用法示例。
在下文中一共展示了Producer._prepare方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_prepare_is_already_unicode
# 需要导入模块: from kombu.messaging import Producer [as 别名]
# 或者: from kombu.messaging.Producer import _prepare [as 别名]
def test_prepare_is_already_unicode(self):
message = u"the quick brown fox"
channel = self.connection.channel()
p = Producer(channel, self.exchange, serializer="json")
m, ctype, cencoding = p._prepare(message, content_type="text/plain")
self.assertEqual(m, message.encode("utf-8"))
self.assertEqual(ctype, "text/plain")
self.assertEqual(cencoding, "utf-8")
m, ctype, cencoding = p._prepare(message, content_type="text/plain",
content_encoding="utf-8")
self.assertEqual(m, message.encode("utf-8"))
self.assertEqual(ctype, "text/plain")
self.assertEqual(cencoding, "utf-8")
示例2: test_prepare_custom_content_type
# 需要导入模块: from kombu.messaging import Producer [as 别名]
# 或者: from kombu.messaging.Producer import _prepare [as 别名]
def test_prepare_custom_content_type(self):
message = "the quick brown fox".encode("utf-8")
channel = self.connection.channel()
p = Producer(channel, self.exchange, serializer="json")
m, ctype, cencoding = p._prepare(message, content_type="custom")
self.assertEqual(m, message)
self.assertEqual(ctype, "custom")
self.assertEqual(cencoding, "binary")
m, ctype, cencoding = p._prepare(message, content_type="custom",
content_encoding="alien")
self.assertEqual(m, message)
self.assertEqual(ctype, "custom")
self.assertEqual(cencoding, "alien")
示例3: test_prepare
# 需要导入模块: from kombu.messaging import Producer [as 别名]
# 或者: from kombu.messaging.Producer import _prepare [as 别名]
def test_prepare(self):
message = {u"the quick brown fox": u"jumps over the lazy dog"}
channel = self.connection.channel()
p = Producer(channel, self.exchange, serializer="json")
m, ctype, cencoding = p._prepare(message, headers={})
self.assertDictEqual(message, anyjson.loads(m))
self.assertEqual(ctype, "application/json")
self.assertEqual(cencoding, "utf-8")
示例4: test_prepare_compression
# 需要导入模块: from kombu.messaging import Producer [as 别名]
# 或者: from kombu.messaging.Producer import _prepare [as 别名]
def test_prepare_compression(self):
message = {u"the quick brown fox": u"jumps over the lazy dog"}
channel = self.connection.channel()
p = Producer(channel, self.exchange, serializer="json")
headers = {}
m, ctype, cencoding = p._prepare(message, compression="zlib",
headers=headers)
self.assertEqual(ctype, "application/json")
self.assertEqual(cencoding, "utf-8")
self.assertEqual(headers["compression"], "application/x-gzip")
self.assertEqual(simplejson.loads(m.decode("zlib")), message)
示例5: test_prepare_compression
# 需要导入模块: from kombu.messaging import Producer [as 别名]
# 或者: from kombu.messaging.Producer import _prepare [as 别名]
def test_prepare_compression(self):
message = {u'the quick brown fox': u'jumps over the lazy dog'}
channel = self.connection.channel()
p = Producer(channel, self.exchange, serializer='json')
headers = {}
m, ctype, cencoding = p._prepare(message, compression='zlib',
headers=headers)
self.assertEqual(ctype, 'application/json')
self.assertEqual(cencoding, 'utf-8')
self.assertEqual(headers['compression'], 'application/x-gzip')
import zlib
self.assertEqual(anyjson.loads(
zlib.decompress(m).decode('utf-8')), message)