本文整理汇总了Python中pyamf.tests.util.check_buffer函数的典型用法代码示例。如果您正苦于以下问题:Python check_buffer函数的具体用法?Python check_buffer怎么用?Python check_buffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_buffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_save
def test_save(self):
s = sol.SOL("hello")
s.update({"name": "value", "spam": "eggs"})
x = StringIO()
s.save(x)
self.assertTrue(check_buffer(x.getvalue(), HelperTestCase.contents))
x = tempfile.mkstemp()[1]
try:
fp = open(x, "wb+")
self.assertEqual(fp.closed, False)
s.save(fp)
self.assertNotEquals(fp.tell(), 0)
fp.seek(0)
self.assertTrue(check_buffer(fp.read(), HelperTestCase.contents))
self.assertEqual(fp.closed, False)
self.assertTrue(check_buffer(open(x, "rb").read(), HelperTestCase.contents))
except:
if os.path.isfile(x):
os.unlink(x)
raise
示例2: test_save
def test_save(self):
s = sol.SOL('hello')
s.update({'name': 'value', 'spam': 'eggs'})
x = StringIO()
s.save(x)
self.assertTrue(check_buffer(x.getvalue(), HelperTestCase.contents))
x = tempfile.mkstemp()[1]
try:
fp = open(x, 'wb+')
self.assertEqual(fp.closed, False)
s.save(fp)
self.assertNotEquals(fp.tell(), 0)
fp.seek(0)
self.assertTrue(check_buffer(fp.read(), HelperTestCase.contents))
self.assertEqual(fp.closed, False)
self.assertTrue(
check_buffer(open(x, 'rb').read(), HelperTestCase.contents)
)
except:
if os.path.isfile(x):
os.unlink(x)
raise
示例3: test_deep
def test_deep(self):
class A(object):
class __amf__:
static = ('a')
class B(A):
class __amf__:
static = ('b')
class C(B):
class __amf__:
static = ('c')
pyamf.register_class(A, 'A')
pyamf.register_class(B, 'B')
pyamf.register_class(C, 'C')
x = C()
x.a = 'spam'
x.b = 'eggs'
x.c = 'foo'
stream = util.BufferedByteStream()
encoder = pyamf._get_encoder_class(pyamf.AMF0)(stream)
encoder.writeElement(x)
self.assertTrue(check_buffer(stream.getvalue(), ('\x10\x00\x01C', (
'\x00\x01a\x02\x00\x04spam',
'\x00\x01c\x02\x00\x03foo',
'\x00\x01b\x02\x00\x04eggs'
), '\x00\x00\t')))
示例4: test_amf3_encode
def test_amf3_encode(self):
x = sets.ImmutableSet(["1", "2", "3"])
self.assertTrue(
check_buffer(
pyamf.encode(x, encoding=pyamf.AMF3).getvalue(), ("\t\x07\x01", ("\x06\x031", "\x06\x033", "\x06\x032"))
)
)
示例5: test_amf0_encode
def test_amf0_encode(self):
x = sets.ImmutableSet(["1", "2", "3"])
self.assertTrue(
check_buffer(
pyamf.encode(x, encoding=pyamf.AMF0).getvalue(),
("\n\x00\x00\x00\x03", ("\x02\x00\x011", "\x02\x00\x013", "\x02\x00\x012")),
)
)
示例6: test_amf3_encode
def test_amf3_encode(self):
x = sets.ImmutableSet(['1', '2', '3'])
self.assertTrue(check_buffer(
pyamf.encode(x, encoding=pyamf.AMF3).getvalue(), (
'\t\x07\x01', (
'\x06\x031',
'\x06\x033',
'\x06\x032'
))
))
示例7: test_use_amf3
def test_use_amf3(self):
self.encoder.use_amf3 = True
x = {'foo': 'bar', 'baz': 'gak'}
self.encoder.writeElement(x)
self.assertTrue(check_buffer(self.buf.getvalue(), ('\x11\n\x0b', (
'\x01\x07foo\x06\x07bar',
'\x07baz\x06\x07gak\x01'
))))
示例8: test_encode
def test_encode(self):
stream = util.BufferedByteStream()
encoder = amf3.Encoder(stream)
x = flex.ObjectProxy(pyamf.MixedArray(a='spam', b=5))
encoder.writeElement(x)
self.assertTrue(check_buffer(stream.getvalue(), (
'\n\x07;flex.messaging.io.ObjectProxy\t\x01',
('\x03a\x06\x09spam', '\x03b\x04\x05'), '\x01')))
示例9: test_amf0_encode
def test_amf0_encode(self):
x = sets.ImmutableSet(['1', '2', '3'])
self.assertTrue(check_buffer(
pyamf.encode(x, encoding=pyamf.AMF0).getvalue(), (
'\n\x00\x00\x00\x03', (
'\x02\x00\x011',
'\x02\x00\x013',
'\x02\x00\x012'
))
))
示例10: test_amf3
def test_amf3(self):
bytes = ('\x00\xbf\x00\x00\x00aTCSO\x00\x04\x00\x00\x00\x00\x00\x08' + \
'EchoTest\x00\x00\x00\x03', (
'\x0fhttpUri\x06=http://localhost:8000/gateway/\x00',
'\x0frtmpUri\x06+rtmp://localhost/echo\x00'
)
)
stream = sol.encode(u'EchoTest',
{u'httpUri': u'http://localhost:8000/gateway/', u'rtmpUri': u'rtmp://localhost/echo'}, encoding=pyamf.AMF3)
self.assertTrue(check_buffer(stream.getvalue(), bytes))
示例11: test_save_file
def test_save_file(self):
fp = open(self.file_name, 'wb+')
s = sol.SOL('hello')
s.update({'name': 'value', 'spam': 'eggs'})
sol.save(s, fp)
fp.seek(0)
self.assertFalse(fp.closed)
self.assertTrue(check_buffer(fp.read(), self.contents))
fp.close()
示例12: test_save_name
def test_save_name(self):
s = sol.SOL("hello")
s.update({"name": "value", "spam": "eggs"})
sol.save(s, self.file_name)
fp = open(self.file_name, "rb")
try:
self.assertTrue(check_buffer(fp.read(), self.contents))
finally:
fp.close()
示例13: test_amf3
def test_amf3(self):
bytes = (
"\x00\xbf\x00\x00\x00aTCSO\x00\x04\x00\x00\x00\x00\x00\x08" + "EchoTest\x00\x00\x00\x03",
("\x0fhttpUri\x06=http://localhost:8000/gateway/\x00", "\x0frtmpUri\x06+rtmp://localhost/echo\x00"),
)
stream = sol.encode(
u"EchoTest",
{u"httpUri": u"http://localhost:8000/gateway/", u"rtmpUri": u"rtmp://localhost/echo"},
encoding=pyamf.AMF3,
)
self.assertTrue(check_buffer(stream.getvalue(), bytes))
示例14: test_elementtree_tag
def test_elementtree_tag(self):
class NotAnElement(object):
items = lambda self: []
def __iter__(self):
return iter([])
foo = NotAnElement()
foo.tag = 'foo'
foo.text = 'bar'
foo.tail = None
self.encoder.writeElement(foo)
self.assertTrue(check_buffer(self.buf.getvalue(), ('\x03', (
'\x00\x04text\x02\x00\x03bar',
'\x00\x04tail\x05',
'\x00\x03tag\x02\x00\x03foo',
), '\x00\x00\t')))
示例15: test_old_style_classes
def test_old_style_classes(self):
class Person:
pass
pyamf.register_class(Person, 'spam.eggs.Person')
u = Person()
u.family_name = 'Doe'
u.given_name = 'Jane'
self.encoder.writeElement(u)
self.assertTrue(check_buffer(
self.buf.getvalue(), (
'\x10\x00\x10spam.eggs.Person', (
'\x00\x0bfamily_name\x02\x00\x03Doe',
'\x00\ngiven_name\x02\x00\x04Jane'
),
'\x00\x00\t'
)
))