当前位置: 首页>>代码示例>>Python>>正文


Python operator.or_方法代码示例

本文整理汇总了Python中operator.or_方法的典型用法代码示例。如果您正苦于以下问题:Python operator.or_方法的具体用法?Python operator.or_怎么用?Python operator.or_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在operator的用法示例。


在下文中一共展示了operator.or_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: normalize

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def normalize(self, newvars=None):
        """Rename auto-generated unique variables"""
        def get_indiv_vars(e):
            if isinstance(e, IndividualVariableExpression):
                return set([e])
            elif isinstance(e, AbstractVariableExpression):
                return set()
            else:
                return e.visit(get_indiv_vars,
                               lambda parts: reduce(operator.or_, parts, set()))

        result = self
        for i,e in enumerate(sorted(get_indiv_vars(self), key=lambda e: e.variable)):
            if isinstance(e,EventVariableExpression):
                newVar = e.__class__(Variable('e0%s' % (i+1)))
            elif isinstance(e,IndividualVariableExpression):
                newVar = e.__class__(Variable('z%s' % (i+1)))
            else:
                newVar = e
            result = result.replace(e.variable, newVar, True)
        return result 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:23,代码来源:logic.py

示例2: index

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def index(request):
    person = get_person(request.user)

    # PERS, INST reminders for this person
    personal_reminders = Reminder.objects.filter(reminder_type__in=['PERS','INST'], person=person).select_related('course')

    # ROLE reminders for this person's current roles
    user_roles = Role.objects_fresh.filter(person=person)
    role_query = reduce(
        operator.or_,
        (Q(role=r.role) & Q(unit=r.unit) for r in user_roles)
        )
    role_reminders = Reminder.objects.filter(role_query, reminder_type='ROLE').select_related('unit')

    reminders = set(personal_reminders) | set(role_reminders)
    context = {
        'reminders': reminders,
    }
    return render(request, 'reminders/index.html', context) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:views.py

示例3: get_queryset

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def get_queryset(self):
        queryset = super(ListModelView, self).get_queryset()
        search = self.get_search_by()
        effective = self.get_filter_by()
        ordering = self.get_ordering()
        if search and 'actived' in effective.keys():
            del effective['actived']
        _all = self.apply_optimize_queryset().filter(**effective)
        if hasattr(
                self.model,
                'onidc_id') and not self.request.user.is_superuser:
            _shared = _all.filter(mark='shared')
            _private = _all.filter(onidc_id=self.onidc_id)
            queryset = (_shared | _private).order_by(*ordering)
        else:
            queryset = _all.order_by(*ordering)
        if search:
            lst = []
            for q in search:
                q = q.strip()
                str = [models.Q(**{k: q}) for k in self.allow_search_fields]
                lst.extend(str)
            query_str = reduce(operator.or_, lst)
            queryset = queryset.filter(query_str).order_by(*ordering)
        return queryset 
开发者ID:Wenvki,项目名称:django-idcops,代码行数:27,代码来源:list.py

示例4: _apply_filter

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _apply_filter(self, col, val, comparator):
        """
        Builds a dataframe matching original dataframe with conditions passed

        The original dataframe is left intact
        """
        if not is_container(val):
            val = [val]

        if comparator == LookupComparator.EQUALS:
            # index must be sliced differently
            if col == 'id':
                expr = self._meta.index.isin(val)
            else:
                expr = self._meta[col].isin(val)
        else:
            if comparator == LookupComparator.STARTSWITH:
                op = 'startswith'
            else:
                op = 'contains'
            expr = self._combine_filters(
                map(getattr(self._meta[col].str, op), val), operator.or_)
        return expr 
开发者ID:ffeast,项目名称:finam-export,代码行数:25,代码来源:export.py

示例5: _normalize_group_dns

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _normalize_group_dns(self, group_dns):
        """
        Converts one or more group DNs to an LDAPGroupQuery.

        group_dns may be a string, a non-empty list or tuple of strings, or an
        LDAPGroupQuery. The result will be an LDAPGroupQuery. A list or tuple
        will be joined with the | operator.

        """
        if isinstance(group_dns, LDAPGroupQuery):
            query = group_dns
        elif isinstance(group_dns, str):
            query = LDAPGroupQuery(group_dns)
        elif isinstance(group_dns, (list, tuple)) and len(group_dns) > 0:
            query = reduce(operator.or_, map(LDAPGroupQuery, group_dns))
        else:
            raise ValueError(group_dns)

        return query 
开发者ID:django-auth-ldap,项目名称:django-auth-ldap,代码行数:21,代码来源:backend.py

示例6: _flagOp

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _flagOp(op, left, right):
    """
    Implement a binary operator for a L{FlagConstant} instance.

    @param op: A two-argument callable implementing the binary operation.  For
        example, C{operator.or_}.

    @param left: The left-hand L{FlagConstant} instance.
    @param right: The right-hand L{FlagConstant} instance.

    @return: A new L{FlagConstant} instance representing the result of the
        operation.
    """
    value = op(left.value, right.value)
    names = op(left.names, right.names)
    result = FlagConstant()
    result._realize(left._container, names, value)
    return result 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:_constants.py

示例7: _term_eval

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _term_eval(term, column_variable, column_key):

    if term["type"].lower() == "conjunction":
        return and_(*((_term_eval(t, column_variable, column_key) for t in term["terms"])))
    elif term["type"].lower() == "disjunction":
        return or_(*((_term_eval(t, column_variable, column_key) for t in term["terms"])))
    elif term["type"].lower() == "literal":
        if "key" in term and term["key"]:
            key_operator = term.get("key_operator", "IN")
            if key_operator is None or key_operator == "IN":
                key_condition = column_key.in_(term["key"])
            elif key_operator=="ILIKE":
                key_condition = or_(*(column_key.ilike(pattern) for pattern in term["key"]))
            return and_(column_variable==term["variable"], key_condition)
        else:
            return column_variable==term["variable"] 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:18,代码来源:formular.py

示例8: chain_with_mv

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def chain_with_mv(self):
        coords = x, y, z = symbols('x y z', real=True)
        ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
        s = Sdop([(x, Pdop(x)), (y, Pdop(y))])

        assert type(ex * s) is Sdop
        assert type(s * ex) is Mv

        # type should be preserved even when the result is 0
        assert type(ex * Sdop([])) is Sdop
        assert type(Sdop([]) * ex) is Mv

        # As discussed with brombo, these operations are not well defined - if
        # you need them, you should be using `Dop` not `Sdop`.
        for op in [operator.xor, operator.or_, operator.lt, operator.gt]:
            with pytest.raises(TypeError):
                op(ex, s)
            with pytest.raises(TypeError):
                op(s, ex) 
开发者ID:pygae,项目名称:galgebra,代码行数:21,代码来源:test_differential_ops.py

示例9: test_multiply

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def test_multiply(self):
        coords = x, y, z = symbols('x y z', real=True)
        ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)

        p = Pdop(x)
        assert x * p == Sdop([(x, p)])
        assert ex * p == Sdop([(ex, p)])

        assert p * x == p(x) == S(1)
        assert p * ex == p(ex) == S(0)
        assert type(p(ex)) is Mv

        # These are not defined for consistency with Sdop
        for op in [operator.xor, operator.or_, operator.lt, operator.gt]:
            with pytest.raises(TypeError):
                op(ex, p)
            with pytest.raises(TypeError):
                op(p, ex) 
开发者ID:pygae,项目名称:galgebra,代码行数:20,代码来源:test_differential_ops.py

示例10: get_descendants

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def get_descendants(self, include_self=True):
        """
        Gets a the MPTT descendants of a queryset
        Found and modified from
        http://stackoverflow.com/questions/5722767
        """
        filters = []
        for node in self.all():
            lft, rght = node.lft, node.rght
            if include_self:
                lft -= 1
                rght += 1

            filters.append(Q(tree_id=node.tree_id, lft__gt=lft, rght__lt=rght))

        q = functools.reduce(operator.or_, filters)

        return self.model.objects.filter(q) 
开发者ID:chaoss,项目名称:prospector,代码行数:20,代码来源:managers.py

示例11: get_ancestors

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def get_ancestors(self, include_self=True):
        """
        Gets the MPTT ancestors of a queryset. Adapted from get_descendants()
        """

        filters = []
        for node in self.all():
            lft, rght = node.lft, node.rght

            if include_self:
                lft += 1
                rght -= 1

            filters.append(Q(tree_id=node.tree_id, lft__lt=lft, rght__gt=rght))

        q = functools.reduce(operator.or_, filters)

        return self.model.objects.filter(q) 
开发者ID:chaoss,项目名称:prospector,代码行数:20,代码来源:managers.py

示例12: testOr

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def testOr(self):
        self.binaryCheck(operator.or_) 
开发者ID:myhdl,项目名称:myhdl,代码行数:4,代码来源:test_Signal.py

示例13: __init__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def __init__(self, left: CriteriaType, right: CriteriaType):
        super().__init__(left, right, operator.or_, "|") 
开发者ID:tensortrade-org,项目名称:tensortrade,代码行数:4,代码来源:criteria.py

示例14: free

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def free(self):
        return reduce(operator.or_, ((atom.free() | atom.constants()) for atom in self)) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:4,代码来源:resolution.py

示例15: free

# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def free(self):
        """
        Return a set of all the free (non-bound) variables.  This includes
        both individual and predicate variables, but not constants.
        :return: set of ``Variable`` objects
        """
        return self.visit(lambda e: e.free(),
                          lambda parts: reduce(operator.or_, parts, set())) 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:10,代码来源:logic.py


注:本文中的operator.or_方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。