Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python3....
File: operator.py
"""
[0] Fix | Delete
Operator Interface
[1] Fix | Delete
[2] Fix | Delete
This module exports a set of functions corresponding to the intrinsic
[3] Fix | Delete
operators of Python. For example, operator.add(x, y) is equivalent
[4] Fix | Delete
to the expression x+y. The function names are those used for special
[5] Fix | Delete
methods; variants without leading and trailing '__' are also provided
[6] Fix | Delete
for convenience.
[7] Fix | Delete
[8] Fix | Delete
This is the pure Python implementation of the module.
[9] Fix | Delete
"""
[10] Fix | Delete
[11] Fix | Delete
__all__ = ['abs', 'add', 'and_', 'attrgetter', 'concat', 'contains', 'countOf',
[12] Fix | Delete
'delitem', 'eq', 'floordiv', 'ge', 'getitem', 'gt', 'iadd', 'iand',
[13] Fix | Delete
'iconcat', 'ifloordiv', 'ilshift', 'imatmul', 'imod', 'imul',
[14] Fix | Delete
'index', 'indexOf', 'inv', 'invert', 'ior', 'ipow', 'irshift',
[15] Fix | Delete
'is_', 'is_not', 'isub', 'itemgetter', 'itruediv', 'ixor', 'le',
[16] Fix | Delete
'length_hint', 'lshift', 'lt', 'matmul', 'methodcaller', 'mod',
[17] Fix | Delete
'mul', 'ne', 'neg', 'not_', 'or_', 'pos', 'pow', 'rshift',
[18] Fix | Delete
'setitem', 'sub', 'truediv', 'truth', 'xor']
[19] Fix | Delete
[20] Fix | Delete
from builtins import abs as _abs
[21] Fix | Delete
[22] Fix | Delete
[23] Fix | Delete
# Comparison Operations *******************************************************#
[24] Fix | Delete
[25] Fix | Delete
def lt(a, b):
[26] Fix | Delete
"Same as a < b."
[27] Fix | Delete
return a < b
[28] Fix | Delete
[29] Fix | Delete
def le(a, b):
[30] Fix | Delete
"Same as a <= b."
[31] Fix | Delete
return a <= b
[32] Fix | Delete
[33] Fix | Delete
def eq(a, b):
[34] Fix | Delete
"Same as a == b."
[35] Fix | Delete
return a == b
[36] Fix | Delete
[37] Fix | Delete
def ne(a, b):
[38] Fix | Delete
"Same as a != b."
[39] Fix | Delete
return a != b
[40] Fix | Delete
[41] Fix | Delete
def ge(a, b):
[42] Fix | Delete
"Same as a >= b."
[43] Fix | Delete
return a >= b
[44] Fix | Delete
[45] Fix | Delete
def gt(a, b):
[46] Fix | Delete
"Same as a > b."
[47] Fix | Delete
return a > b
[48] Fix | Delete
[49] Fix | Delete
# Logical Operations **********************************************************#
[50] Fix | Delete
[51] Fix | Delete
def not_(a):
[52] Fix | Delete
"Same as not a."
[53] Fix | Delete
return not a
[54] Fix | Delete
[55] Fix | Delete
def truth(a):
[56] Fix | Delete
"Return True if a is true, False otherwise."
[57] Fix | Delete
return True if a else False
[58] Fix | Delete
[59] Fix | Delete
def is_(a, b):
[60] Fix | Delete
"Same as a is b."
[61] Fix | Delete
return a is b
[62] Fix | Delete
[63] Fix | Delete
def is_not(a, b):
[64] Fix | Delete
"Same as a is not b."
[65] Fix | Delete
return a is not b
[66] Fix | Delete
[67] Fix | Delete
# Mathematical/Bitwise Operations *********************************************#
[68] Fix | Delete
[69] Fix | Delete
def abs(a):
[70] Fix | Delete
"Same as abs(a)."
[71] Fix | Delete
return _abs(a)
[72] Fix | Delete
[73] Fix | Delete
def add(a, b):
[74] Fix | Delete
"Same as a + b."
[75] Fix | Delete
return a + b
[76] Fix | Delete
[77] Fix | Delete
def and_(a, b):
[78] Fix | Delete
"Same as a & b."
[79] Fix | Delete
return a & b
[80] Fix | Delete
[81] Fix | Delete
def floordiv(a, b):
[82] Fix | Delete
"Same as a // b."
[83] Fix | Delete
return a // b
[84] Fix | Delete
[85] Fix | Delete
def index(a):
[86] Fix | Delete
"Same as a.__index__()."
[87] Fix | Delete
return a.__index__()
[88] Fix | Delete
[89] Fix | Delete
def inv(a):
[90] Fix | Delete
"Same as ~a."
[91] Fix | Delete
return ~a
[92] Fix | Delete
invert = inv
[93] Fix | Delete
[94] Fix | Delete
def lshift(a, b):
[95] Fix | Delete
"Same as a << b."
[96] Fix | Delete
return a << b
[97] Fix | Delete
[98] Fix | Delete
def mod(a, b):
[99] Fix | Delete
"Same as a % b."
[100] Fix | Delete
return a % b
[101] Fix | Delete
[102] Fix | Delete
def mul(a, b):
[103] Fix | Delete
"Same as a * b."
[104] Fix | Delete
return a * b
[105] Fix | Delete
[106] Fix | Delete
def matmul(a, b):
[107] Fix | Delete
"Same as a @ b."
[108] Fix | Delete
return a @ b
[109] Fix | Delete
[110] Fix | Delete
def neg(a):
[111] Fix | Delete
"Same as -a."
[112] Fix | Delete
return -a
[113] Fix | Delete
[114] Fix | Delete
def or_(a, b):
[115] Fix | Delete
"Same as a | b."
[116] Fix | Delete
return a | b
[117] Fix | Delete
[118] Fix | Delete
def pos(a):
[119] Fix | Delete
"Same as +a."
[120] Fix | Delete
return +a
[121] Fix | Delete
[122] Fix | Delete
def pow(a, b):
[123] Fix | Delete
"Same as a ** b."
[124] Fix | Delete
return a ** b
[125] Fix | Delete
[126] Fix | Delete
def rshift(a, b):
[127] Fix | Delete
"Same as a >> b."
[128] Fix | Delete
return a >> b
[129] Fix | Delete
[130] Fix | Delete
def sub(a, b):
[131] Fix | Delete
"Same as a - b."
[132] Fix | Delete
return a - b
[133] Fix | Delete
[134] Fix | Delete
def truediv(a, b):
[135] Fix | Delete
"Same as a / b."
[136] Fix | Delete
return a / b
[137] Fix | Delete
[138] Fix | Delete
def xor(a, b):
[139] Fix | Delete
"Same as a ^ b."
[140] Fix | Delete
return a ^ b
[141] Fix | Delete
[142] Fix | Delete
# Sequence Operations *********************************************************#
[143] Fix | Delete
[144] Fix | Delete
def concat(a, b):
[145] Fix | Delete
"Same as a + b, for a and b sequences."
[146] Fix | Delete
if not hasattr(a, '__getitem__'):
[147] Fix | Delete
msg = "'%s' object can't be concatenated" % type(a).__name__
[148] Fix | Delete
raise TypeError(msg)
[149] Fix | Delete
return a + b
[150] Fix | Delete
[151] Fix | Delete
def contains(a, b):
[152] Fix | Delete
"Same as b in a (note reversed operands)."
[153] Fix | Delete
return b in a
[154] Fix | Delete
[155] Fix | Delete
def countOf(a, b):
[156] Fix | Delete
"Return the number of times b occurs in a."
[157] Fix | Delete
count = 0
[158] Fix | Delete
for i in a:
[159] Fix | Delete
if i == b:
[160] Fix | Delete
count += 1
[161] Fix | Delete
return count
[162] Fix | Delete
[163] Fix | Delete
def delitem(a, b):
[164] Fix | Delete
"Same as del a[b]."
[165] Fix | Delete
del a[b]
[166] Fix | Delete
[167] Fix | Delete
def getitem(a, b):
[168] Fix | Delete
"Same as a[b]."
[169] Fix | Delete
return a[b]
[170] Fix | Delete
[171] Fix | Delete
def indexOf(a, b):
[172] Fix | Delete
"Return the first index of b in a."
[173] Fix | Delete
for i, j in enumerate(a):
[174] Fix | Delete
if j == b:
[175] Fix | Delete
return i
[176] Fix | Delete
else:
[177] Fix | Delete
raise ValueError('sequence.index(x): x not in sequence')
[178] Fix | Delete
[179] Fix | Delete
def setitem(a, b, c):
[180] Fix | Delete
"Same as a[b] = c."
[181] Fix | Delete
a[b] = c
[182] Fix | Delete
[183] Fix | Delete
def length_hint(obj, default=0):
[184] Fix | Delete
"""
[185] Fix | Delete
Return an estimate of the number of items in obj.
[186] Fix | Delete
This is useful for presizing containers when building from an iterable.
[187] Fix | Delete
[188] Fix | Delete
If the object supports len(), the result will be exact. Otherwise, it may
[189] Fix | Delete
over- or under-estimate by an arbitrary amount. The result will be an
[190] Fix | Delete
integer >= 0.
[191] Fix | Delete
"""
[192] Fix | Delete
if not isinstance(default, int):
[193] Fix | Delete
msg = ("'%s' object cannot be interpreted as an integer" %
[194] Fix | Delete
type(default).__name__)
[195] Fix | Delete
raise TypeError(msg)
[196] Fix | Delete
[197] Fix | Delete
try:
[198] Fix | Delete
return len(obj)
[199] Fix | Delete
except TypeError:
[200] Fix | Delete
pass
[201] Fix | Delete
[202] Fix | Delete
try:
[203] Fix | Delete
hint = type(obj).__length_hint__
[204] Fix | Delete
except AttributeError:
[205] Fix | Delete
return default
[206] Fix | Delete
[207] Fix | Delete
try:
[208] Fix | Delete
val = hint(obj)
[209] Fix | Delete
except TypeError:
[210] Fix | Delete
return default
[211] Fix | Delete
if val is NotImplemented:
[212] Fix | Delete
return default
[213] Fix | Delete
if not isinstance(val, int):
[214] Fix | Delete
msg = ('__length_hint__ must be integer, not %s' %
[215] Fix | Delete
type(val).__name__)
[216] Fix | Delete
raise TypeError(msg)
[217] Fix | Delete
if val < 0:
[218] Fix | Delete
msg = '__length_hint__() should return >= 0'
[219] Fix | Delete
raise ValueError(msg)
[220] Fix | Delete
return val
[221] Fix | Delete
[222] Fix | Delete
# Generalized Lookup Objects **************************************************#
[223] Fix | Delete
[224] Fix | Delete
class attrgetter:
[225] Fix | Delete
"""
[226] Fix | Delete
Return a callable object that fetches the given attribute(s) from its operand.
[227] Fix | Delete
After f = attrgetter('name'), the call f(r) returns r.name.
[228] Fix | Delete
After g = attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).
[229] Fix | Delete
After h = attrgetter('name.first', 'name.last'), the call h(r) returns
[230] Fix | Delete
(r.name.first, r.name.last).
[231] Fix | Delete
"""
[232] Fix | Delete
__slots__ = ('_attrs', '_call')
[233] Fix | Delete
[234] Fix | Delete
def __init__(self, attr, *attrs):
[235] Fix | Delete
if not attrs:
[236] Fix | Delete
if not isinstance(attr, str):
[237] Fix | Delete
raise TypeError('attribute name must be a string')
[238] Fix | Delete
self._attrs = (attr,)
[239] Fix | Delete
names = attr.split('.')
[240] Fix | Delete
def func(obj):
[241] Fix | Delete
for name in names:
[242] Fix | Delete
obj = getattr(obj, name)
[243] Fix | Delete
return obj
[244] Fix | Delete
self._call = func
[245] Fix | Delete
else:
[246] Fix | Delete
self._attrs = (attr,) + attrs
[247] Fix | Delete
getters = tuple(map(attrgetter, self._attrs))
[248] Fix | Delete
def func(obj):
[249] Fix | Delete
return tuple(getter(obj) for getter in getters)
[250] Fix | Delete
self._call = func
[251] Fix | Delete
[252] Fix | Delete
def __call__(self, obj):
[253] Fix | Delete
return self._call(obj)
[254] Fix | Delete
[255] Fix | Delete
def __repr__(self):
[256] Fix | Delete
return '%s.%s(%s)' % (self.__class__.__module__,
[257] Fix | Delete
self.__class__.__qualname__,
[258] Fix | Delete
', '.join(map(repr, self._attrs)))
[259] Fix | Delete
[260] Fix | Delete
def __reduce__(self):
[261] Fix | Delete
return self.__class__, self._attrs
[262] Fix | Delete
[263] Fix | Delete
class itemgetter:
[264] Fix | Delete
"""
[265] Fix | Delete
Return a callable object that fetches the given item(s) from its operand.
[266] Fix | Delete
After f = itemgetter(2), the call f(r) returns r[2].
[267] Fix | Delete
After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])
[268] Fix | Delete
"""
[269] Fix | Delete
__slots__ = ('_items', '_call')
[270] Fix | Delete
[271] Fix | Delete
def __init__(self, item, *items):
[272] Fix | Delete
if not items:
[273] Fix | Delete
self._items = (item,)
[274] Fix | Delete
def func(obj):
[275] Fix | Delete
return obj[item]
[276] Fix | Delete
self._call = func
[277] Fix | Delete
else:
[278] Fix | Delete
self._items = items = (item,) + items
[279] Fix | Delete
def func(obj):
[280] Fix | Delete
return tuple(obj[i] for i in items)
[281] Fix | Delete
self._call = func
[282] Fix | Delete
[283] Fix | Delete
def __call__(self, obj):
[284] Fix | Delete
return self._call(obj)
[285] Fix | Delete
[286] Fix | Delete
def __repr__(self):
[287] Fix | Delete
return '%s.%s(%s)' % (self.__class__.__module__,
[288] Fix | Delete
self.__class__.__name__,
[289] Fix | Delete
', '.join(map(repr, self._items)))
[290] Fix | Delete
[291] Fix | Delete
def __reduce__(self):
[292] Fix | Delete
return self.__class__, self._items
[293] Fix | Delete
[294] Fix | Delete
class methodcaller:
[295] Fix | Delete
"""
[296] Fix | Delete
Return a callable object that calls the given method on its operand.
[297] Fix | Delete
After f = methodcaller('name'), the call f(r) returns r.name().
[298] Fix | Delete
After g = methodcaller('name', 'date', foo=1), the call g(r) returns
[299] Fix | Delete
r.name('date', foo=1).
[300] Fix | Delete
"""
[301] Fix | Delete
__slots__ = ('_name', '_args', '_kwargs')
[302] Fix | Delete
[303] Fix | Delete
def __init__(self, name, /, *args, **kwargs):
[304] Fix | Delete
self._name = name
[305] Fix | Delete
if not isinstance(self._name, str):
[306] Fix | Delete
raise TypeError('method name must be a string')
[307] Fix | Delete
self._args = args
[308] Fix | Delete
self._kwargs = kwargs
[309] Fix | Delete
[310] Fix | Delete
def __call__(self, obj):
[311] Fix | Delete
return getattr(obj, self._name)(*self._args, **self._kwargs)
[312] Fix | Delete
[313] Fix | Delete
def __repr__(self):
[314] Fix | Delete
args = [repr(self._name)]
[315] Fix | Delete
args.extend(map(repr, self._args))
[316] Fix | Delete
args.extend('%s=%r' % (k, v) for k, v in self._kwargs.items())
[317] Fix | Delete
return '%s.%s(%s)' % (self.__class__.__module__,
[318] Fix | Delete
self.__class__.__name__,
[319] Fix | Delete
', '.join(args))
[320] Fix | Delete
[321] Fix | Delete
def __reduce__(self):
[322] Fix | Delete
if not self._kwargs:
[323] Fix | Delete
return self.__class__, (self._name,) + self._args
[324] Fix | Delete
else:
[325] Fix | Delete
from functools import partial
[326] Fix | Delete
return partial(self.__class__, self._name, **self._kwargs), self._args
[327] Fix | Delete
[328] Fix | Delete
[329] Fix | Delete
# In-place Operations *********************************************************#
[330] Fix | Delete
[331] Fix | Delete
def iadd(a, b):
[332] Fix | Delete
"Same as a += b."
[333] Fix | Delete
a += b
[334] Fix | Delete
return a
[335] Fix | Delete
[336] Fix | Delete
def iand(a, b):
[337] Fix | Delete
"Same as a &= b."
[338] Fix | Delete
a &= b
[339] Fix | Delete
return a
[340] Fix | Delete
[341] Fix | Delete
def iconcat(a, b):
[342] Fix | Delete
"Same as a += b, for a and b sequences."
[343] Fix | Delete
if not hasattr(a, '__getitem__'):
[344] Fix | Delete
msg = "'%s' object can't be concatenated" % type(a).__name__
[345] Fix | Delete
raise TypeError(msg)
[346] Fix | Delete
a += b
[347] Fix | Delete
return a
[348] Fix | Delete
[349] Fix | Delete
def ifloordiv(a, b):
[350] Fix | Delete
"Same as a //= b."
[351] Fix | Delete
a //= b
[352] Fix | Delete
return a
[353] Fix | Delete
[354] Fix | Delete
def ilshift(a, b):
[355] Fix | Delete
"Same as a <<= b."
[356] Fix | Delete
a <<= b
[357] Fix | Delete
return a
[358] Fix | Delete
[359] Fix | Delete
def imod(a, b):
[360] Fix | Delete
"Same as a %= b."
[361] Fix | Delete
a %= b
[362] Fix | Delete
return a
[363] Fix | Delete
[364] Fix | Delete
def imul(a, b):
[365] Fix | Delete
"Same as a *= b."
[366] Fix | Delete
a *= b
[367] Fix | Delete
return a
[368] Fix | Delete
[369] Fix | Delete
def imatmul(a, b):
[370] Fix | Delete
"Same as a @= b."
[371] Fix | Delete
a @= b
[372] Fix | Delete
return a
[373] Fix | Delete
[374] Fix | Delete
def ior(a, b):
[375] Fix | Delete
"Same as a |= b."
[376] Fix | Delete
a |= b
[377] Fix | Delete
return a
[378] Fix | Delete
[379] Fix | Delete
def ipow(a, b):
[380] Fix | Delete
"Same as a **= b."
[381] Fix | Delete
a **=b
[382] Fix | Delete
return a
[383] Fix | Delete
[384] Fix | Delete
def irshift(a, b):
[385] Fix | Delete
"Same as a >>= b."
[386] Fix | Delete
a >>= b
[387] Fix | Delete
return a
[388] Fix | Delete
[389] Fix | Delete
def isub(a, b):
[390] Fix | Delete
"Same as a -= b."
[391] Fix | Delete
a -= b
[392] Fix | Delete
return a
[393] Fix | Delete
[394] Fix | Delete
def itruediv(a, b):
[395] Fix | Delete
"Same as a /= b."
[396] Fix | Delete
a /= b
[397] Fix | Delete
return a
[398] Fix | Delete
[399] Fix | Delete
def ixor(a, b):
[400] Fix | Delete
"Same as a ^= b."
[401] Fix | Delete
a ^= b
[402] Fix | Delete
return a
[403] Fix | Delete
[404] Fix | Delete
[405] Fix | Delete
try:
[406] Fix | Delete
from _operator import *
[407] Fix | Delete
except ImportError:
[408] Fix | Delete
pass
[409] Fix | Delete
else:
[410] Fix | Delete
from _operator import __doc__
[411] Fix | Delete
[412] Fix | Delete
# All of these "__func__ = func" assignments have to happen after importing
[413] Fix | Delete
# from _operator to make sure they're set to the right function
[414] Fix | Delete
__lt__ = lt
[415] Fix | Delete
__le__ = le
[416] Fix | Delete
__eq__ = eq
[417] Fix | Delete
__ne__ = ne
[418] Fix | Delete
__ge__ = ge
[419] Fix | Delete
__gt__ = gt
[420] Fix | Delete
__not__ = not_
[421] Fix | Delete
__abs__ = abs
[422] Fix | Delete
__add__ = add
[423] Fix | Delete
__and__ = and_
[424] Fix | Delete
__floordiv__ = floordiv
[425] Fix | Delete
__index__ = index
[426] Fix | Delete
__inv__ = inv
[427] Fix | Delete
__invert__ = invert
[428] Fix | Delete
__lshift__ = lshift
[429] Fix | Delete
__mod__ = mod
[430] Fix | Delete
__mul__ = mul
[431] Fix | Delete
__matmul__ = matmul
[432] Fix | Delete
__neg__ = neg
[433] Fix | Delete
__or__ = or_
[434] Fix | Delete
__pos__ = pos
[435] Fix | Delete
__pow__ = pow
[436] Fix | Delete
__rshift__ = rshift
[437] Fix | Delete
__sub__ = sub
[438] Fix | Delete
__truediv__ = truediv
[439] Fix | Delete
__xor__ = xor
[440] Fix | Delete
__concat__ = concat
[441] Fix | Delete
__contains__ = contains
[442] Fix | Delete
__delitem__ = delitem
[443] Fix | Delete
__getitem__ = getitem
[444] Fix | Delete
__setitem__ = setitem
[445] Fix | Delete
__iadd__ = iadd
[446] Fix | Delete
__iand__ = iand
[447] Fix | Delete
__iconcat__ = iconcat
[448] Fix | Delete
__ifloordiv__ = ifloordiv
[449] Fix | Delete
__ilshift__ = ilshift
[450] Fix | Delete
__imod__ = imod
[451] Fix | Delete
__imul__ = imul
[452] Fix | Delete
__imatmul__ = imatmul
[453] Fix | Delete
__ior__ = ior
[454] Fix | Delete
__ipow__ = ipow
[455] Fix | Delete
__irshift__ = irshift
[456] Fix | Delete
__isub__ = isub
[457] Fix | Delete
__itruediv__ = itruediv
[458] Fix | Delete
__ixor__ = ixor
[459] Fix | Delete
[460] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function