Python operator.__xor__() Examples
The following are 11
code examples of operator.__xor__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
operator
, or try the search function
.
Example #1
Source File: BitVector.py From knob with MIT License | 6 votes |
def __xor__(self, other): ''' Take a bitwise 'XOR' of the bit vector on which the method is invoked with the argument bit vector. Return the result as a new bit vector. If the two bit vectors are not of the same size, pad the shorter one with zeros from the left. ''' if self.size < other.size: bv1 = self._resize_pad_from_left(other.size - self.size) bv2 = other elif self.size > other.size: bv1 = self bv2 = other._resize_pad_from_left(self.size - other.size) else: bv1 = self bv2 = other res = BitVector( size = bv1.size ) lpb = map(operator.__xor__, bv1.vector, bv2.vector) res.vector = array.array( 'H', lpb ) return res
Example #2
Source File: backend_vsa.py From claripy with BSD 2-Clause "Simplified" License | 6 votes |
def __init__(self): Backend.__init__(self) # self._make_raw_ops(set(expression_operations) - set(expression_set_operations), op_module=BackendVSA) self._make_expr_ops(set(expression_set_operations), op_class=self) self._make_raw_ops(set(backend_operations_vsa_compliant), op_module=BackendVSA) self._op_raw['StridedInterval'] = BackendVSA.CreateStridedInterval self._op_raw['ValueSet'] = ValueSet.__init__ self._op_raw['AbstractLocation'] = AbstractLocation.__init__ self._op_raw['Reverse'] = BackendVSA.Reverse self._op_raw['If'] = self.If self._op_expr['BVV'] = self.BVV self._op_expr['BoolV'] = self.BoolV self._op_expr['BVS'] = self.BVS # reduceable self._op_raw['__add__'] = self._op_add self._op_raw['__sub__'] = self._op_sub self._op_raw['__mul__'] = self._op_mul self._op_raw['__or__'] = self._op_or self._op_raw['__xor__'] = self._op_xor self._op_raw['__and__'] = self._op_and self._op_raw['__mod__'] = self._op_mod
Example #3
Source File: BitVector.py From ClusType with GNU General Public License v3.0 | 6 votes |
def __xor__(self, other): ''' Take a bitwise 'XOR' of the bit vector on which the method is invoked with the argument bit vector. Return the result as a new bit vector. If the two bit vectors are not of the same size, pad the shorter one with zeros from the left. ''' if self.size < other.size: bv1 = self._resize_pad_from_left(other.size - self.size) bv2 = other elif self.size > other.size: bv1 = self bv2 = other._resize_pad_from_left(self.size - other.size) else: bv1 = self bv2 = other res = BitVector( size = bv1.size ) lpb = map(operator.__xor__, bv1.vector, bv2.vector) res.vector = array.array( 'H', lpb ) return res
Example #4
Source File: backend_vsa.py From claripy with BSD 2-Clause "Simplified" License | 5 votes |
def _op_xor(*args): return reduce(operator.__xor__, args)
Example #5
Source File: backend_z3.py From claripy with BSD 2-Clause "Simplified" License | 5 votes |
def _op_xor(*args): return reduce(operator.__xor__, args)
Example #6
Source File: backend_concrete.py From claripy with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self): Backend.__init__(self) self._make_raw_ops(set(backend_operations) - { 'If' }, op_module=bv) self._make_raw_ops(backend_strings_operations, op_module=strings) self._make_raw_ops(backend_fp_operations, op_module=fp) self._op_raw['If'] = self._If self._op_raw['BVV'] = self.BVV self._op_raw['StringV'] = self.StringV self._op_raw['FPV'] = self.FPV # reduceable self._op_raw['__add__'] = self._op_add self._op_raw['__sub__'] = self._op_sub self._op_raw['__mul__'] = self._op_mul self._op_raw['__or__'] = self._op_or self._op_raw['__xor__'] = self._op_xor self._op_raw['__and__'] = self._op_and # unary self._op_raw['__invert__'] = self._op_not self._op_raw['__neg__'] = self._op_neg # boolean ops self._op_raw['And'] = self._op_and self._op_raw['Or'] = self._op_or self._op_raw['Xor'] = self._op_xor self._op_raw['Not'] = self._op_boolnot self._cache_objects = False
Example #7
Source File: bitwise_util.py From MARA_Framework with GNU Lesser General Public License v3.0 | 5 votes |
def propagateXor( x, y): return propagateBitwise(x, y, operator.__xor__, False, False)
Example #8
Source File: test_arithmetic.py From py-flags with MIT License | 5 votes |
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)
Example #9
Source File: nodes.py From hyper-engine with Apache License 2.0 | 5 votes |
def __xor__(self, other): return _op2(self, other, operator.__xor__)
Example #10
Source File: nodes.py From hyper-engine with Apache License 2.0 | 5 votes |
def __rxor__(self, other): return _op2(self, other, operator.__xor__, rev=True)
Example #11
Source File: backend_z3.py From claripy with BSD 2-Clause "Simplified" License | 4 votes |
def __init__(self, reuse_z3_solver=None, ast_cache_size=10000): Backend.__init__(self, solver_required=True) self._enable_simplification_cache = False self._hash_to_constraint = weakref.WeakValueDictionary() # Per-thread Z3 solver # This setting is treated as a global setting and is not supposed to be changed during runtime, unless you know # what you are doing. if reuse_z3_solver is None: reuse_z3_solver = True if os.environ.get('REUSE_Z3_SOLVER', "False").lower() in {"1", "true", "yes", "y"} \ else False self.reuse_z3_solver = reuse_z3_solver self._ast_cache_size = ast_cache_size # and the operations all_ops = backend_fp_operations | backend_operations if supports_fp else backend_operations all_ops |= backend_strings_operations - {'StrIsDigit'} for o in all_ops - {'BVV', 'BoolV', 'FPV', 'FPS', 'BitVec', 'StringV'}: self._op_raw[o] = getattr(self, '_op_raw_' + o) self._op_raw['Xor'] = self._op_raw_Xor self._op_raw['__ge__'] = self._op_raw_UGE self._op_raw['__gt__'] = self._op_raw_UGT self._op_raw['__le__'] = self._op_raw_ULE self._op_raw['__lt__'] = self._op_raw_ULT self._op_raw['Reverse'] = self._op_raw_Reverse self._op_raw['Identical'] = self._identical self._op_raw['fpToSBV'] = self._op_raw_fpToSBV self._op_raw['fpToUBV'] = self._op_raw_fpToUBV self._op_expr['BVS'] = self.BVS self._op_expr['BVV'] = self.BVV self._op_expr['FPV'] = self.FPV self._op_expr['FPS'] = self.FPS self._op_expr['BoolV'] = self.BoolV self._op_expr['BoolS'] = self.BoolS self._op_expr['StringV'] = self.StringV self._op_expr['StringS'] = self.StringS self._op_raw['__floordiv__'] = self._op_div self._op_raw['__mod__'] = self._op_mod # reduceable self._op_raw['__add__'] = self._op_add self._op_raw['__sub__'] = self._op_sub self._op_raw['__mul__'] = self._op_mul self._op_raw['__or__'] = self._op_or self._op_raw['__xor__'] = self._op_xor self._op_raw['__and__'] = self._op_and # XXX this is a HUGE HACK that should be removed whenever uninitialized gets moved to the # "proposed annotation backend" or wherever will prevent it from being part of the object # identity. also whenever the VSA attributes get the fuck out of BVS as well