Python operator.lshift() Examples
The following are 30
code examples of operator.lshift().
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: test_sectypes.py From mpyc with MIT License | 6 votes |
def test_operatorerrors(self): secfld = sectypes.SecFld() secint = sectypes.SecInt() a = secfld(0) b = secint(1) self.assertRaises(TypeError, operator.add, a, b) self.assertRaises(TypeError, operator.add, a, 3.14) self.assertRaises(TypeError, operator.sub, a, b) self.assertRaises(TypeError, operator.mul, a, b) self.assertRaises(TypeError, operator.mul, 3.14, b) self.assertRaises(TypeError, operator.truediv, a, b) self.assertRaises(TypeError, operator.truediv, a, b) self.assertRaises(TypeError, operator.mod, a, b) self.assertRaises(TypeError, operator.mod, b, a) self.assertRaises(TypeError, operator.floordiv, a, b) self.assertRaises(TypeError, divmod, a, b) self.assertRaises(TypeError, divmod, b, a) self.assertRaises(TypeError, operator.pow, b, 3.14) self.assertRaises(TypeError, operator.lshift, b, 3.14) self.assertRaises(TypeError, operator.lshift, 3.14, b) self.assertRaises(TypeError, operator.rshift, b, 3.14) self.assertRaises(TypeError, operator.rshift, 3.14, b)
Example #2
Source File: SPI.py From Adafruit_Python_GPIO with MIT License | 6 votes |
def set_bit_order(self, order): """Set order of bits to be read/written over serial lines. Should be either MSBFIRST for most-significant first, or LSBFIRST for least-signifcant first. """ # Set self._mask to the bitmask which points at the appropriate bit to # read or write, and appropriate left/right shift operator function for # reading/writing. if order == MSBFIRST: self._mask = 0x80 self._write_shift = operator.lshift self._read_shift = operator.rshift elif order == LSBFIRST: self._mask = 0x01 self._write_shift = operator.rshift self._read_shift = operator.lshift else: raise ValueError('Order must be MSBFIRST or LSBFIRST.')
Example #3
Source File: test_finfields.py From mpyc with MIT License | 6 votes |
def test_operatorerrors(self): f2 = self.f2 f2p = self.f2p f256 = self.f256 f19 = self.f19 self.assertRaises(TypeError, operator.add, f2(1), f2p(2)) self.assertRaises(TypeError, operator.iadd, f2(1), f2p(2)) self.assertRaises(TypeError, operator.sub, f2(1), f256(2)) self.assertRaises(TypeError, operator.isub, f2(1), f256(2)) self.assertRaises(TypeError, operator.mul, f2(1), f19(2)) self.assertRaises(TypeError, operator.imul, f2(1), f19(2)) self.assertRaises(TypeError, operator.truediv, f256(1), f19(2)) self.assertRaises(TypeError, operator.itruediv, f256(1), f19(2)) self.assertRaises(TypeError, operator.truediv, 3.14, f19(2)) self.assertRaises(TypeError, operator.lshift, f2(1), f2(1)) self.assertRaises(TypeError, operator.ilshift, f2(1), f2(1)) self.assertRaises(TypeError, operator.lshift, 1, f2(1)) self.assertRaises(TypeError, operator.rshift, f19(1), f19(1)) self.assertRaises(TypeError, operator.irshift, f19(1), f19(1)) self.assertRaises(TypeError, operator.irshift, f256(1), f256(1)) self.assertRaises(TypeError, operator.pow, f2(1), f19(2)) self.assertRaises(TypeError, operator.pow, f19(1), 3.14)
Example #4
Source File: nodes.py From hyper-engine with Apache License 2.0 | 5 votes |
def __lshift__(self, other): return _op2(self, other, operator.lshift)
Example #5
Source File: test_operator.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_lshift(self): self.failUnlessRaises(TypeError, operator.lshift) self.failUnlessRaises(TypeError, operator.lshift, None, 42) self.failUnless(operator.lshift(5, 1) == 10) self.failUnless(operator.lshift(5, 0) == 5) self.assertRaises(ValueError, operator.lshift, 2, -1)
Example #6
Source File: TLorentzVector.py From uproot-methods with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __rlshift__(self, other): return self._scalar(operator.lshift, other, True)
Example #7
Source File: test_operator.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_lshift(self): self.failUnlessRaises(TypeError, operator.lshift) self.failUnlessRaises(TypeError, operator.lshift, None, 42) self.failUnless(operator.lshift(5, 1) == 10) self.failUnless(operator.lshift(5, 0) == 5) self.assertRaises(ValueError, operator.lshift, 2, -1)
Example #8
Source File: test_util.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def __rlshift__(self, y): return NonStandardInteger(operator.lshift(y, self.val))
Example #9
Source File: test_util.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def __lshift__(self, y): return NonStandardInteger(operator.lshift(self.val, y))
Example #10
Source File: nodes.py From hyper-engine with Apache License 2.0 | 5 votes |
def __rlshift__(self, other): return _op2(self, other, operator.lshift, rev=True)
Example #11
Source File: expr.py From owasp-pysec with Apache License 2.0 | 5 votes |
def __lshift__(self, other): return Expression((self, other), operator.lshift)
Example #12
Source File: TVector.py From uproot-methods with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __rlshift__(self, other): return self._scalar(operator.lshift, other, True)
Example #13
Source File: TVector.py From uproot-methods with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __lshift__(self, other): return self._scalar(operator.lshift, other)
Example #14
Source File: generate_test.py From protorpc with Apache License 2.0 | 5 votes |
def testNoneInvalid(self): self.assertRaises( TypeError, operator.lshift, self.indent_writer, None)
Example #15
Source File: vec2d.py From code-for-blog with The Unlicense | 5 votes |
def __lshift__(self, other): return self._o2(other, operator.lshift)
Example #16
Source File: vec2d.py From code-for-blog with The Unlicense | 5 votes |
def __rlshift__(self, other): return self._r_o2(other, operator.lshift)
Example #17
Source File: operators.py From sqlalchemy with MIT License | 5 votes |
def __lshift__(self, other): """implement the << operator. Not used by SQLAlchemy core, this is provided for custom operator systems which want to use << as an extension point. """ return self.operate(lshift, other)
Example #18
Source File: transform.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __lshift__(self, other): return type(self)(self, operator.lshift, other)
Example #19
Source File: constantfolding.py From ppci with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self): super().__init__() self.ops = { "+": enhance(operator.add), "-": enhance(operator.sub), "*": enhance(operator.mul), "%": enhance(operator.mod), "<<": enhance(operator.lshift), ">>": enhance(operator.rshift), }
Example #20
Source File: test_number.py From hpy with MIT License | 5 votes |
def test_binary(self): import operator for c_name, op in [ ('Add', operator.add), ('Subtract', operator.sub), ('Multiply', operator.mul), ('FloorDivide', operator.floordiv), ('TrueDivide', operator.truediv), ('Remainder', operator.mod), ('Divmod', divmod), ('Lshift', operator.lshift), ('Rshift', operator.rshift), ('And', operator.and_), ('Xor', operator.xor), ('Or', operator.or_), ]: mod = self.make_module(""" HPyDef_METH(f, "f", f_impl, HPyFunc_VARARGS) static HPy f_impl(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs) { HPy a, b; if (!HPyArg_Parse(ctx, args, nargs, "OO", &a, &b)) return HPy_NULL; return HPy_%s(ctx, a, b); } @EXPORT(f) @INIT """ % (c_name,), name='number_'+c_name) assert mod.f(5, 4) == op(5, 4) assert mod.f(6, 3) == op(6, 3)
Example #21
Source File: ops.py From hwt with MIT License | 5 votes |
def __lshift__(self, other): try: return self.naryOp(lshift, tv(self).__lshift__, other) except Exception as e: # simplification of previous exception traceback e_simplified = copy(e) raise e_simplified
Example #22
Source File: test_gfpx.py From mpyc with MIT License | 5 votes |
def _test_errors(self, poly): self.assertRaises(ValueError, poly.from_terms, 'x**2') self.assertRaises(TypeError, poly, 0.1) self.assertRaises(TypeError, poly, gfpx.GFpX(257)(0)) self.assertRaises(ValueError, poly, [poly.p]) self.assertRaises(TypeError, operator.add, poly(0), 0.1) self.assertRaises(TypeError, operator.iadd, poly(0), 0.1) self.assertRaises(TypeError, operator.sub, poly(0), 0.1) self.assertRaises(TypeError, operator.sub, 0.1, poly(0)) self.assertRaises(TypeError, operator.isub, poly(0), 0.1) self.assertRaises(TypeError, operator.mul, poly(0), 0.1) self.assertRaises(TypeError, operator.imul, poly(0), 0.1) self.assertRaises(TypeError, operator.lshift, poly(0), 0.1) self.assertRaises(TypeError, operator.lshift, 0.1, poly(0)) self.assertRaises(TypeError, operator.ilshift, poly(0), 0.1) self.assertRaises(TypeError, operator.rshift, poly(0), 0.1) self.assertRaises(TypeError, operator.rshift, 0.1, poly(0)) self.assertRaises(TypeError, operator.irshift, poly(0), 0.1) self.assertRaises(TypeError, operator.floordiv, poly(0), 0.1) self.assertRaises(TypeError, operator.floordiv, 0.1, poly(0)) self.assertRaises(TypeError, operator.ifloordiv, poly(0), 0.1) self.assertRaises(TypeError, operator.mod, poly(0), 0.1) self.assertRaises(TypeError, operator.mod, 0.1, poly(0)) self.assertRaises(TypeError, operator.imod, poly(0), 0.1) self.assertRaises(TypeError, divmod, poly(0), 0.1) self.assertRaises(TypeError, divmod, 0.1, poly(0)) self.assertRaises(TypeError, operator.lt, poly(0), 0.1) self.assertRaises(TypeError, operator.lt, 0.1, poly(0)) # NB: tests > self.assertRaises(TypeError, operator.le, poly(0), 0.1) self.assertRaises(TypeError, operator.le, 0.1, poly(0)) # NB: tests < self.assertRaises(ZeroDivisionError, poly.invert, poly(283), poly(0)) self.assertRaises(ZeroDivisionError, poly.invert, poly(283), poly(283)) self.assertRaises(ZeroDivisionError, poly.mod, poly(283), poly(0)) self.assertRaises(ZeroDivisionError, poly.divmod, poly(283), poly(0)) self.assertRaises(ValueError, operator.pow, poly(3), -16)
Example #23
Source File: test_operator.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_lshift(self): self.assertRaises(TypeError, operator.lshift) self.assertRaises(TypeError, operator.lshift, None, 42) self.assertTrue(operator.lshift(5, 1) == 10) self.assertTrue(operator.lshift(5, 0) == 5) self.assertRaises(ValueError, operator.lshift, 2, -1)
Example #24
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __lshift__(self, y): return NonStandardInteger(operator.lshift(self.val, y))
Example #25
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __rlshift__(self, y): return NonStandardInteger(operator.lshift(y, self.val))
Example #26
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __lshift__(self, y): return NonStandardInteger(operator.lshift(self.val, y))
Example #27
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __rlshift__(self, y): return NonStandardInteger(operator.lshift(y, self.val))
Example #28
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __lshift__(self, y): return NonStandardInteger(operator.lshift(self.val, y))
Example #29
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __lshift__(self, y): return NonStandardInteger(operator.lshift(self.val, y))
Example #30
Source File: test_util.py From luci-py with Apache License 2.0 | 5 votes |
def __rlshift__(self, y): return NonStandardInteger(operator.lshift(y, self.val))