本文整理汇总了Python中typhon.objects.equality.optSame函数的典型用法代码示例。如果您正苦于以下问题:Python optSame函数的具体用法?Python optSame怎么用?Python optSame使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了optSame函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRefEqualitySettled
def testRefEqualitySettled(self):
with scopedVat(testingVat()):
first, r = makePromise()
r.resolve(IntObject(42))
second, r = makePromise()
r.resolve(IntObject(42))
self.assertEqual(optSame(first, second), EQUAL)
示例2: testListEqualityRecursion
def testListEqualityRecursion(self):
# Yes, this is very hacky.
first = ConstList([IntObject(42)])
first.strategy.append(first, [first])
second = ConstList([IntObject(42)])
second.strategy.append(second, [second])
self.assertEqual(optSame(first, second), EQUAL)
示例3: eq
def eq(self, other):
if not isinstance(other, Proxy):
return False
if self.checkSlot() or other.checkSlot():
raise userError(u"equals comparison of resolved proxy is"
u" impossible")
return optSame(self.handler, other.handler) is EQUAL
示例4: testListEqualityRecursion
def testListEqualityRecursion(self):
first = wrapList([IntObject(42), NullObject])
# Hax.
first.objs.append(first)
second = wrapList([IntObject(42), NullObject])
# Hax.
second.objs.append(second)
self.assertEqual(optSame(first, second), EQUAL)
示例5: startOf
def startOf(self, needleList, start=0):
# This is quadratic. It could be better.
from typhon.objects.equality import EQUAL, optSame
for index in range(start, self.strategy.size(self)):
for needleIndex, needle in enumerate(needleList):
offset = index + needleIndex
if optSame(self.strategy.fetch(self, offset), needle) is not EQUAL:
break
return index
return -1
示例6: recv
def recv(self, atom, args):
from typhon.nodes import Noun, Method, Obj
from typhon.objects.equality import optSame, EQUAL
from typhon.objects.user import Audition
if atom is _UNCALL_0:
from typhon.objects.collections.maps import EMPTY_MAP
return ConstList([subrangeGuardMaker, StrObject(u"get"), ConstList([self.superGuard]), EMPTY_MAP])
if atom is AUDIT_1:
audition = args[0]
if not isinstance(audition, Audition):
raise userError(u"not invoked with an Audition")
ast = audition.ast
if not isinstance(ast, Obj):
raise userError(u"audition not created with an object expr")
methods = ast._script._methods
for m in methods:
if isinstance(m, Method) and m._verb == u"coerce":
mguard = m._g
if isinstance(mguard, Noun):
rGSG = audition.getGuard(mguard.name)
if isinstance(rGSG, FinalSlotGuard):
rGSG0 = rGSG.valueGuard
if isinstance(rGSG0, SameGuard):
resultGuard = rGSG0.value
if optSame(resultGuard, self.superGuard) is EQUAL or (
SUPERSETOF_1 in self.superGuard.respondingAtoms()
and self.superGuard.call(u"supersetOf", [resultGuard]) is wrapBool(True)
):
return wrapBool(True)
raise userError(
u"%s does not have a result guard implying "
u"%s, but %s" % (audition.fqn, self.superGuard.toQuote(), resultGuard.toQuote())
)
raise userError(
u"%s does not have a determinable "
u"result guard, but <& %s> :%s" % (audition.fqn, mguard.name, rGSG.toQuote())
)
break
return self
if atom is PASSES_1:
return wrapBool(args[0].auditedBy(self))
if atom is COERCE_2:
specimen, ej = args[0], args[1]
if specimen.auditedBy(self):
return specimen
c = specimen.call(u"_conformTo", [self])
if c.auditedBy(self):
return c
throw(ej, StrObject(u"%s does not conform to %s" % (specimen.toQuote(), self.toQuote())))
raise Refused(self, atom, args)
示例7: _startOf
def _startOf(self, needleCL, start):
if start < 0:
raise userError(u"startOf/2: Negative start %d not permitted" %
start)
# This is quadratic. It could be better.
from typhon.objects.equality import EQUAL, optSame
for index in range(start, len(self.objs)):
for needleIndex, needle in enumerate(needleCL):
offset = index + needleIndex
if optSame(self.objs[offset], needle) is not EQUAL:
break
return index
return -1
示例8: auditedBy
def auditedBy(self, prospect):
"""
Whether a prospective stamp has been left on this object.
"""
# The number of different objects that will pass through here is
# surprisingly low; consider how Python would look if metaclasses were
# promoted.
prospect = promote(prospect)
from typhon.objects.equality import optSame, EQUAL
# Already audited with an identical stamp?
for stamp in self.auditorStamps():
if optSame(prospect, stamp) is EQUAL:
return True
# Sorry, but nope.
return False
示例9: audit
def audit(self, audition):
from typhon.nodes import Noun, Method, Obj
from typhon.objects.equality import optSame, EQUAL
from typhon.objects.user import Audition
if not isinstance(audition, Audition):
raise userError(u"not invoked with an Audition")
ast = audition.ast
if not isinstance(ast, Obj):
raise userError(u"audition not created with an object expr")
methods = ast._script._methods
for m in methods:
if isinstance(m, Method) and m._verb == u"coerce":
mguard = m._g
if isinstance(mguard, Noun):
rGSG = audition.getGuard(mguard.name)
if isinstance(rGSG, FinalSlotGuard):
rGSG0 = rGSG.valueGuard
if isinstance(rGSG0, SameGuard):
resultGuard = rGSG0.value
if (optSame(resultGuard, self.superGuard)
is EQUAL or
(self.superGuard.call(u"supersetOf",
[resultGuard])
is wrapBool(True))):
return True
raise userError(
u"%s does not have a result guard implying "
u"%s, but %s" % (audition.fqn,
self.superGuard.toQuote(),
resultGuard.toQuote()))
raise userError(u"%s does not have a determinable "
u"result guard, but <& %s> :%s" % (
audition.fqn, mguard.name,
rGSG.toQuote()))
break
return False
示例10: indexOf
def indexOf(self, needle):
from typhon.objects.equality import EQUAL, optSame
for index, specimen in enumerate(self.objs):
if optSame(needle, specimen) is EQUAL:
return index
return -1
示例11: testListEqualityRecursionReflexive
def testListEqualityRecursionReflexive(self):
first = ConstList([IntObject(42)])
first.strategy.append(first, [first])
self.assertEqual(optSame(first, first), EQUAL)
示例12: contains
def contains(self, needle):
from typhon.objects.equality import EQUAL, optSame
for specimen in self.objs:
if optSame(needle, specimen) is EQUAL:
return True
return False
示例13: testListEquality
def testListEquality(self):
first = wrapList([IntObject(42)])
second = wrapList([IntObject(42)])
self.assertEqual(optSame(first, second), EQUAL)
示例14: testListEqualityRecursionReflexive
def testListEqualityRecursionReflexive(self):
first = wrapList([IntObject(42), NullObject])
# Hax.
first.objs.append(first)
self.assertEqual(optSame(first, first), EQUAL)
示例15: testStrInequality
def testStrInequality(self):
first = StrObject(u"false")
second = StrObject(u"true")
self.assertEqual(optSame(first, second), INEQUAL)