本文整理汇总了Python中twisted.spread.jelly.unjelly函数的典型用法代码示例。如果您正苦于以下问题:Python unjelly函数的具体用法?Python unjelly怎么用?Python unjelly使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unjelly函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_classSecurity
def test_classSecurity(self):
"""
Test for class-level security of serialization.
"""
taster = jelly.SecurityOptions()
taster.allowInstancesOf(A, B)
a = A()
b = B()
c = C()
# add a little complexity to the data
a.b = b
a.c = c
# and a backreference
a.x = b
b.c = c
# first, a friendly insecure serialization
friendly = jelly.jelly(a, taster)
x = jelly.unjelly(friendly, taster)
self.assertIsInstance(x.c, jelly.Unpersistable)
# now, a malicious one
mean = jelly.jelly(a)
self.assertRaises(jelly.InsecureJelly, jelly.unjelly, mean, taster)
self.assertIdentical(x.x, x.b, "Identity mismatch")
# test class serialization
friendly = jelly.jelly(A, taster)
x = jelly.unjelly(friendly, taster)
self.assertIdentical(x, A, "A came back: %s" % x)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:27,代码来源:test_jelly.py
示例2: testClassSecurity
def testClassSecurity(self):
"""
test for class-level security of serialization
"""
taster = jelly.SecurityOptions()
taster.allowInstancesOf(A, B)
a = A()
b = B()
c = C()
# add a little complexity to the data
a.b = b
a.c = c
# and a backreference
a.x = b
b.c = c
# first, a friendly insecure serialization
friendly = jelly.jelly(a, taster)
x = jelly.unjelly(friendly, taster)
assert isinstance(x.c, jelly.Unpersistable), "C came back: %s" % x.c.__class__
# now, a malicious one
mean = jelly.jelly(a)
try:
x = jelly.unjelly(mean, taster)
assert 0, "x came back: %s" % x
except jelly.InsecureJelly:
# OK
pass
assert x.x is x.b, "Identity mismatch"
开发者ID:lhl,项目名称:songclub,代码行数:28,代码来源:test_jelly.py
示例3: testLotsaTypes
def testLotsaTypes(self):
"""
test for all types currently supported in jelly
"""
a = A()
jelly.unjelly(jelly.jelly(a))
jelly.unjelly(jelly.jelly(a.amethod))
items = [afunc, [1, 2, 3], not bool(1), bool(1), 'test', 20.3, (1,2,3), None, A, unittest, {'a':1}, A.amethod]
for i in items:
self.assertEquals(i, jelly.unjelly(jelly.jelly(i)))
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:10,代码来源:test_jelly.py
示例4: testSerialize
def testSerialize(self):
text = N_("Something is really wrong.")
self.cmsg = messages.Error(T_(text))
self.mmsg = jelly.unjelly(jelly.jelly(self.cmsg))
t = self.mmsg.translatables[0]
self.assertEquals(t.format, "Something is really wrong.")
self.assertEquals(self.mmsg.level, messages.ERROR)
self.amsg = jelly.unjelly(jelly.jelly(self.mmsg))
t = self.amsg.translatables[0]
self.assertEquals(t.format, "Something is really wrong.")
self.assertEquals(self.amsg.level, messages.ERROR)
开发者ID:flyapen,项目名称:UgFlu,代码行数:11,代码来源:test_common_messages.py
示例5: testTypeSecurity
def testTypeSecurity(self):
"""
test for type-level security of serialization
"""
taster = jelly.SecurityOptions()
dct = jelly.jelly({})
try:
jelly.unjelly(dct, taster)
assert 0, "Insecure Jelly unjellied successfully."
except jelly.InsecureJelly:
# OK, works
pass
开发者ID:lhl,项目名称:songclub,代码行数:12,代码来源:test_jelly.py
示例6: test_deprecatedUnjellyingInstanceAtom
def test_deprecatedUnjellyingInstanceAtom(self):
"""
Unjellying the instance atom is deprecated with 15.0.0.
"""
jelly.unjelly(["instance", ["class", "twisted.test.test_jelly.A"], ["dictionary"]])
warnings = self.flushWarnings()
self.assertEqual(len(warnings), 1)
self.assertEqual(
warnings[0]["message"],
"Unjelly support for the instance atom is deprecated since "
"Twisted 15.0.0. Upgrade peer for modern instance support.",
)
self.assertEqual(warnings[0]["category"], DeprecationWarning)
开发者ID:dumengnan,项目名称:ohmydata_spider,代码行数:13,代码来源:test_jelly.py
示例7: testPersistentStorage
def testPersistentStorage(self):
perst = [{}, 1]
def persistentStore(obj, jel, perst = perst):
perst[1] = perst[1] + 1
perst[0][perst[1]] = obj
return str(perst[1])
def persistentLoad(pidstr, unj, perst = perst):
pid = int(pidstr)
return perst[0][pid]
a = SimpleJellyTest(1, 2)
b = SimpleJellyTest(3, 4)
c = SimpleJellyTest(5, 6)
a.b = b
a.c = c
c.b = b
jel = jelly.jelly(a, persistentStore = persistentStore)
x = jelly.unjelly(jel, persistentLoad = persistentLoad)
assert x.b is x.c.b, "Identity failure."
# assert len(perst) == 3, "persistentStore should only be called 3 times."
assert perst[0], "persistentStore was not called."
assert x.b is a.b, "Persistent storage identity failure."
开发者ID:lhl,项目名称:songclub,代码行数:26,代码来源:test_jelly.py
示例8: test_persistentStorage
def test_persistentStorage(self):
perst = [{}, 1]
def persistentStore(obj, jel, perst=perst):
perst[1] = perst[1] + 1
perst[0][perst[1]] = obj
return str(perst[1])
def persistentLoad(pidstr, unj, perst=perst):
pid = int(pidstr)
return perst[0][pid]
a = SimpleJellyTest(1, 2)
b = SimpleJellyTest(3, 4)
c = SimpleJellyTest(5, 6)
a.b = b
a.c = c
c.b = b
jel = jelly.jelly(a, persistentStore=persistentStore)
x = jelly.unjelly(jel, persistentLoad=persistentLoad)
self.assertIdentical(x.b, x.c.b)
self.failUnless(perst[0], "persistentStore was not called.")
self.assertIdentical(x.b, a.b, "Persistent storage identity failure.")
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:26,代码来源:test_jelly.py
示例9: test_twiceUnjelliedFailureCheck
def test_twiceUnjelliedFailureCheck(self):
"""
The object which results from jellying a L{CopyableFailure}, unjellying
the result, creating a new L{CopyableFailure} from the result of that,
jellying it, and finally unjellying the result of that has a check
method which behaves the same way as the original L{CopyableFailure}'s
check method.
"""
original = pb.CopyableFailure(ZeroDivisionError())
self.assertIdentical(original.check(ZeroDivisionError), ZeroDivisionError)
self.assertIdentical(original.check(ArithmeticError), ArithmeticError)
copiedOnce = jelly.unjelly(jelly.jelly(original, invoker=DummyInvoker()))
derivative = pb.CopyableFailure(copiedOnce)
copiedTwice = jelly.unjelly(jelly.jelly(derivative, invoker=DummyInvoker()))
self.assertIdentical(copiedTwice.check(ZeroDivisionError), ZeroDivisionError)
self.assertIdentical(copiedTwice.check(ArithmeticError), ArithmeticError)
开发者ID:RCBiczok,项目名称:VTK,代码行数:16,代码来源:test_pbfailure.py
示例10: test_methodSelfIdentity
def test_methodSelfIdentity(self):
a = A()
b = B()
a.bmethod = b.bmethod
b.a = a
im_ = jelly.unjelly(jelly.jelly(b)).a.bmethod
self.assertEqual(im_.im_class, im_.im_self.__class__)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:7,代码来源:test_jelly.py
示例11: test_moreReferences
def test_moreReferences(self):
a = []
t = (a,)
a.append((t,))
s = jelly.jelly(t)
z = jelly.unjelly(s)
self.assertIdentical(z[0][0][0], z)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:7,代码来源:test_jelly.py
示例12: testInvalidate
def testInvalidate(self):
mcomp = planet.ManagerComponentState()
mflow = planet.ManagerFlowState()
mstate = planet.ManagerPlanetState()
mflow.append('components', mcomp)
mstate.append('flows', mflow)
astate = jelly.unjelly(jelly.jelly(mstate))
self.failUnless(isinstance(astate, planet.AdminPlanetState))
aflow, = astate.get('flows')
acomp, = aflow.get('components')
invalidates = []
def invalidate(obj):
invalidates.append(obj)
astate.addListener(self, invalidate=invalidate)
aflow.addListener(self, invalidate=invalidate)
acomp.addListener(self, invalidate=invalidate)
self.assertEquals(invalidates, [])
astate.invalidate()
self.assertEquals(invalidates, [acomp, aflow, astate])
开发者ID:flyapen,项目名称:UgFlu,代码行数:26,代码来源:test_common_planet.py
示例13: test_stressReferences
def test_stressReferences(self):
reref = []
toplevelTuple = ({"list": reref}, reref)
reref.append(toplevelTuple)
s = jelly.jelly(toplevelTuple)
z = jelly.unjelly(s)
self.assertIdentical(z[0]["list"], z[1])
self.assertIdentical(z[0]["list"][0], z)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:8,代码来源:test_jelly.py
示例14: test_dateTime
def test_dateTime(self):
dtn = datetime.datetime.now()
dtd = datetime.datetime.now() - dtn
input = [dtn, dtd]
c = jelly.jelly(input)
output = jelly.unjelly(c)
self.assertEqual(input, output)
self.assertNotIdentical(input, output)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:8,代码来源:test_jelly.py
示例15: test_typeBuiltin
def test_typeBuiltin(self):
"""
Test that a builtin type can be jellied and unjellied to the original
type.
"""
t = [str]
r = jelly.unjelly(jelly.jelly(t))
self.assertEqual(t, r)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:8,代码来源:test_jelly.py
示例16: test_typeNewStyle
def test_typeNewStyle(self):
"""
Test that a new style class type can be jellied and unjellied
to the original type.
"""
t = [D]
r = jelly.unjelly(jelly.jelly(t))
self.assertEqual(t, r)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:8,代码来源:test_jelly.py
示例17: test_typeOldStyle
def test_typeOldStyle(self):
"""
Test that an old style class type can be jellied and unjellied
to the original type.
"""
t = [C]
r = jelly.unjelly(jelly.jelly(t))
self.assertEquals(t, r)
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:8,代码来源:test_jelly.py
示例18: test_stressReferences
def test_stressReferences(self):
reref = []
toplevelTuple = ({'list': reref}, reref)
reref.append(toplevelTuple)
s = jelly.jelly(toplevelTuple)
z = jelly.unjelly(s)
self.assertIs(z[0]['list'], z[1])
self.assertIs(z[0]['list'][0], z)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:8,代码来源:test_jelly.py
示例19: _testSecurity
def _testSecurity(self, inputList, atom):
"""
Helper test method to test security options for a type.
@param inputList: a sample input for the type.
@param inputList: C{list}
@param atom: atom identifier for the type.
@type atom: C{str}
"""
c = jelly.jelly(inputList)
taster = jelly.SecurityOptions()
taster.allowBasicTypes()
# By default, it should succeed
jelly.unjelly(c, taster)
taster.allowedTypes.pop(atom)
# But it should raise an exception when disallowed
self.assertRaises(jelly.InsecureJelly, jelly.unjelly, c, taster)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:18,代码来源:test_jelly.py
示例20: testSimple
def testSimple(self):
"""
simplest test case
"""
self.failUnless(SimpleJellyTest('a', 'b').isTheSameAs(SimpleJellyTest('a', 'b')))
a = SimpleJellyTest(1, 2)
cereal = jelly.jelly(a)
b = jelly.unjelly(cereal)
self.failUnless(a.isTheSameAs(b))
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:9,代码来源:test_jelly.py
注:本文中的twisted.spread.jelly.unjelly函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论