當前位置: 首頁>>代碼示例>>Python>>正文


Python ProtectedRef.ProtectedRef類代碼示例

本文整理匯總了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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:7,代碼來源:testJeevesWrite.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:7,代碼來源:testJeevesWrite.py

示例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)
開發者ID:labdalla,項目名稱:jeeves,代碼行數:8,代碼來源:testJeevesWrite.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:8,代碼來源:testJeevesWrite.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:8,代碼來源:testJeevesWrite.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:9,代碼來源:testJeevesWrite.py

示例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)	 
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:9,代碼來源:testJeevesWrite.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:9,代碼來源:testFunctions.py

示例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")
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:12,代碼來源:testSanitization.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:12,代碼來源:Square.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:10,代碼來源:testJeevesWrite.py

示例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 = []
開發者ID:labdalla,項目名稱:jeeves,代碼行數:15,代碼來源:GamePiece.py

示例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)
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:13,代碼來源:testJeevesWrite.py

示例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)
開發者ID:labdalla,項目名稱:jeeves,代碼行數:46,代碼來源:Square.py

示例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))
開發者ID:Ch0c0late,項目名稱:jeeves,代碼行數:18,代碼來源:Chemotaxis.py


注:本文中的fast.ProtectedRef.ProtectedRef類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。