def like(a, b):
return operator.contains(a.lower(), b.lower())
python类contains()的实例源码
def test_operator(self):
import operator
self.assertIs(operator.truth(0), False)
self.assertIs(operator.truth(1), True)
self.assertIs(operator.not_(1), False)
self.assertIs(operator.not_(0), True)
self.assertIs(operator.contains([], 1), False)
self.assertIs(operator.contains([1], 1), True)
self.assertIs(operator.lt(0, 0), False)
self.assertIs(operator.lt(0, 1), True)
self.assertIs(operator.is_(True, True), True)
self.assertIs(operator.is_(True, False), False)
self.assertIs(operator.is_not(True, True), False)
self.assertIs(operator.is_not(True, False), True)
json_filter.py 文件源码
项目:Trusted-Platform-Module-nova
作者: BU-NU-CLOUD-SP16
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def _op_compare(self, args, op):
"""Returns True if the specified operator can successfully
compare the first item in the args with all the rest. Will
return False if only one item is in the list.
"""
if len(args) < 2:
return False
if op is operator.contains:
bad = args[0] not in args[1:]
else:
bad = [arg for arg in args[1:]
if not op(args[0], arg)]
return not bool(bad)
json_filter.py 文件源码
项目:Trusted-Platform-Module-nova
作者: BU-NU-CLOUD-SP16
项目源码
文件源码
阅读 25
收藏 0
点赞 0
评论 0
def _in(self, args):
"""First term is in set of remaining terms."""
return self._op_compare(args, operator.contains)
def in_(x, y):
return operator.contains(y, x)
def not_in(x, y):
return not operator.contains(y, x)
def chained_contains(chained, id, contains=op.contains):
stores_with_read = [s for s in chained.stores if s._read]
if len(stores_with_read) == 0:
raise PermissionError('contains', chained, 'read')
for store in stores_with_read:
if store._read and contains(store, id):
return True
return False