Python operator.not_() Examples

The following are 30 code examples of operator.not_(). 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_bool.py    From ironpython2 with Apache License 2.0 7 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #2
Source File: test_bool.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #3
Source File: webenginesettings.py    From qutebrowser with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, settings):
        super().__init__(settings)
        # Attributes which don't exist in all Qt versions.
        new_attributes = {
            # Qt 5.8
            'content.print_element_backgrounds':
                ('PrintElementBackgrounds', None),

            # Qt 5.11
            'content.autoplay':
                ('PlaybackRequiresUserGesture', operator.not_),

            # Qt 5.12
            'content.dns_prefetch':
                ('DnsPrefetchEnabled', None),
        }
        for name, (attribute, converter) in new_attributes.items():
            try:
                value = getattr(QWebEngineSettings, attribute)
            except AttributeError:
                continue

            self._ATTRIBUTES[name] = Attr(value, converter=converter) 
Example #4
Source File: cparser.py    From pyglet with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def p_unary_operator(p):
    '''unary_operator : '&'
                      | '*'
                      | '+'
                      | '-'
                      | '~'
                      | '!'
    '''
    # reduces to (op, op_str)
    p[0] = ({
        '+': operator.pos,
        '-': operator.neg,
        '~': operator.inv,
        '!': operator.not_,
        '&': 'AddressOfUnaryOperator',
        '*': 'DereferenceUnaryOperator'}[p[1]], p[1]) 
Example #5
Source File: parser.py    From algorithm with Do What The F*ck You Want To Public License 6 votes vote down vote up
def __init__(self,tokens=None,syms=None,codes=None,level=0):
        '''init pc, closure, reserved keywords, operators'''
        super().__init__()
        self.reserved={'FUNC','PRINT','RETURN','BEGIN','END','IF','THEN','FOR','ELIF','ELSE','WHILE','DO','BREAK','CONTINUE','VAR','CONST','ODD','RANDOM','SWITCH','CASE','DEFAULT'}
        self.bodyFirst= self.reserved.copy()
        self.bodyFirst.remove('ODD')
        self.relationOPR= {'EQ':eq,'NEQ':ne,'GT':gt,'LT':lt,'GE':ge,'LE':le} # odd
        self.conditionOPR = {'AND':and_,'OR':or_, 'NOT':not_}
        self.conditionOPR.update(self.relationOPR)
        self.arithmeticOPR = {'ADD':add,'SUB':sub,'MOD':mod,'MUL':mul,'POW':pow,'DIV':lambda x,y:x/y,'INTDIV':lambda x,y:round(x)//round(y) }
        self.bitOPR = {'LSHIFT':lambda x,y:round(x)<<round(y),'RSHIFT':lambda x,y:round(x)>>round(y),'BITAND':lambda x,y:round(x)&round(y), 'BITOR':lambda x,y:round(x)|round(y),'BITNOT':lambda x:~round(x)}
        self.binaryOPR = dict()
        self.binaryOPR.update(self.conditionOPR)
        del self.binaryOPR['NOT']
        self.binaryOPR.update(self.arithmeticOPR)
        self.binaryOPR.update(self.bitOPR)
        del self.binaryOPR['BITNOT']
        self.unaryOPR = {'NEG':neg,'NOT':not_,'BITNOT':lambda x:~round(x),'FAC':lambda x:reduce(mul,range(1,round(x)+1),1),'ODD':lambda x:round(x)%2==1, 'RND':lambda x:randint(0,x),'INT':round}#abs 
Example #6
Source File: test_bool.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #7
Source File: __init__.py    From aireamhan with MIT License 6 votes vote down vote up
def add_globals(self):
    "Add some Scheme standard procedures."
    import math, cmath, operator as op
    from functools import reduce
    self.update(vars(math))
    self.update(vars(cmath))
    self.update({
     '+':op.add, '-':op.sub, '*':op.mul, '/':op.itruediv, 'níl':op.not_, 'agus':op.and_,
     '>':op.gt, '<':op.lt, '>=':op.ge, '<=':op.le, '=':op.eq, 'mod':op.mod, 
     'frmh':cmath.sqrt, 'dearbhluach':abs, 'uas':max, 'íos':min,
     'cothrom_le?':op.eq, 'ionann?':op.is_, 'fad':len, 'cons':cons,
     'ceann':lambda x:x[0], 'tóin':lambda x:x[1:], 'iarcheangail':op.add,  
     'liosta':lambda *x:list(x), 'liosta?': lambda x:isa(x,list),
     'folamh?':lambda x: x == [], 'adamh?':lambda x: not((isa(x, list)) or (x == None)),
     'boole?':lambda x: isa(x, bool), 'scag':lambda f, x: list(filter(f, x)),
     'cuir_le':lambda proc,l: proc(*l), 'mapáil':lambda p, x: list(map(p, x)), 
     'lódáil':lambda fn: load(fn), 'léigh':lambda f: f.read(),
     'oscail_comhad_ionchuir':open,'dún_comhad_ionchuir':lambda p: p.file.close(), 
     'oscail_comhad_aschur':lambda f:open(f,'w'), 'dún_comhad_aschur':lambda p: p.close(),
     'dac?':lambda x:x is eof_object, 'luacháil':lambda x: evaluate(x),
     'scríobh':lambda x,port=sys.stdout:port.write(to_string(x) + '\n')})
    return self 
Example #8
Source File: test_richcmp.py    From android_universal with MIT License 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __bool__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __bool__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #9
Source File: misc.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def first_false_index(iterable, pred=None, default=None):
    """find the first index position for the which the callable pred returns False"""
    if pred is None:
        func = operator.not_
    else:
        func = lambda x: not pred(x)
    return first_true_index(iterable, func, default) 
Example #10
Source File: __init__.py    From git-pull-request with Apache License 2.0 5 votes vote down vote up
def parse_pr_message(message):
    message = textparse.remove_ignore_marker(message)
    message_by_line = message.split("\n")
    if len(message) == 0:
        return None, None
    title = message_by_line[0]
    body = "\n".join(itertools.dropwhile(operator.not_, message_by_line[1:]))
    return title, body 
Example #11
Source File: testSourceTransform.py    From jeeves with MIT License 5 votes vote down vote up
def test_jbool_functions_fexprs(self):
		jl = JeevesLib

		x = jl.mkLabel('x')
		jl.restrict(x, lambda (a,_) : a == 42)

		for lh in (True, False):
			for ll in (True, False):
				for rh in (True, False):
					for rl in (True, False):
						l = jl.mkSensitive(x, lh, ll)
						r = jl.mkSensitive(x, rh, rl)
						self.assertEquals(jl.concretize((42,0), l and r), operator.and_(lh, rh))
						self.assertEquals(jl.concretize((10,0), l and r), operator.and_(ll, rl))
						self.assertEquals(jl.concretize((42,0), l or r), operator.or_(lh, rh))
						self.assertEquals(jl.concretize((10,0), l or r), operator.or_(ll, rl))
						self.assertEquals(jl.concretize((42,0), not l), operator.not_(lh))
						self.assertEquals(jl.concretize((10,0), not l), operator.not_(ll))

		y = jl.mkLabel('y')
		jl.restrict(y, lambda (_,b) : b == 42)

		for lh in (True, False):
			for ll in (True, False):
				for rh in (True, False):
					for rl in (True, False):
						l = jl.mkSensitive(x, lh, ll)
						r = jl.mkSensitive(y, rh, rl)
						self.assertEquals(jl.concretize((42,0), l and r), operator.and_(lh, rl))
						self.assertEquals(jl.concretize((10,0), l and r), operator.and_(ll, rl))
						self.assertEquals(jl.concretize((42,42), l and r), operator.and_(lh, rh))
						self.assertEquals(jl.concretize((10,42), l and r), operator.and_(ll, rh))

						self.assertEquals(jl.concretize((42,0), l or r), operator.or_(lh, rl))
						self.assertEquals(jl.concretize((10,0), l or r), operator.or_(ll, rl))
						self.assertEquals(jl.concretize((42,42), l or r), operator.or_(lh, rh))
						self.assertEquals(jl.concretize((10,42), l or r), operator.or_(ll, rh)) 
Example #12
Source File: parser.py    From incubator-tvm with Apache License 2.0 5 votes vote down vote up
def visit_BoolOp(self, node):
        n = len(node.values)
        if n == 1:
            _internal_assert(isinstance(node.op, ast.Not), \
                             "Unary is supposed to be not!")
            return operator.not_(self.visit(node.values[0]))
        _internal_assert(isinstance(node.op, (ast.And, ast.Or)), \
                         "Binary is supposed to be and/or!")
        values = [self.visit(i) for i in node.values]
        return HybridParser._binop_maker[type(node.op)](*values) 
Example #13
Source File: test_richcmp.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __nonzero__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __nonzero__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #14
Source File: expressionparser.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def _parse_not(self, tokens):
		# Handle "not ..."
		if not tokens:
			raise ExpressionSyntaxError('Unexpected end of expression')
		if tokens[0] == 'not':
			tokens.pop(0)
			rexpr = self._parse_comparison(tokens)
			return ExpressionUnaryOperator(operator.not_, rexpr)
		else:
			return self._parse_comparison(tokens) 
Example #15
Source File: test_bool.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        self.assertIs(operator.isCallable(0), False)
        self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #16
Source File: test_richcmp.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __nonzero__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __nonzero__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #17
Source File: test_bool.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #18
Source File: test_richcmp.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __bool__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __bool__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #19
Source File: transform.py    From holoviews with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __not__(self): return type(self)(self, operator.not_) 
Example #20
Source File: expr.py    From owasp-pysec with Apache License 2.0 5 votes vote down vote up
def __not__(self, other):
        return Expression((self, other), operator.not_) 
Example #21
Source File: test_richcmp.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __nonzero__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __nonzero__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #22
Source File: preprocessor.py    From pyglet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def p_unary_operator(self, p):
        '''unary_operator : '+'
                          | '-'
                          | '~'
                          | '!'
        '''
        # reduces to (op, op_str)
        p[0] = ({
            '+': operator.pos,
            '-': operator.neg,
            '~': operator.inv,
            '!': operator.not_}[p[1]], p[1]) 
Example #23
Source File: test_bool.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        with test_support.check_py3k_warnings():
            self.assertIs(operator.isCallable(0), False)
            self.assertIs(operator.isCallable(len), True)
        self.assertIs(operator.isNumberType(None), False)
        self.assertIs(operator.isNumberType(0), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.isSequenceType(0), False)
        self.assertIs(operator.isSequenceType([]), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.isMappingType(1), False)
        self.assertIs(operator.isMappingType({}), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #24
Source File: eval.py    From lispy with MIT License 5 votes vote down vote up
def standard_env():
    env = Env()
    env.update(vars(math))
    env.update({
        '+':op.add, 
        '-':op.sub, 
        '*':op.mul, 
        '/':op.div, 
        '>':op.gt,
        '<':op.lt,
        '>=':op.ge,
        '<=':op.le,
        '=':op.eq,
        'abs': abs,
        'append': op.add,
        'apply': apply,
        'begin': lambda *x: x[-1],
        'car': lambda x: x[0],
        'cdr': lambda x: x[1:],
        'cons': lambda x,y: [x] + y,
        'eq?':     op.is_, 
        'equal?':  op.eq, 
        'length':  len, 
        'list':    lambda *x: list(x),
        'list?':   lambda x: isinstance(x,list), 
        'map':     map,
        'max':     max,
        'filter':   filter,
        'foldr':    foldr,
        'foldl':    foldl,
        'min':     min,
        'not':     op.not_,
        'null?':   lambda x: x == [], 
        'number?': lambda x: isinstance(x, Number),   
        'procedure?': callable,
        'round':   round,
        'symbol?': lambda x: isinstance(x, Symbol),
        })
    return env 
Example #25
Source File: test_bool.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #26
Source File: test_richcmp.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __bool__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __bool__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #27
Source File: myhdlpeek.py    From myhdlpeek with MIT License 5 votes vote down vote up
def __not__(self):
        return self.apply_op1(operator.not_).binarize() 
Example #28
Source File: test_richcmp.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __nonzero__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __nonzero__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad()) 
Example #29
Source File: test_bool.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_operator(self):
        import operator
        self.assertIs(operator.truth(0), False)
        self.assertIs(operator.truth(1), True)
        self.assertIs(operator.not_(1), False)
        self.assertIs(operator.not_(0), True)
        self.assertIs(operator.contains([], 1), False)
        self.assertIs(operator.contains([1], 1), True)
        self.assertIs(operator.lt(0, 0), False)
        self.assertIs(operator.lt(0, 1), True)
        self.assertIs(operator.is_(True, True), True)
        self.assertIs(operator.is_(True, False), False)
        self.assertIs(operator.is_not(True, True), False)
        self.assertIs(operator.is_not(True, False), True) 
Example #30
Source File: test_richcmp.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_not(self):
        # Check that exceptions in __bool__ are properly
        # propagated by the not operator
        import operator
        class Exc(Exception):
            pass
        class Bad:
            def __bool__(self):
                raise Exc

        def do(bad):
            not bad

        for func in (do, operator.not_):
            self.assertRaises(Exc, func, Bad())