Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: functools.py
"""functools.py - Tools for working with functions and callable objects
[0] Fix | Delete
"""
[1] Fix | Delete
# Python module wrapper for _functools C module
[2] Fix | Delete
# to allow utilities written in Python to be added
[3] Fix | Delete
# to the functools module.
[4] Fix | Delete
# Written by Nick Coghlan <ncoghlan at gmail.com>
[5] Fix | Delete
# Copyright (C) 2006 Python Software Foundation.
[6] Fix | Delete
# See C source code for _functools credits/copyright
[7] Fix | Delete
[8] Fix | Delete
from _functools import partial, reduce
[9] Fix | Delete
[10] Fix | Delete
# update_wrapper() and wraps() are tools to help write
[11] Fix | Delete
# wrapper functions that can handle naive introspection
[12] Fix | Delete
[13] Fix | Delete
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
[14] Fix | Delete
WRAPPER_UPDATES = ('__dict__',)
[15] Fix | Delete
def update_wrapper(wrapper,
[16] Fix | Delete
wrapped,
[17] Fix | Delete
assigned = WRAPPER_ASSIGNMENTS,
[18] Fix | Delete
updated = WRAPPER_UPDATES):
[19] Fix | Delete
"""Update a wrapper function to look like the wrapped function
[20] Fix | Delete
[21] Fix | Delete
wrapper is the function to be updated
[22] Fix | Delete
wrapped is the original function
[23] Fix | Delete
assigned is a tuple naming the attributes assigned directly
[24] Fix | Delete
from the wrapped function to the wrapper function (defaults to
[25] Fix | Delete
functools.WRAPPER_ASSIGNMENTS)
[26] Fix | Delete
updated is a tuple naming the attributes of the wrapper that
[27] Fix | Delete
are updated with the corresponding attribute from the wrapped
[28] Fix | Delete
function (defaults to functools.WRAPPER_UPDATES)
[29] Fix | Delete
"""
[30] Fix | Delete
for attr in assigned:
[31] Fix | Delete
setattr(wrapper, attr, getattr(wrapped, attr))
[32] Fix | Delete
for attr in updated:
[33] Fix | Delete
getattr(wrapper, attr).update(getattr(wrapped, attr, {}))
[34] Fix | Delete
# Return the wrapper so this can be used as a decorator via partial()
[35] Fix | Delete
return wrapper
[36] Fix | Delete
[37] Fix | Delete
def wraps(wrapped,
[38] Fix | Delete
assigned = WRAPPER_ASSIGNMENTS,
[39] Fix | Delete
updated = WRAPPER_UPDATES):
[40] Fix | Delete
"""Decorator factory to apply update_wrapper() to a wrapper function
[41] Fix | Delete
[42] Fix | Delete
Returns a decorator that invokes update_wrapper() with the decorated
[43] Fix | Delete
function as the wrapper argument and the arguments to wraps() as the
[44] Fix | Delete
remaining arguments. Default arguments are as for update_wrapper().
[45] Fix | Delete
This is a convenience function to simplify applying partial() to
[46] Fix | Delete
update_wrapper().
[47] Fix | Delete
"""
[48] Fix | Delete
return partial(update_wrapper, wrapped=wrapped,
[49] Fix | Delete
assigned=assigned, updated=updated)
[50] Fix | Delete
[51] Fix | Delete
def total_ordering(cls):
[52] Fix | Delete
"""Class decorator that fills in missing ordering methods"""
[53] Fix | Delete
convert = {
[54] Fix | Delete
'__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
[55] Fix | Delete
('__le__', lambda self, other: self < other or self == other),
[56] Fix | Delete
('__ne__', lambda self, other: not self == other),
[57] Fix | Delete
('__ge__', lambda self, other: not self < other)],
[58] Fix | Delete
'__le__': [('__ge__', lambda self, other: not self <= other or self == other),
[59] Fix | Delete
('__lt__', lambda self, other: self <= other and not self == other),
[60] Fix | Delete
('__ne__', lambda self, other: not self == other),
[61] Fix | Delete
('__gt__', lambda self, other: not self <= other)],
[62] Fix | Delete
'__gt__': [('__lt__', lambda self, other: not (self > other or self == other)),
[63] Fix | Delete
('__ge__', lambda self, other: self > other or self == other),
[64] Fix | Delete
('__ne__', lambda self, other: not self == other),
[65] Fix | Delete
('__le__', lambda self, other: not self > other)],
[66] Fix | Delete
'__ge__': [('__le__', lambda self, other: (not self >= other) or self == other),
[67] Fix | Delete
('__gt__', lambda self, other: self >= other and not self == other),
[68] Fix | Delete
('__ne__', lambda self, other: not self == other),
[69] Fix | Delete
('__lt__', lambda self, other: not self >= other)]
[70] Fix | Delete
}
[71] Fix | Delete
defined_methods = set(dir(cls))
[72] Fix | Delete
roots = defined_methods & set(convert)
[73] Fix | Delete
if not roots:
[74] Fix | Delete
raise ValueError('must define at least one ordering operation: < > <= >=')
[75] Fix | Delete
root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__
[76] Fix | Delete
for opname, opfunc in convert[root]:
[77] Fix | Delete
if opname not in defined_methods:
[78] Fix | Delete
opfunc.__name__ = opname
[79] Fix | Delete
opfunc.__doc__ = getattr(int, opname).__doc__
[80] Fix | Delete
setattr(cls, opname, opfunc)
[81] Fix | Delete
return cls
[82] Fix | Delete
[83] Fix | Delete
def cmp_to_key(mycmp):
[84] Fix | Delete
"""Convert a cmp= function into a key= function"""
[85] Fix | Delete
class K(object):
[86] Fix | Delete
__slots__ = ['obj']
[87] Fix | Delete
def __init__(self, obj, *args):
[88] Fix | Delete
self.obj = obj
[89] Fix | Delete
def __lt__(self, other):
[90] Fix | Delete
return mycmp(self.obj, other.obj) < 0
[91] Fix | Delete
def __gt__(self, other):
[92] Fix | Delete
return mycmp(self.obj, other.obj) > 0
[93] Fix | Delete
def __eq__(self, other):
[94] Fix | Delete
return mycmp(self.obj, other.obj) == 0
[95] Fix | Delete
def __le__(self, other):
[96] Fix | Delete
return mycmp(self.obj, other.obj) <= 0
[97] Fix | Delete
def __ge__(self, other):
[98] Fix | Delete
return mycmp(self.obj, other.obj) >= 0
[99] Fix | Delete
def __ne__(self, other):
[100] Fix | Delete
return mycmp(self.obj, other.obj) != 0
[101] Fix | Delete
def __hash__(self):
[102] Fix | Delete
raise TypeError('hash not implemented')
[103] Fix | Delete
return K
[104] Fix | Delete
[105] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function