本文整理汇总了Python中operator.or_方法的典型用法代码示例。如果您正苦于以下问题:Python operator.or_方法的具体用法?Python operator.or_怎么用?Python operator.or_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块operator的用法示例。
在下文中一共展示了operator.or_方法的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: normalize
点赞 6
# 需要导入模块: 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,
示例2: index
点赞 6
# 需要导入模块: 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,
示例3: get_queryset
点赞 6
# 需要导入模块: 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,
示例4: _apply_filter
点赞 6
# 需要导入模块: 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,
示例5: _normalize_group_dns
点赞 6
# 需要导入模块: 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,
示例6: _flagOp
点赞 6
# 需要导入模块: 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,
示例7: _term_eval
点赞 6
# 需要导入模块: 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,
示例8: chain_with_mv
点赞 6
# 需要导入模块: 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,
示例9: test_multiply
点赞 6
# 需要导入模块: 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,
示例10: get_descendants
点赞 6
# 需要导入模块: 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,
示例11: get_ancestors
点赞 6
# 需要导入模块: 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,
示例12: testOr
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def testOr(self):
self.binaryCheck(operator.or_)
开发者ID:myhdl,项目名称:myhdl,代码行数:4,
示例13: __init__
点赞 5
# 需要导入模块: 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,
示例14: free
点赞 5
# 需要导入模块: 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,
示例15: free
点赞 5
# 需要导入模块: 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,
示例16: constants
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def constants(self):
"""
Return a set of individual constants (non-predicates).
:return: set of ``Variable`` objects
"""
return self.visit(lambda e: e.constants(),
lambda parts: reduce(operator.or_, parts, set()))
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:9,
示例17: predicates
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def predicates(self):
"""
Return a set of predicates (constants, not variables).
:return: set of ``Variable`` objects
"""
return self.visit(lambda e: e.predicates(),
lambda parts: reduce(operator.or_, parts, set()))
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:9,
示例18: _variables
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _variables(self):
return tuple(map(operator.or_, (set(), set(), set([self.var])), self.drs._variables()))
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:4,
示例19: free
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def free(self):
""":see: Expression.free()"""
conds_free = reduce(operator.or_, [c.free() for c in self.conds], set())
if self.consequent:
conds_free.update(self.consequent.free())
return conds_free - set(self.refs)
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:8,
示例20: __init__
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def __init__(self, label, gen, op=operator.or_):
self.gen = gen
self.op = op
self.out_label = label + '_out'
self.in_label = label + '_in'
self.gen_label = label + '_gen'
self.kill_label = label + '_kill'
开发者ID:google,项目名称:tangent,代码行数:9,
示例21: __init__
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def __init__(self, flags: str = None,
none_ok: bool = False) -> None:
super().__init__(none_ok)
self._regex_type = type(re.compile(''))
# Parse flags from configdata.yml
if flags is None:
self.flags = 0
else:
self.flags = functools.reduce(
operator.or_,
(getattr(re, flag.strip()) for flag in flags.split(' | ')))
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:13,
示例22: get_tree_queryset_descendants
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def get_tree_queryset_descendants(model, nodes, include_self=False):
if not nodes:
return nodes
filters = []
for n in nodes:
lft, rght = n.lft, n.rght
if include_self:
lft -= 1
rght += 1
filters.append(Q(tree_id=n.tree_id, lft__gt=lft, rght__lt=rght))
q = reduce(operator.or_, filters)
return model.objects.filter(q).order_by(*model._meta.ordering)
# http://stackoverflow.com/questions/6471354/efficient-function-to-retrieve-a-queryset-of-ancestors-of-an-mptt-queryset
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:17,
示例23: get_tree_queryset_all
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def get_tree_queryset_all(model, nodes):
filters = []
for node in nodes:
filters.append(Q(tree_id=node.tree_id))
q = reduce(operator.or_, filters)
return model.objects.filter(q).order_by(*model._meta.ordering)
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:8,
示例24: orwhere
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def orwhere(self, *expressions):
self._where = self._add_query_clauses(
self._where, expressions, operator.or_)
开发者ID:danielecook,项目名称:Quiver-alfred,代码行数:5,
示例25: test_logical_operators
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def test_logical_operators(self):
def _check_bin_op(op):
result = op(df1, df2)
expected = DataFrame(op(df1.values, df2.values), index=df1.index,
columns=df1.columns)
assert result.values.dtype == np.bool_
assert_frame_equal(result, expected)
def _check_unary_op(op):
result = op(df1)
expected = DataFrame(op(df1.values), index=df1.index,
columns=df1.columns)
assert result.values.dtype == np.bool_
assert_frame_equal(result, expected)
df1 = {'a': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True},
'b': {'a': False, 'b': True, 'c': False,
'd': False, 'e': False},
'c': {'a': False, 'b': False, 'c': True,
'd': False, 'e': False},
'd': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True},
'e': {'a': True, 'b': False, 'c': False, 'd': True, 'e': True}}
df2 = {'a': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False},
'b': {'a': False, 'b': True, 'c': False,
'd': False, 'e': False},
'c': {'a': True, 'b': False, 'c': True, 'd': False, 'e': False},
'd': {'a': False, 'b': False, 'c': False,
'd': True, 'e': False},
'e': {'a': False, 'b': False, 'c': False,
'd': False, 'e': True}}
df1 = DataFrame(df1)
df2 = DataFrame(df2)
_check_bin_op(operator.and_)
_check_bin_op(operator.or_)
_check_bin_op(operator.xor)
_check_unary_op(operator.inv) # TODO: belongs elsewhere
开发者ID:Frank-qlu,项目名称:recruit,代码行数:43,
示例26: _create_comparison_method
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _create_comparison_method(cls, op):
def cmp_method(self, other):
op_name = op.__name__
if op_name in {'and_', 'or_'}:
op_name = op_name[:-1]
if isinstance(other, (ABCSeries, ABCIndexClass)):
# Rely on pandas to unbox and dispatch to us.
return NotImplemented
if not is_scalar(other) and not isinstance(other, type(self)):
# convert list-like to ndarray
other = np.asarray(other)
if isinstance(other, np.ndarray):
# TODO: make this more flexible than just ndarray...
if len(self) != len(other):
raise AssertionError("length mismatch: {self} vs. {other}"
.format(self=len(self),
other=len(other)))
other = SparseArray(other, fill_value=self.fill_value)
if isinstance(other, SparseArray):
return _sparse_array_op(self, other, op, op_name)
else:
with np.errstate(all='ignore'):
fill_value = op(self.fill_value, other)
result = op(self.sp_values, other)
return type(self)(result,
sparse_index=self.sp_index,
fill_value=fill_value,
dtype=np.bool_)
name = '__{name}__'.format(name=op.__name__)
return compat.set_function_name(cmp_method, name, cls)
开发者ID:Frank-qlu,项目名称:recruit,代码行数:39,
示例27: _add_comparison_ops
点赞 5
# 需要导入模块: import operator [as 别名]
# 或者: from operator import or_ [as 别名]
def _add_comparison_ops(cls):
cls.__and__ = cls._create_comparison_method(operator.and_)
cls.__or__ = cls._create_comparison_method(operator.or_)
super(SparseArray, cls)._add_comparison_ops()
# ----------
# Formatting
# -----------
开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,
注:本文中的operator.or_方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。