本文整理汇总了Python中fast.ProtectedRef.ProtectedRef类的典型用法代码示例。如果您正苦于以下问题:Python ProtectedRef类的具体用法?Python ProtectedRef怎么用?Python ProtectedRef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProtectedRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_permitted_writer_overwrite
def test_permitted_writer_overwrite(self):
x = ProtectedRef(0, None, self.allowUserWrite(self.bobUser))
assert x.update(self.aliceUser, self.aliceUser, 42) == UpdateResult.Unknown
assert x.update(self.bobUser, self.bobUser, 43) == UpdateResult.Unknown
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v), 43)
self.assertEqual(JeevesLib.concretize(self.bobUser, x.v), 43)
self.assertEqual(JeevesLib.concretize(self.carolUser, x.v), 43)
示例2: test_determine_writer_trust_later
def test_determine_writer_trust_later(self):
x = ProtectedRef(0, None
, lambda _this: lambda ictxt: lambda octxt:
JeevesLib.jhas(octxt, ictxt))
x.update(self.aliceUser, self.aliceUser, 42)
self.assertEqual(JeevesLib.concretize([self.aliceUser], x.v), 42)
self.assertEqual(JeevesLib.concretize([], x.v), 0)
示例3: test_output_write_policies_involving_this_can_update
def test_output_write_policies_involving_this_can_update(self):
x = ProtectedRef(0, None
, lambda v: lambda ictxt: lambda _:
v == 0 and ictxt == self.aliceUser)
x.update(self.aliceUser, self.aliceUser, 1)
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v), 1)
x.update(self.aliceUser, self.aliceUser, 3)
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v), 1)
示例4: test_write_selectively_allowed
def test_write_selectively_allowed(self):
x = ProtectedRef(0, None
, lambda _this: lambda ictxt: lambda octxt:
ictxt == self.aliceUser and octxt == self.bobUser)
assert x.update(self.aliceUser, self.aliceUser, 42) == UpdateResult.Unknown
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v), 0)
self.assertEqual(JeevesLib.concretize(self.bobUser, x.v), 42)
self.assertEqual(JeevesLib.concretize(self.carolUser, x.v), 0)
示例5: test_output_varies_depending_on_viewer
def test_output_varies_depending_on_viewer(self):
x = ProtectedRef(0, None
, lambda _this: lambda ictxt: lambda octxt:
ictxt == self.aliceUser and octxt == self.bobUser)
x.update(self.aliceUser, self.aliceUser, 42)
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v), 0)
self.assertEqual(JeevesLib.concretize(self.bobUser, x.v), 42)
self.assertEqual(JeevesLib.concretize(self.carolUser, x.v), 0)
示例6: test_function_facets_cannot_write
def test_function_facets_cannot_write(self):
def id(x):
return x
def inc(x):
return x+1
x = ProtectedRef(id, None, self.allowUserWrite(self.bobUser))
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v)(1), 1)
x.update(self.aliceUser, self.aliceUser, inc)
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v)(1), 1)
示例7: test_prevent_flow_of_untrusted_writes
def test_prevent_flow_of_untrusted_writes(self):
x = ProtectedRef(0, None, self.allowUserWrite(self.aliceUser))
assert x.update(self.aliceUser, self.aliceUser, 42) == UpdateResult.Unknown
y = ProtectedRef(1, None, self.allowUserWrite(self.bobUser))
assert y.update(self.bobUser, self.bobUser, x.v) == UpdateResult.Unknown
self.assertEqual(JeevesLib.concretize(self.aliceUser, x.v), 42)
self.assertEqual(JeevesLib.concretize(self.bobUser, x.v), 42)
self.assertEqual(JeevesLib.concretize(self.aliceUser, y.v), 0)
self.assertEqual(JeevesLib.concretize(self.bobUser, y.v), 0)
示例8: testBehavioralGood
def testBehavioralGood(self):
touchedBadData = False
def f(x):
return x+1
x = ProtectedRef(lambda x: x, None
, lambda _this: lambda ic: lambda touchedBad: not touchedBad)
self.assertEqual(JeevesLib.concretize(None, (x.v)(1)), 1)
assert x.update(None, None, f) == UpdateResult.Unknown
self.assertEqual(JeevesLib.concretize(None, (x.v)(1)), 2)
示例9: testBehavioralSanitizationBad
def testBehavioralSanitizationBad(self):
touchedBadData = False
def f(s):
global touchedBadData
if s == "bad":
touchedBadData = True
return s
x = ProtectedRef("dunno", None
, lambda _this: lambda ic: lambda oc: not touchedBadData)
assert x.update(None, None, f("bad")) == UpdateResult.Unknown
print touchedBadData
self.assertEqual(JeevesLib.concretize(None, x.v), "dunno")
示例10: __init__
def __init__(self, owner):
self.owner = owner
self.shipRef = ProtectedRef(NoShip()
# Policy for updating: must be owner and there can't be a ship there
# already.
, lambda ship: lambda ic: ship == NoShip() and self.isOwner(ic)
, None)
self.hasBombRef = ProtectedRef(None
, lambda _bomb: lambda ic:
self.hasTurn(ic) and self.allShipsPlaced(ic) and
not self.gameOver(ic)
, None)
示例11: test_prevent_flow_of_operations_on_untrusted_writes
def test_prevent_flow_of_operations_on_untrusted_writes(self):
x = ProtectedRef(0, None, self.allowUserWrite(self.aliceUser))
x.update(self.aliceUser, self.aliceUser, 42)
y = ProtectedRef(1, None, self.allowUserWrite(self.bobUser))
y.update(self.bobUser, self.bobUser, 43)
z = ProtectedRef(0, None, self.allowUserWrite(self.carolUser))
z.update(self.carolUser, self.carolUser, x.v + y.v)
self.assertEqual(JeevesLib.concretize(self.aliceUser, z.v), 1)
self.assertEqual(JeevesLib.concretize(self.bobUser, z.v), 1)
self.assertEqual(JeevesLib.concretize(self.carolUser, z.v), 1)
示例12: __init__
def __init__(self, owner):
self.owner = owner
self._placedRef = ProtectedRef(False
, lambda hasShip: lambda ic: (not hasShip) and self.isOwner(ic)
, None)
# TODO: See if we can do away with this...
self._placed = False
self.bombedRef = ProtectedRef(False
, lambda hasBomb: lambda ic: not hasBomb
, None)
# TODO: See if we can do away with this...
self.bombed = False
self._squares = []
示例13: test_combining_values_into_permissive_write
def test_combining_values_into_permissive_write(self):
x = ProtectedRef(0, None, self.allowUserWrite(self.bobUser))
x.update(self.bobUser, self.bobUser, 42)
y = ProtectedRef(1, None, self.allowUserWrite(self.aliceUser))
y.update(self.aliceUser, self.aliceUser, 43)
z = ProtectedRef(0, None
, lambda _this: lambda ictxt: lambda otxt:
ictxt == self.aliceUser or ictxt == self.bobUser
or ictxt == self.carolUser)
z.update(self.carolUser, self.carolUser, x.v + y.v)
self.assertEqual(JeevesLib.concretize(self.aliceUser, z.v), 85)
self.assertEqual(JeevesLib.concretize(self.bobUser, z.v), 85)
self.assertEqual(JeevesLib.concretize(self.carolUser, z.v), 85)
示例14: __init__
class Square:
@jeeves
def __init__(self, owner):
self.owner = owner
self.shipRef = ProtectedRef(NoShip()
# Policy for updating: must be owner and there can't be a ship there
# already.
, lambda ship: lambda ic: ship == NoShip()
, lambda ship: lambda ic: lambda _oc: self.isOwner(ic))
self.hasBombRef = ProtectedRef(None
, lambda _bomb: lambda ic: True
, lambda _bomb: lambda ic: lambda _oc:
self.hasTurn(ic) and self.allShipsPlaced(ic) and
(not self.gameOver(ic)))
def isOwner(self, ctxt):
return ctxt.user == self.owner
# TODO: Make sure function applications get applied correctly here.
# Do we need another @jeeves annotation?
def hasTurn(self, ctxt):
return ctxt.game.hasTurn(ctxt.user)
def allShipsPlaced(self, ctxt):
return ctxt.game.allShipsPlaced()
def gameOver(self, ctxt):
return ctxt.game.gameOver()
@jeeves
def mkShipSecret(self, ship):
a = JeevesLib.mkLabel("ship")
JeevesLib.restrict(a
, lambda ctxt:
self.hasBomb() or self.isOwner(ctxt) or self.gameOver(ctxt));
return JeevesLib.mkSensitive(a, ship, NoShip())
# Returns whether updating a square's ship reference succeeded.
def updateShip(self, ctxt, ship):
return self.shipRef.update(ctxt, ctxt, self.mkShipSecret(ship)) == UpdateResult.Success
def hasShip(self):
return not self.shipRef.v == NoShip()
def getShip(self):
return self.shipRef.v
def bomb(self, ctxt, bomb):
return self.hasBombRef.update(ctxt, ctxt, bomb) == UpdateResult.Success
def hasBomb(self):
return not (self.hasBombRef.v == None)
示例15: __init__
class Protein:
# TODO: Figure out what kinds of policies should go here...
def __init__(self, name, initValue=0):
self.name = name
self._vRef = ProtectedRef(initValue
# We also support policies where the write checks get concretized right
# away in the context of the user.
, None
# Flow is only permitted if there is an edge.
# The policy takes the current value (v), the input channel (ic), and
# the output channel.
, lambda v: lambda ic: lambda oc:
JeevesLib.jhasElt(self.edges, lambda edge: edge.v == oc))
self._edges = []
def addEdge(self, node, edgeType):
self._edges.append(Edge(node, edgeType))
def updateValue(self, ictxt, f):
self._vRef.update(ictxt, ictxt, f(self._vRef.v))