python类__xor__()的实例源码

easyparse.py 文件源码 项目:easyparse 作者: jayvanderwall 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:easyparse 作者: jayvanderwall 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __xor__(self, other_rule):
        return ConjunctionRule(self, other_rule, allow_whitespace=False)
native_int.py 文件源码 项目:ntypes 作者: AlexAltea 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __xor__(self, rhs):
        return op_binary(self, rhs, operator.__xor__)
native_int.py 文件源码 项目:ntypes 作者: AlexAltea 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __rxor__(self, lhs):
        return op_binary(lhs, self, operator.__xor__)
native_int.py 文件源码 项目:ntypes 作者: AlexAltea 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __ixor__(self, v):
        return self.op_binary_inplace(v, operator.__xor__)
thread_tools.py 文件源码 项目:cpy2py 作者: maxfischer2781 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __xor__(self, other):
        with self._lock:
            return operator.__xor__(self.__wrapped__, other)
thread_tools.py 文件源码 项目:cpy2py 作者: maxfischer2781 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def __rxor__(self, other):
        with self._lock:
            return operator.__xor__(other, self.__wrapped__)
nodes.py 文件源码 项目:hyper-engine 作者: maxim5 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __xor__(self, other):  return _op2(self, other, operator.__xor__)
nodes.py 文件源码 项目:hyper-engine 作者: maxim5 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __rxor__(self, other):  return _op2(self, other, operator.__xor__, rev=True)
test_arithmetic.py 文件源码 项目:py-flags 作者: pasztorpisti 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号