本文整理匯總了Python中twisted.protocols.amp.ListOf方法的典型用法代碼示例。如果您正苦於以下問題:Python amp.ListOf方法的具體用法?Python amp.ListOf怎麽用?Python amp.ListOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.protocols.amp
的用法示例。
在下文中一共展示了amp.ListOf方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_toBox
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_toBox(self):
"""
L{ListOf.toBox} extracts the list of objects from the C{objects}
dictionary passed to it, using the C{name} key also passed to it,
serializes each of the elements in that list using the L{Argument}
instance previously passed to its initializer, combines the serialized
results, and inserts the result into the C{strings} dictionary using
the same C{name} key.
"""
stringList = amp.ListOf(self.elementType)
strings = amp.AmpBox()
for key in self.objects:
stringList.toBox(
key.encode("ascii"), strings, self.objects.copy(), None)
self.assertEqual(strings, self.strings)
示例2: test_fromBox
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_fromBox(self):
"""
L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
"""
stringList = amp.ListOf(self.elementType)
objects = {}
for key in self.strings:
stringList.fromBox(key, self.strings.copy(), objects, None)
self.assertEqual(objects, self.objects)
示例3: test_requiredArgumentWithNoneValueRaisesTypeError
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_requiredArgumentWithNoneValueRaisesTypeError(self):
"""
L{ListOf.toBox} raises C{TypeError} when passed a value of L{None}
for the argument.
"""
stringList = amp.ListOf(amp.Integer())
self.assertRaises(
TypeError, stringList.toBox, b'omitted', amp.AmpBox(),
{'omitted': None}, None)
示例4: test_optionalArgumentWithNoneValueOmitted
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_optionalArgumentWithNoneValueOmitted(self):
"""
L{ListOf.toBox} silently omits serializing any argument with a
value of L{None} that is designated as optional for the protocol.
"""
stringList = amp.ListOf(amp.Integer(), optional=True)
strings = amp.AmpBox()
stringList.toBox(b'omitted', strings, {b'omitted': None}, None)
self.assertEqual(strings, {})
示例5: test_optionalArgumentWithKeyMissingOmitted
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_optionalArgumentWithKeyMissingOmitted(self):
"""
L{ListOf.toBox} silently omits serializing any argument designated
as optional whose key is not present in the objects dictionary.
"""
stringList = amp.ListOf(amp.Integer(), optional=True)
stringList.toBox(b'ommited', amp.AmpBox(), {b'someOtherKey': 0}, None)
示例6: test_omittedOptionalArgumentDeserializesAsNone
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_omittedOptionalArgumentDeserializesAsNone(self):
"""
L{ListOf.fromBox} correctly reverses the operation performed by
L{ListOf.toBox} for optional arguments.
"""
stringList = amp.ListOf(amp.Integer(), optional=True)
objects = {}
stringList.fromBox(b'omitted', {}, objects, None)
self.assertEqual(objects, {'omitted': None})
示例7: test_toBox
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_toBox(self):
"""
L{ListOf.toBox} extracts the list of objects from the C{objects}
dictionary passed to it, using the C{name} key also passed to it,
serializes each of the elements in that list using the L{Argument}
instance previously passed to its initializer, combines the serialized
results, and inserts the result into the C{strings} dictionary using
the same C{name} key.
"""
stringList = amp.ListOf(self.elementType)
strings = amp.AmpBox()
for key in self.objects:
stringList.toBox(key, strings, self.objects.copy(), None)
self.assertEquals(strings, self.strings)
示例8: test_fromBox
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_fromBox(self):
"""
L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
"""
stringList = amp.ListOf(self.elementType)
objects = {}
for key in self.strings:
stringList.fromBox(key, self.strings.copy(), objects, None)
self.assertEquals(objects, self.objects)
示例9: test_requiredArgumentWithNoneValueRaisesTypeError
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_requiredArgumentWithNoneValueRaisesTypeError(self):
"""
L{ListOf.toBox} raises C{TypeError} when passed a value of C{None}
for the argument.
"""
stringList = amp.ListOf(amp.Integer())
self.assertRaises(
TypeError, stringList.toBox, 'omitted', amp.AmpBox(),
{'omitted': None}, None)
示例10: test_optionalArgumentWithNoneValueOmitted
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_optionalArgumentWithNoneValueOmitted(self):
"""
L{ListOf.toBox} silently omits serializing any argument with a
value of C{None} that is designated as optional for the protocol.
"""
stringList = amp.ListOf(amp.Integer(), optional=True)
strings = amp.AmpBox()
stringList.toBox('omitted', strings, {'omitted': None}, None)
self.assertEquals(strings, {})
示例11: test_optionalArgumentWithKeyMissingOmitted
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_optionalArgumentWithKeyMissingOmitted(self):
"""
L{ListOf.toBox} silently omits serializing any argument designated
as optional whose key is not present in the objects dictionary.
"""
stringList = amp.ListOf(amp.Integer(), optional=True)
stringList.toBox('ommited', amp.AmpBox(), {'someOtherKey': 0}, None)
示例12: test_omittedOptionalArgumentDeserializesAsNone
# 需要導入模塊: from twisted.protocols import amp [as 別名]
# 或者: from twisted.protocols.amp import ListOf [as 別名]
def test_omittedOptionalArgumentDeserializesAsNone(self):
"""
L{ListOf.fromBox} correctly reverses the operation performed by
L{ListOf.toBox} for optional arguments.
"""
stringList = amp.ListOf(amp.Integer(), optional=True)
objects = {}
stringList.fromBox('omitted', {}, objects, None)
self.assertEquals(objects, {'omitted': None})