Пример #1
0
 def test_is_not(self):
     #operator = self.module
     a = b = 'xyzpdq'
     c = a[:3] + b[3:]
     self.assertRaises(TypeError, operator.is_not)
     self.assertFalse(operator.is_not(a, b))
     self.assertTrue(operator.is_not(a,c))
Пример #2
0
 def test_is_not(self):
     #operator = self.module
     a = b = 'xyzpdq'
     c = a[:3] + b[3:]
     self.assertRaises(TypeError, operator.is_not)
     self.assertFalse(operator.is_not(a, b))
     self.assertTrue(operator.is_not(a, c))
Пример #3
0
 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)
Пример #4
0
 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)
Пример #5
0
def test_operator():
    # stdlib
    import operator

    assert operator.truth(0) == SyFalse
    assert operator.truth(1) == SyTrue
    assert operator.not_(1) == SyFalse
    assert operator.not_(0) == SyTrue
    assert operator.contains([], 1) == SyFalse
    assert operator.contains([1], 1) == SyTrue
    assert operator.lt(0, 0) == SyFalse
    assert operator.lt(0, 1) == SyTrue
    assert operator.is_(SyTrue, SyTrue) == SyTrue
    assert operator.is_(SyTrue, SyFalse) == SyFalse
    assert operator.is_not(SyTrue, SyTrue) == SyFalse
    assert operator.is_not(SyTrue, SyFalse) == SyTrue
Пример #6
0
 def eos(self, inputLink=0):
     self.eosSeen[inputLink] = True
     if reduce(operator.and_, filter(lambda x: operator.is_not(x, None),
                                     self.eosSeen)):
         self._localEos()
         for f in self.outputEos:
             if f: f()
Пример #7
0
    def get_all_point_resource_id(self, series_id):
        """
        获取一个系列所有的pointID
        :param series_id:
        :return:
        """
        from operator import is_not

        url = f'{self.ip}/common/points/{series_id}'
        response = requests.get(url=url, headers=self.headers)
        point_list_ret = response.json()
        try:
            data_list = point_list_ret['data']
            id_list = [data_dic['children'] for data_dic in data_list]
        except TypeError:
            print(f'接口common/points报错,返回{point_list_ret["msg"]}', series_id)
        except KeyError:
            print(f'接口common/points返回{point_list_ret}')
        else:
            point_id_list = [[{
                'id': c['id'],
                'resource_id': c['resourceId']
            } for c in child_id_list] for child_id_list in id_list]
            all_id_list = list(chain(*point_id_list))
            return list(
                filter(lambda x: is_not(x['resource_id'], None), all_id_list))
def parse_parameter_joint(joint: ParameterJoint, instance, variables):
    results = []
    if joint.jointType is not None:
        if joint.jointType == "and":
            for filter_ in joint.filters:
                results.append(parse_parameter_joint(filter_, instance, variables))
            if False in results:
                return False
            else:
                return True
        elif joint.jointType == "or":
            for filter_ in joint.filters:
                results.append(parse_parameter_joint(filter_, instance, variables))
            if True in results:
                return True
            else:
                return False
    else:
        left = parse_parameter(joint.left, instance, variables)
        operator_ = joint.operator
        right = parse_parameter(joint.right, instance, variables)
        if operator_ == "equals":
            return do_equals_with_value_type_check(left, right)
        elif operator_ == "not-equals":
            return do_not_equals_with_value_type_check(left, right)
        elif operator_ == 'empty':
            if left == "":
                return operator.is_(None, None)
            return operator.is_(left, None)
        elif operator_ == 'not-empty':
            if left == "":
                return operator.is_not(None, None)
            return operator.is_not(left, None)
        elif operator_ == "more":
            return do_more_with_value_type_check(left, right)
        elif operator_ == "more-equals":
            return do_more_equals_with_value_type_check(left, right)
        elif operator_ == "less":
            return do_less_with_value_type_check(left, right)
        elif operator_ == "less-equals":
            return do_less_equals_with_value_type_check(left, right)
        elif operator_ == 'in':
            return do_in_with_value_type_check(left, right)
        elif operator_ == 'not-in':
            return do_not_in_with_value_type_check(left, right)
        else:
            raise Exception("operator is not supported")
Пример #9
0
def main():
    a = -1
    b = 5

    print("a =", a)
    print("b =", b)

    print("not_(a)     :", operator.not_(a))
    print("truth(a)    :", operator.truth(a))
    print("is_(a, b)   :", operator.is_(a, b))
    print("is_not(a, b):", operator.is_not(a, b))
Пример #10
0
 def test_operator(self):
     import operator
     self.assertIs(operator.truth(0), False)
     self.assertIs(operator.truth(1), 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)
Пример #11
0
def operator_Boolean():
    a = -1
    b = 5

    print('a = ', a)
    print('b = ', b)
    print()
    print('not_(a)      :', operator.not_(a))
    print('truth(a)     :', operator.truth(a))
    print('is_(a, b)    :', operator.is_(a, b))
    print('is_not(a, b) :', operator.is_not(a, b))
Пример #12
0
 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)
Пример #13
0
 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)
Пример #14
0
def parse_filename(args):
    def mapper(arg):
        try:
            new_int = int(arg)
            return new_int
        except ValueError:
            return arg
        except TypeError:
            pass

    def predicate(_type):
        return lambda x: isinstance(x, _type)

    arg_list = filter(lambda x: op.is_not(x, None), map(mapper, args))

    pair = (tuple(filter(predicate(str),
                         arg_list)), filter(predicate(int), arg_list))

    return pair
Пример #15
0
def parse_filename(args):
    def mapper(arg):
        try:
            new_int = int(arg)
            return new_int
        except ValueError:
            return arg
        except TypeError:
            pass

    def predicate(_type):
        return lambda x: isinstance(x, _type)

    arg_list = filter(lambda x: op.is_not(x, None),
                      map(mapper, args))

    pair = (tuple(filter(predicate(str), arg_list)),
            filter(predicate(int), arg_list))

    return pair
Пример #16
0
 def test_is_not(self):
     a = b = "xyzpdq"
     c = a[:3] + b[3:]
     self.assertRaises(TypeError, operator.is_not)
     self.assertFalse(operator.is_not(a, b))
     self.assertTrue(operator.is_not(a, c))
Пример #17
0
print('x or y is',x or y)
print('not x is',not x)


print(" sequence operator ")
print(" +  ", "Hello" + "World")
print(" concat ", op.concat("Hello", "World"))
print(" __add__ ", "Hello".__add__("World"))
print(" *  ", "Hello" * 3)
print(" __mul__ ", "Hello".__mul__(3))
print(" repeat ", op.repeat("Hello", 3))

print(" is ", "abc" is "abc")
print(" is_", op.is_("abc","abc"))
print(" is not ", "abc" is not "abcd")
print(" is_", op.is_not("abc","abcd"))

print(" in ", "a" in "abc")
print(" __contains__", "abc".__contains__('a'))
print(" contains", op.contains("abc",'a'))

print(" in ", "a" not in "abc")
print(" __contains__", not("abc".__contains__('a')))
print(" contains", op.not_(op.contains("abc",'a')))


print(" __getslice__ :", [0,1,2,3].__getslice__(0,2))
print("  getslice    :", op.getslice([0,1,2,3],0,2))
l=[0,1,2,3]
print(" __setslice__ :", l.__setslice__(0,2,[99,99]),l)
print(" __delslice__ :", l.__delslice__(0,2),l)
Пример #18
0
hasattr_ = lambda a: partial(reorder_args(hasattr, 1, 0), a)
getattr_ = lambda a: partial(reorder_args(getattr, 1, 0), a)
# it is "setattr(o, a, v)" but we call it as "setattr_(a, v)(o)" thus a,v,o needs to be reorderd to o, a, v, i.e. 2,0,1
# note that setattr_ returns the object itself so it can be chained
setattr_ = lambda a, v: combine(
    logic_or, partial(reorder_args(setattr, 2, 0, 1), a, v), identity)
delattr_ = lambda a: combine(logic_or, partial(reorder_args(delattr, 1, 0), a),
                             identity)
maybe_get = lambda a, d=None: choice(hasattr_(a), getattr_(a), const(d))
maybe_set = lambda a, v: choice(const(is_not_none(v)), setattr_(a, v), identity
                                )
identity = lambda x, *a, **kw: x
#mk_query    = lambda c, t, w, *args: "SELECT {0} FROM {1} WHERE {2}{3}".format(c, t, w, "" if not args else " and "+args[0])
do_update = lambda x, y: x.update(y) or x
d_filter = lambda keys: (lambda d: dict(
    ((k, v) for k, v in d.iteritems() if k in keys)))
d_filter_n = lambda keys: (lambda d: dict(
    ((k, v) for k, v in d.iteritems() if k not in keys)))
#printf      = lambda x, y : x.printfn(y)
#collectf    = lambda x, y : x.collectfn(y)

filter_true = partial(filter, truth)
is_not_kw = lambda x, y, **kwargs: is_not(x, y)
is_not_none = partial(is_not, None)
is_not_none_kw = partial(is_not_kw, None)
is_iterable = combine(logic_or, hasattr_('__iter__'), hasattr_('__getitem__'))
listify = choice(is_iterable, identity, lambda x: [x])
mk_list = lambda *args: list(args)
mk_tuple = lambda *args: args
truth_tbl = lambda *args: tuple(map(truth, args))
        self.id = id
        self.nombre = nombre


personas = []

personas.append(Persona(1001, 'Mario'))
personas.append(Persona(1002, 'Angela'))
personas.append(personas[0])
personas.append(Persona(1003, 'Fabián'))
personas.append(Persona(1004, 'Andrea'))
personas.append(personas[0])

primera_persona = personas[0]

resultado = list(filter(lambda p: is_not(p, primera_persona), personas))

for r in resultado:
    print(r.id, r.nombre)

print()

print('Cantidad de elementos en el resultado:', len(resultado))

print()

resultado = list(filter(lambda p: p is not primera_persona, personas))

for r in resultado:
    print(r.id, r.nombre)
Пример #20
0
def is_not(a):
    return operator.is_not(a)
Пример #21
0
# 逻辑操作也通常适用于所有对象,并支持真值测试,身份测试和布尔运算
# 这些带双__前后的method很多都可以用于定义新的类方法(OOP环境)

# operator.not_(obj)
# operator.__not__(obj)
# 返回not obj。(请注意,对象实例没有__not__()方法;只有解释器核定义了此操作。结果受到__bool__()和__len__()方法的影响。)

# operator.truth(obj)
# 如果obj为真,则返回True,否则返回False。这相当于使用bool构造函数。

# operator.is_(a, b)
# 返回a 是 b。测试对象标识。

# operator.is_not(a, b)
# 返回a 是 不是 b。测试对象标识。
print(operator.is_not(6, 6))

# 数学和按位操作是最多的:

# operator.abs(obj)
# operator.__abs__(obj)
# 返回obj的绝对值

# operator.add(a, b)
# operator.__add__(a, b)
# 返回a + b,对于a和b t5 >数字

# operator.and_(a, b)
# operator.__and__(a, b)
# 返回按位和a和b
print(operator.and_(True, True))
Пример #22
0
# for simple expressions

import operator

# ------------------------------------------------------------------------------
# Logical Operations
# Functions are provided for determining the boolean equivalent for a value,
# negating a value to create the opposite boolean value, and comparing objects
# to see if they are identical.

a, b, c = [1], [1], [-1]

print("not a:       ", operator.not_(a))
print("if a:        ", operator.truth(a))
print("b is a:      ", operator.is_(a, b))
print("b is not a:  ", operator.is_not(a, b))


# ------------------------------------------------------------------------------
# Comparison Operators
# All of the rich comparison operators are supported

a, b = 1, 5.0

print("a = ", a)

for func in "lt le eq ne ge gt".split():
    print("{}(a, b): {}".format(func, getattr(operator, func)(a, b)))


# ------------------------------------------------------------------------------
Пример #23
0
def test_is_not(a: object, b: object):
    assert op.is_not(a)(b) == operator.is_not(a, b)
Пример #24
0
def is_not(a):
    return operator.is_not(a)
Пример #25
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.is_not(self.input(0), self.input(1)))
Пример #26
0
def is_not_(a, b):
    return is_not(b, a)
Пример #27
0
print("0x0010 ^ 0x0011 = operator.xor(0x0010, 0x0011) = ", operator.xor(0x0010, 0x0011))

# 二進位NOT運算
print("~ 0x1000 = operator.invert(0x1000) = ", operator.invert(0x1000))

# 二進位OR運算
print("0x0010 | 0x0011 = operator.or_(0x0010, 0x0011) = ", operator.or_(0x0010, 0x0011))

# 次方運算
print("2 ** 16 = operator.pow(2, 16) = ", operator.pow(2, 16))

# 辨識運算
print("1 is 1 = operator.is_(1,1) = ", operator.is_(1,1))

# 辨識運算
print("1 is not 2 = operator.is_not(1,2) = ", operator.is_not(1,2))

# 以索引指派值
obj = [1,2,3]
operator.setitem(obj, 1, 4)
print("obj[1] = 4 = operator.setitem(obj, 1, 4) = ", obj)

# 以索引刪除值
operator.delitem(obj, 1)
print("del obj[1] = operator.delitem(obj, 1) = ", obj)

# 以索引取值
print("obj[1] = operator.getitem(obj,1) = ", operator.getitem(obj, 1))

# 左移運算
print("16 << 1 = operator.lshift(16, 1) = ", operator.lshift(16, 1))
def parse_parameter_joint(joint: ParameterJoint, instance, variables):
    results = []
    if joint.jointType is not None:
        if joint.jointType == "and":
            for filter_ in joint.filters:
                results.append(
                    parse_parameter_joint(filter_, instance, variables))
            if False in results:
                return False
            else:
                return True
        elif joint.jointType == "or":
            for filter_ in joint.filters:
                results.append(
                    parse_parameter_joint(filter_, instance, variables))
            if True in results:
                return True
            else:
                return False
    else:
        left = parse_parameter(joint.left, instance, variables)
        operator_ = joint.operator
        right = parse_parameter(joint.right, instance, variables)
        if operator_ == "equals":
            if isinstance(right, str):
                return operator.eq(str(left), right)
            return operator.eq(str(left), right)
        elif operator_ == "not-equals":
            if isinstance(right, str):
                return operator.eq(str(left), right)
            return operator.ne(left, right)
        elif operator_ == 'empty':
            return operator.is_(left, None)
        elif operator_ == 'not-empty':
            return operator.is_not(left, None)
        elif operator_ == "more":
            return operator.gt(left, right)
        elif operator_ == "more-equals":
            return operator.ge(left, right)
        elif operator_ == "less":
            return operator.lt(left, right)
        elif operator_ == "less-equals":
            return operator.le(left, right)
        elif operator_ == 'in':
            value_list = right.split(',')
            values: List = []
            for value in value_list:
                if value.isdigit():
                    values.append(int(value))
                else:
                    values.append(value)
            return left.isin(values)
        elif operator_ == 'not-in':
            value_list = right.split(',')
            values: List = []
            for value in value_list:
                if value.isdigit():
                    values.append(int(value))
                else:
                    values.append(value)
            return left.notin(values)
        else:
            raise Exception("operator is not supported")
Пример #29
0
"""
@project = 0604-1
@file = operator_1
@author = Liangjisheng
@create_time = 2018/6/5 0005 下午 18:02
"""
import operator as op

a = [1, 2, 3]
b = a
print('a =', a)
print('b =', b)
print('operator.not_(a):', op.not_(a))
print('operator.truth(a):', op.truth(a))
print('operator.is_(a, b):', op.is_(a, b))
print('operator.is_not(a, b):', op.is_not(a, b))
print()

a = 3
b = 5
print('a =', a)
print('b =', b)
for func in (op.lt, op.le, op.eq, op.ne, op.ge, op.gt):
    print('{0}({1}, {2}):'.format(func.__name__, a, b), func(a, b))
print()

a, b, c, d = -1, 2, -3, 4
print('a =', a)
print('b =', b)
print('c =', c)
print('d =', d)
Пример #30
0
                doc=operator.getitem.__doc__)
__getitem__ = spice(lambda x, y: operator.__getitem__(x, y),
                    name='__getitem__',
                    doc=operator.getitem.__doc__)

# reversed
gt = spice(lambda x, y: operator.gt(y, x), name='gt')
__gt__ = spice(lambda x, y: operator.__gt__(y, x))

indexOf = spice(lambda x, y: operator.indexOf(x, y),
                name='indexOf',
                doc=operator.indexOf.__doc__)
is_ = spice(lambda x, y: operator.is_(x, y),
            name='is_',
            doc=operator.is_.__doc__)
is_not = spice(lambda x, y: operator.is_not(x, y),
               name='is_not',
               doc=operator.is_not.__doc__)

# reversed
le = spice(lambda x, y: operator.le(y, x), name='le')
__le__ = spice(lambda x, y: operator.__le__(y, x), name='__le__')

# reversed
lshift = spice(lambda x, y: operator.lshift(y, x), name='lshift')
__lshift__ = spice(lambda x, y: operator.__lshift__(y, x), name='__lshift__')

# reversed
lt = spice(lambda x, y: operator.lt(y, x), name='lt')
__lt__ = spice(lambda x, y: operator.__lt__(y, x), name='__lt__')
 def test_is_not(self):
     a = b = 'xyzpdq'
     c = a[:3] + b[3:]
     self.failUnlessRaises(TypeError, operator.is_not)
     self.failIf(operator.is_not(a, b))
     self.failUnless(operator.is_not(a, c))
Пример #32
0
# You can always use your own functions and lambda expressions instead

print(operator.add(2, 3))
print(operator.mul(2, 3))
print(operator.pow(2, 3))
print(operator.mod(2, 3))
print(operator.floordiv(2, 3))
print(operator.neg(2))
print(operator.lt(2, 3))
print(operator.le(3, 3))
print(operator.gt(2, 3))
print(operator.ge(3, 3))
print(operator.eq(3, 3))
print(operator.ne(2, 3))
print(operator.is_(2, 3))
print(operator.is_not(2, 3))
print(operator.and_(2, 3))
print(operator.or_(0, 3))
print(operator.not_(0))
print(operator.concat('py', 'python'))
print(operator.contains('py', 'python'))
print(operator.countOf('py', 'python'))
print(operator.truth([]))

l = [1, 2, 3, 4, 5, 6]
s = 'python'
print(operator.getitem(l, 2))

f = operator.itemgetter(2, 4, 5)
print(f(l))
print(f(s))
Пример #33
0
 def test_is_not(self):
     a = b = 'xyzpdq'
     c = a[:3] + b[3:]
     self.failUnlessRaises(TypeError, operator.is_not)
     self.failIf(operator.is_not(a, b))
     self.failUnless(operator.is_not(a,c))
Пример #34
0
# Not implemented
# print operator.not_("hello")

print operator.truth(True)
print operator.truth(False)
print operator.truth(1)
print operator.truth(0)


print operator.is_("hello", "hello")
print operator.is_("hello", "goodbye")
print operator.is_(1, 1)
print operator.is_(2, 1)

print operator.is_not("hello", "goodbye")
print operator.is_not("hello", "hello")
print operator.is_not(1, 2)
print operator.is_not(1, 1)

print operator.abs(5)
print operator.abs(-5)
print operator.abs(1.1)
print operator.abs(-1.1)

print operator.add(1, 2)
print operator.add(-4, 2)
print operator.add("he", "llo")

print operator.and_(2, 3)
print operator.and_(5, 3)
Пример #35
0
from operator import not_, truth, is_, is_not

a = -1
b = 5

print('a = ', a)
print('b = ', b)
print()

print('not_(a)      :', not_(a))  # not(a)
print('truth(a)     :', truth(a))  # bool(a)
print('is_(a,b)     :', is_(a, b))  # a is b
print('is_not(a,b)  :', is_not(a, b))  # a is not b
Пример #36
0
# operator_boolean.py

from operator import not_, truth, is_, is_not

a = -1
b = 5

print('a =', a)
print('b =', b)
print()

print('not_(a)     :', not_(a))
print('truth(a)    :', truth(a))
print('is_(a, b)   :', is_(a, b))
print('is_not(a, b):', is_not(a, b))
Пример #37
0
 def test_is_not(self):
     a = b = 'xyzpdq'
     c = a[:3] + b[3:]
     self.failIf(operator.is_not(a, b))
     self.failUnless(operator.is_not(a,c))
 def test_result_each_properties_are_not_same_object(self):
     properties = [i[1] for i in self.result]
     comps = combinations(properties, 2)
     self.assertTrue(all(is_not(*i) for i in comps))