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

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

项目:download-manager    作者:thispc    | 项目源码 | 文件源码
def __init__(self, code, objects=None):
        self._OPERATORS = [
            ('|', operator.or_),
            ('^', operator.xor),
            ('&', operator.and_),
            ('>>', operator.rshift),
            ('<<', operator.lshift),
            ('-', operator.sub),
            ('+', operator.add),
            ('%', operator.mod),
            ('/', operator.truediv),
            ('*', operator.mul),
        ]
        self._ASSIGN_OPERATORS = [(op + '=', opfunc)
                                  for op, opfunc in self._OPERATORS]
        self._ASSIGN_OPERATORS.append(('=', lambda cur, right: right))
        self._VARNAME_PATTERN = r'[a-zA-Z_$][a-zA-Z_$0-9]*'

        if objects is None:
            objects = {}
        self.code = code
        self._functions = {}
        self._objects = objects
项目:pudzu    作者:Udzu    | 项目源码 | 文件源码
def number_of_args(fn):
    """Return the number of positional arguments for a function, or None if the number is variable.
    Looks inside any decorated functions."""
    try:
        if hasattr(fn, '__wrapped__'):
            return number_of_args(fn.__wrapped__)
        if any(p.kind == p.VAR_POSITIONAL for p in signature(fn).parameters.values()):
            return None
        else:
            return sum(p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD) for p in signature(fn).parameters.values())
    except ValueError:
        # signatures don't work for built-in operators, so check for a few explicitly
        UNARY_OPS = [len, op.not_, op.truth, op.abs, op.index, op.inv, op.invert, op.neg, op.pos]
        BINARY_OPS = [op.lt, op.le, op.gt, op.ge, op.eq, op.ne, op.is_, op.is_not, op.add, op.and_, op.floordiv, op.lshift, op.mod, op.mul, op.or_, op.pow, op.rshift, op.sub, op.truediv, op.xor, op.concat, op.contains, op.countOf, op.delitem, op.getitem, op.indexOf]
        TERNARY_OPS = [op.setitem]
        if fn in UNARY_OPS:
            return 1
        elif fn in BINARY_OPS:
            return 2
        elif fn in TERNARY_OPS:
            return 3
        else:
            raise NotImplementedError("Bult-in operator {} not supported".format(fn))
项目:pyload-plugins    作者:pyload    | 项目源码 | 文件源码
def __init__(self, code, objects=None):
        self._OPERATORS = [
            ('|', operator.or_),
            ('^', operator.xor),
            ('&', operator.and_),
            ('>>', operator.rshift),
            ('<<', operator.lshift),
            ('-', operator.sub),
            ('+', operator.add),
            ('%', operator.mod),
            ('/', operator.truediv),
            ('*', operator.mul),
        ]
        self._ASSIGN_OPERATORS = [(op + '=', opfunc)
                                  for op, opfunc in self._OPERATORS]
        self._ASSIGN_OPERATORS.append(('=', lambda cur, right: right))
        self._VARNAME_PATTERN = r'[a-zA-Z_$][a-zA-Z_$0-9]*'

        if objects is None:
            objects = {}
        self.code = code
        self._functions = {}
        self._objects = objects
项目:darkwater_python_escape    作者:darkwaterio    | 项目源码 | 文件源码
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.')
项目:myhdlpeek    作者:xesscorp    | 项目源码 | 文件源码
def __rshift__(self, trc):
        return self.apply_op2(trc, operator.rshift)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_rshift_scalar(self):
        self.check_array_scalar_op(operator.rshift)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_rrshift_scalar(self):
        self.check_array_scalar_op(operator.rshift, swap=True)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_rshift_scalarzero(self):
        self.check_array_scalarzero_op(operator.rshift)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_rrshift_scalarzero(self):
        self.check_array_scalarzero_op(operator.rshift, swap=True)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_rshift_array(self):
        self.check_array_array_op(operator.rshift)
项目:cupy    作者:cupy    | 项目源码 | 文件源码
def test_doubly_broadcasted_rshift(self):
        self.check_array_doubly_broadcasted_op(operator.rshift)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def rshift(x, n):
    """For an integer x, calculate x >> n with the fastest (floor)
    rounding. Unlike the plain Python expression (x >> n), n is
    allowed to be negative, in which case a left shift is performed."""
    if n >= 0: return x >> n
    else:      return x << (-n)
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_rshift(self):
        self.assertRaises(TypeError, operator.rshift)
        self.assertRaises(TypeError, operator.rshift, None, 42)
        self.assertTrue(operator.rshift(5, 1) == 2)
        self.assertTrue(operator.rshift(5, 0) == 5)
        self.assertRaises(ValueError, operator.rshift, 2, -1)
项目:twic_close_reading    作者:jarmoza    | 项目源码 | 文件源码
def rshift(x, n):
    """For an integer x, calculate x >> n with the fastest (floor)
    rounding. Unlike the plain Python expression (x >> n), n is
    allowed to be negative, in which case a left shift is performed."""
    if n >= 0: return x >> n
    else:      return x << (-n)
项目:Vector-Tiles-Reader-QGIS-Plugin    作者:geometalab    | 项目源码 | 文件源码
def __rshift__(self, y):
    return NonStandardInteger(operator.rshift(self.val, y))
项目:Vector-Tiles-Reader-QGIS-Plugin    作者:geometalab    | 项目源码 | 文件源码
def __rrshift__(self, y):
    return NonStandardInteger(operator.rshift(y, self.val))
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def rshift(x, n):
    """For an integer x, calculate x >> n with the fastest (floor)
    rounding. Unlike the plain Python expression (x >> n), n is
    allowed to be negative, in which case a left shift is performed."""
    if n >= 0: return x >> n
    else:      return x << (-n)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
def test_rshift(self):
        self.assertRaises(TypeError, operator.rshift)
        self.assertRaises(TypeError, operator.rshift, None, 42)
        self.assertTrue(operator.rshift(5, 1) == 2)
        self.assertTrue(operator.rshift(5, 0) == 5)
        self.assertRaises(ValueError, operator.rshift, 2, -1)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
def test_rshift(self):
        self.assertRaises(TypeError, operator.rshift)
        self.assertRaises(TypeError, operator.rshift, None, 42)
        self.assertTrue(operator.rshift(5, 1) == 2)
        self.assertTrue(operator.rshift(5, 0) == 5)
        self.assertRaises(ValueError, operator.rshift, 2, -1)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_rshift_scalar(self):
        self.check_array_scalar_op(operator.rshift)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_rrshift_scalar(self):
        self.check_array_scalar_op(operator.rshift, swap=True)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_rshift_scalarzero(self):
        self.check_array_scalarzero_op(operator.rshift)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_rrshift_scalarzero(self):
        self.check_array_scalarzero_op(operator.rshift, swap=True)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_rshift_array(self):
        self.check_array_array_op(operator.rshift)
项目:chainer-deconv    作者:germanRos    | 项目源码 | 文件源码
def test_doubly_broadcasted_rshift(self):
        self.check_array_doubly_broadcasted_op(operator.rshift)
项目:coremltools    作者:apple    | 项目源码 | 文件源码
def __rshift__(self, y):
    return NonStandardInteger(operator.rshift(self.val, y))
项目:coremltools    作者:apple    | 项目源码 | 文件源码
def __rrshift__(self, y):
    return NonStandardInteger(operator.rshift(y, self.val))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_rshift(self):
        self.assertRaises(TypeError, operator.rshift)
        self.assertRaises(TypeError, operator.rshift, None, 42)
        self.assertTrue(operator.rshift(5, 1) == 2)
        self.assertTrue(operator.rshift(5, 0) == 5)
        self.assertRaises(ValueError, operator.rshift, 2, -1)
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def __rshift__(self, other):
        return self._o2(other, operator.rshift)
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def __rrshift__(self, other):
        return self._r_o2(other, operator.rshift)
项目:hyper-engine    作者:maxim5    | 项目源码 | 文件源码
def __rshift__(self, other):  return _op2(self, other, operator.rshift)
项目:hyper-engine    作者:maxim5    | 项目源码 | 文件源码
def __rrshift__(self, other): return _op2(self, other, operator.rshift, rev=True)
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
def test_rshift(self):
        self.assertRaises(TypeError, operator.rshift)
        self.assertRaises(TypeError, operator.rshift, None, 42)
        self.assertTrue(operator.rshift(5, 1) == 2)
        self.assertTrue(operator.rshift(5, 0) == 5)
        self.assertRaises(ValueError, operator.rshift, 2, -1)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
def test_rshift(self):
        self.assertRaises(TypeError, operator.rshift)
        self.assertRaises(TypeError, operator.rshift, None, 42)
        self.assertTrue(operator.rshift(5, 1) == 2)
        self.assertTrue(operator.rshift(5, 0) == 5)
        self.assertRaises(ValueError, operator.rshift, 2, -1)
项目:bytecode    作者:vstinner    | 项目源码 | 文件源码
def eval_BINARY_RSHIFT(self, instr):
        return self.binop(operator.rshift, instr)
项目:Python-iBeacon-Scan    作者:NikNitro    | 项目源码 | 文件源码
def rshift(x, n):
    """For an integer x, calculate x >> n with the fastest (floor)
    rounding. Unlike the plain Python expression (x >> n), n is
    allowed to be negative, in which case a left shift is performed."""
    if n >= 0: return x >> n
    else:      return x << (-n)
项目:POTCO-PS    作者:ksmit799    | 项目源码 | 文件源码
def binaryRepr(number, max_length = 32):
    # This will only work reliably for relatively small numbers.
    # Increase the value of max_length if you think you're going
    # to use long integers
    assert number < 2L << max_length
    shifts = map (operator.rshift, max_length * [number], \
                  range (max_length - 1, -1, -1))
    digits = map (operator.mod, shifts, max_length * [2])
    if not digits.count (1): return 0
    digits = digits [digits.index (1):]
    return ''.join([repr(digit) for digit in digits])
项目:go2mapillary    作者:enricofer    | 项目源码 | 文件源码
def __rshift__(self, y):
    return NonStandardInteger(operator.rshift(self.val, y))
项目:go2mapillary    作者:enricofer    | 项目源码 | 文件源码
def __rrshift__(self, y):
    return NonStandardInteger(operator.rshift(y, self.val))
项目:Simulating-a-Self-Driving-Car    作者:Aniruddha-Tapas    | 项目源码 | 文件源码
def __rshift__(self, other):
        return self._o2(other, operator.rshift)
项目:Simulating-a-Self-Driving-Car    作者:Aniruddha-Tapas    | 项目源码 | 文件源码
def __rrshift__(self, other):
        return self._r_o2(other, operator.rshift)
项目:OpenRAM    作者:mguthaus    | 项目源码 | 文件源码
def rshift(x, n):
    """For an integer x, calculate x >> n with the fastest (floor)
    rounding. Unlike the plain Python expression (x >> n), n is
    allowed to be negative, in which case a left shift is performed."""
    if n >= 0: return x >> n
    else:      return x << (-n)
项目:gazelle    作者:surrsurus    | 项目源码 | 文件源码
def make_env():
  ''' An environment with basic procedures. '''

  import math
  import cmath
  import itertools
  import operator as op

  env = Environment()

  env.update(vars(math))
  env.update(vars(cmath))
  env.update(vars(itertools))

  env.update({
    '>':          op.gt,     '<':       op.lt,    
    '>=':         op.ge,     '<=':      op.le,
    '=':          op.eq,
    '>>':         op.rshift, '<<':      op.lshift,
    '+':          lambda *x: reduce(op.add, x, 0),
    '-':          lambda *x: x[0] - sum(x[1:]),
    '*':          lambda *x: reduce(op.mul, x, 1),
    '/':          lambda *x: reduce(op.truediv, (x[1:]), x[0]),
    '//':         lambda *x: reduce(op.floordiv, (x[1:]), x[0]),
    '%':          op.mod,
    'abs':        abs,
    'append':     op.add,
    'apply':      lambda proc,l: proc(*l),
    'begin':      lambda *x: x[-1],
    'bool?':      lambda x: isinstance(x, bool),
    'call/cc':    callcc,
    'car':        lambda x: x[0],
    'cdr':        lambda x: x[1:],
    'cons':       lambda x,y: [x] + y,
    'filter':     lambda f,l: list(filter(f, l)),
    'length':     len, 
    'list':       lambda *x: list(x),
    'list?':      lambda x: isinstance(x,list), 
    # Map can be defined in the stdlib, though it will max out python's recursion depth
    'map':        lambda f,l: list(map(f, l)),
    'max':        max,
    'min':        min,
    'not':        op.not_,
    'number?':    lambda x: not isinstance(x, bool) and isinstance(x, int) or isinstance(x, float) or isinstance(x, complex),   
    'or':         op.or_,
    'proc?':      callable,
    'range':      lambda *x: list(range(x[0], x[1])) if len(x) > 1 else list(range(x[0])),
    'round':      round,
    'str?':       lambda x: isinstance(x, str),
    'sum':        lambda x: sum(x),
    })
  return env

# Create a global env for `gazeval()` to access