本文整理汇总了Python中twisted.spread.jelly.jelly函数的典型用法代码示例。如果您正苦于以下问题:Python jelly函数的具体用法?Python jelly怎么用?Python jelly使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jelly函数的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: test_oldSets
def test_oldSets(self):
"""
Test jellying C{sets.Set}: it should serialize to the same thing as
C{set} jelly, and be unjellied as C{set} if available.
"""
inputList = [jelly._sets.Set([1, 2, 3])]
inputJelly = jelly.jelly(inputList)
self.assertEqual(inputJelly, jelly.jelly([set([1, 2, 3])]))
output = jelly.unjelly(inputJelly)
# Even if the class is different, it should coerce to the same list
self.assertEqual(list(inputList[0]), list(output[0]))
if set is jelly._sets.Set:
self.assertIsInstance(output[0], jelly._sets.Set)
else:
self.assertIsInstance(output[0], set)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:15,代码来源:test_jelly.py
示例6: serialize
def serialize(self, object, perspective=None, method=None, args=None, kw=None):
"""Jelly an object according to the remote security rules for this broker.
"""
if isinstance(object, defer.Deferred):
object.addCallbacks(
self.serialize,
lambda x: x,
callbackKeywords={"perspective": perspective, "method": method, "args": args, "kw": kw},
)
return object
# XXX This call is NOT REENTRANT and testing for reentrancy is just
# crazy, so it likely won't be. Don't ever write methods that call the
# broker's serialize() method recursively (e.g. sending a method call
# from within a getState (this causes concurrency problems anyway so
# you really, really shouldn't do it))
# self.jellier = _NetJellier(self)
self.serializingPerspective = perspective
self.jellyMethod = method
self.jellyArgs = args
self.jellyKw = kw
try:
return jelly(object, self.security, None, self)
finally:
self.serializingPerspective = None
self.jellyMethod = None
self.jellyArgs = None
self.jellyKw = None
开发者ID:radical-software,项目名称:radicalspam,代码行数:30,代码来源:pb.py
示例7: 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
示例8: 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
示例9: test_typeSecurity
def test_typeSecurity(self):
"""
Test for type-level security of serialization.
"""
taster = jelly.SecurityOptions()
dct = jelly.jelly({})
self.assertRaises(jelly.InsecureJelly, jelly.unjelly, dct, taster)
开发者ID:himalin,项目名称:Nodejs_Python,代码行数:7,代码来源:test_jelly.py
示例10: 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
示例11: 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
示例12: save
def save(self, statefile=None):
"""Save state as a pickled jelly to a file on disk."""
if not statefile:
if not self._statefile:
raise MissingState("Could not find a state file to load.")
statefile = self._statefile
logging.debug("Saving state to: \t'%s'" % statefile)
fh = None
err = ''
try:
fh = open(statefile, 'w')
except MissingState as error:
err += error.message
except (IOError, OSError) as error:
err += "Error writing state file to '%s': %s" % (statefile, error)
else:
try:
pickle.dump(jelly.jelly(self), fh)
except AttributeError as error:
logging.debug("Tried jellying an unjelliable object: %s"
% error.message)
if fh is not None:
fh.flush()
fh.close()
开发者ID:gsathya,项目名称:bridgedb,代码行数:27,代码来源:persistent.py
示例13: 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
示例14: 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
示例15: 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
示例16: 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
示例17: 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
示例18: 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
示例19: 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
示例20: 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
注:本文中的twisted.spread.jelly.jelly函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论