Python operator 模块,__xor__() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用operator.__xor__()

项目:easyparse    作者:jayvanderwall    | 项目源码 | 文件源码
def repeat(rule, from_count, to_count=None, allow_whitespace=False):
    """Allow between from_count and to_count repetitions of a rule.

    If to_count is not given, then allow as many repetitions as can be
    parsed.
    """

    if to_count == 0:
        return null

    if from_count == 0 and to_count is None:
        return many(rule, allow_whitespace=allow_whitespace)

    op = operator.__add__ if allow_whitespace else operator.__xor__
    next_to_count = to_count - 1 if to_count is not None else None
    next_from_count = from_count - 1 if from_count > 0 else 0

    first_part = optional(rule) if from_count == 0 else rule

    return op(first_part, repeat(rule, next_from_count, next_to_count,
                                 allow_whitespace))
项目:easyparse    作者:jayvanderwall    | 项目源码 | 文件源码
def __xor__(self, other_rule):
        return ConjunctionRule(self, other_rule, allow_whitespace=False)
项目:ntypes    作者:AlexAltea    | 项目源码 | 文件源码
def __xor__(self, rhs):
        return op_binary(self, rhs, operator.__xor__)
项目:ntypes    作者:AlexAltea    | 项目源码 | 文件源码
def __rxor__(self, lhs):
        return op_binary(lhs, self, operator.__xor__)
项目:ntypes    作者:AlexAltea    | 项目源码 | 文件源码
def __ixor__(self, v):
        return self.op_binary_inplace(v, operator.__xor__)
项目:cpy2py    作者:maxfischer2781    | 项目源码 | 文件源码
def __xor__(self, other):
        with self._lock:
            return operator.__xor__(self.__wrapped__, other)
项目:cpy2py    作者:maxfischer2781    | 项目源码 | 文件源码
def __rxor__(self, other):
        with self._lock:
            return operator.__xor__(other, self.__wrapped__)
项目:hyper-engine    作者:maxim5    | 项目源码 | 文件源码
def __xor__(self, other):  return _op2(self, other, operator.__xor__)
项目:hyper-engine    作者:maxim5    | 项目源码 | 文件源码
def __rxor__(self, other):  return _op2(self, other, operator.__xor__, rev=True)
项目:py-flags    作者:pasztorpisti    | 项目源码 | 文件源码
def test_xor(self):
        self._test_incompatible_types_fail(operator.__xor__)

        self.assertEqual(no_flags ^ no_flags, no_flags)
        self.assertEqual(no_flags ^ all_flags, all_flags)
        self.assertEqual(no_flags ^ f0, f0)
        self.assertEqual(no_flags ^ f1, f1)
        self.assertEqual(no_flags ^ f2, f2)
        self.assertEqual(no_flags ^ f01, f01)
        self.assertEqual(no_flags ^ f02, f02)
        self.assertEqual(no_flags ^ f12, f12)

        self.assertEqual(f0 ^ no_flags, f0)
        self.assertEqual(f0 ^ all_flags, f12)
        self.assertEqual(f0 ^ f0, no_flags)
        self.assertEqual(f0 ^ f1, f01)
        self.assertEqual(f0 ^ f2, f02)
        self.assertEqual(f0 ^ f01, f1)
        self.assertEqual(f0 ^ f02, f2)
        self.assertEqual(f0 ^ f12, all_flags)

        self.assertEqual(f01 ^ no_flags, f01)
        self.assertEqual(f01 ^ all_flags, f2)
        self.assertEqual(f01 ^ f0, f1)
        self.assertEqual(f01 ^ f1, f0)
        self.assertEqual(f01 ^ f2, all_flags)
        self.assertEqual(f01 ^ f01, no_flags)
        self.assertEqual(f01 ^ f02, f12)
        self.assertEqual(f01 ^ f12, f02)

        self.assertEqual(all_flags ^ no_flags, all_flags)
        self.assertEqual(all_flags ^ all_flags, no_flags)
        self.assertEqual(all_flags ^ f0, f12)
        self.assertEqual(all_flags ^ f1, f02)
        self.assertEqual(all_flags ^ f2, f01)
        self.assertEqual(all_flags ^ f01, f2)
        self.assertEqual(all_flags ^ f02, f1)
        self.assertEqual(all_flags ^ f12, f0)