本文整理匯總了Python中six.callable方法的典型用法代碼示例。如果您正苦於以下問題:Python six.callable方法的具體用法?Python six.callable怎麽用?Python six.callable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six
的用法示例。
在下文中一共展示了six.callable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def __init__(self, ps_tasks, ps_device, worker_device, merge_devices, ps_ops,
ps_strategy):
"""Create a new `_ReplicaDeviceChooser`.
Args:
ps_tasks: Number of tasks in the `ps` job.
ps_device: String. Name of the `ps` job.
worker_device: String. Name of the `worker` job.
merge_devices: Boolean. Set to True to allow merging of device specs.
ps_ops: List of strings representing `Operation` types that need to be
placed on `ps` devices.
ps_strategy: A callable invoked for every ps `Operation` (i.e. matched by
`ps_ops`), that takes the `Operation` and returns the ps task index to
use.
"""
self._ps_tasks = ps_tasks
self._ps_device = ps_device
self._worker_device = worker_device
self._merge_devices = merge_devices
self._ps_ops = ps_ops
self._ps_strategy = ps_strategy
示例2: to_sequence_field
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def to_sequence_field(cls):
"""
Returns a callable instance that will convert a value to a Sequence.
:param cls: Valid class type of the items in the Sequence.
:return: instance of the SequenceConverter.
"""
class SequenceConverter(object):
def __init__(self, cls):
self._cls = cls
@property
def cls(self):
return resolve_class(self._cls)
def __call__(self, values):
values = values or []
args = [to_model(self.cls, value) for value in values]
return TypedSequence(cls=self.cls, args=args)
return SequenceConverter(cls)
示例3: to_set_field
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def to_set_field(cls):
"""
Returns a callable instance that will convert a value to a Sequence.
:param cls: Valid class type of the items in the Sequence.
:return: instance of the SequenceConverter.
"""
class SetConverter(object):
def __init__(self, cls):
self._cls = cls
@property
def cls(self):
return resolve_class(self._cls)
def __call__(self, values):
values = values or set()
args = {to_model(self.cls, value) for value in values}
return TypedSet(cls=self.cls, args=args)
return SetConverter(cls)
示例4: to_date_field
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def to_date_field(formatter):
"""
Returns a callable instance that will convert a string to a Date.
:param formatter: String that represents data format for parsing.
:return: instance of the DateConverter.
"""
class DateConverter(object):
def __init__(self, formatter):
self.formatter = formatter
def __call__(self, value):
if isinstance(value, string_types):
value = datetime.strptime(value, self.formatter).date()
if isinstance(value, datetime):
value = value.date()
return value
return DateConverter(formatter)
示例5: to_time_field
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def to_time_field(formatter):
"""
Returns a callable instance that will convert a string to a Time.
:param formatter: String that represents data format for parsing.
:return: instance of the TimeConverter.
"""
class TimeConverter(object):
def __init__(self, formatter):
self.formatter = formatter
def __call__(self, value):
if isinstance(value, string_types):
value = datetime.strptime(value, self.formatter).time()
return value
return TimeConverter(formatter)
示例6: contains
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def contains(self, mouseevent):
"""Test whether the mouse event occured in the x axis.
"""
if six.callable(self._contains):
return self._contains(self, mouseevent)
x, y = mouseevent.x, mouseevent.y
try:
trans = self.axes.transAxes.inverted()
xaxes, yaxes = trans.transform_point((x, y))
except ValueError:
return False, {}
l, b = self.axes.transAxes.transform_point((0, 0))
r, t = self.axes.transAxes.transform_point((1, 1))
inaxis = xaxes >= 0 and xaxes <= 1 and (
(y < b and y > b - self.pickradius) or
(y > t and y < t + self.pickradius))
return inaxis, {}
示例7: wrap
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def wrap(self, fmt, func, level='helpful', always=True):
"""
return a callable function that wraps func and reports it
output through the verbose handler if current verbosity level
is higher than level
if always is True, the report will occur on every function
call; otherwise only on the first time the function is called
"""
assert six.callable(func)
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)
if (always or not wrapper._spoke):
spoke = self.report(fmt%ret, level)
if not wrapper._spoke: wrapper._spoke = spoke
return ret
wrapper._spoke = False
wrapper.__doc__ = func.__doc__
return wrapper
示例8: contains
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def contains(self, mouseevent, radius=None):
"""Test whether the mouse event occurred in the patch.
Returns T/F, {}
"""
# This is a general version of contains that should work on any
# patch with a path. However, patches that have a faster
# algebraic solution to hit-testing should override this
# method.
if six.callable(self._contains):
return self._contains(self, mouseevent)
if radius is None:
radius = self.get_linewidth()
inside = self.get_path().contains_point(
(mouseevent.x, mouseevent.y), self.get_transform(), radius)
return inside, {}
示例9: contains
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def contains(self, mouseevent):
"""Test whether the mouse event occurred in the table.
Returns T/F, {}
"""
if six.callable(self._contains):
return self._contains(self, mouseevent)
# TODO: Return index of the cell containing the cursor so that the user
# doesn't have to bind to each one individually.
if self._cachedRenderer is not None:
boxes = [self._cells[pos].get_window_extent(self._cachedRenderer)
for pos in six.iterkeys(self._cells)
if pos[0] >= 0 and pos[1] >= 0]
bbox = Bbox.union(boxes)
return bbox.contains(mouseevent.x, mouseevent.y), {}
else:
return False, {}
示例10: contains
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def contains(self, mouseevent):
"""
Test whether the mouse event occured within the image.
"""
if six.callable(self._contains):
return self._contains(self, mouseevent)
# TODO: make sure this is consistent with patch and patch
# collection on nonlinear transformed coordinates.
# TODO: consider returning image coordinates (shouldn't
# be too difficult given that the image is rectilinear
x, y = mouseevent.xdata, mouseevent.ydata
xmin, xmax, ymin, ymax = self.get_extent()
if xmin > xmax:
xmin, xmax = xmax, xmin
if ymin > ymax:
ymin, ymax = ymax, ymin
#print x, y, xmin, xmax, ymin, ymax
if x is not None and y is not None:
inside = ((x >= xmin) and (x <= xmax) and
(y >= ymin) and (y <= ymax))
else:
inside = False
return inside, {}
示例11: __call__
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def __call__(self, *args, **kwargs):
'''
Proxy for a call to the weak referenced object. Take
arbitrary params to pass to the callable.
Raises `ReferenceError`: When the weak reference refers to
a dead object
'''
if self.inst is not None and self.inst() is None:
raise ReferenceError
elif self.inst is not None:
# build a new instance method with a strong reference to the
# instance
mtd = types.MethodType(self.func, self.inst())
else:
# not a bound method, just return the func
mtd = self.func
# invoke the callable and return the result
return mtd(*args, **kwargs)
示例12: update
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def update(self, props):
"""
Update the properties of this :class:`Artist` from the
dictionary *prop*.
"""
store = self.eventson
self.eventson = False
changed = False
for k, v in six.iteritems(props):
func = getattr(self, 'set_' + k, None)
if func is None or not six.callable(func):
raise AttributeError('Unknown property %s' % k)
func(v)
changed = True
self.eventson = store
if changed:
self.pchanged()
示例13: get_aliases
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def get_aliases(self):
"""
Get a dict mapping *fullname* -> *alias* for each *alias* in
the :class:`~matplotlib.artist.ArtistInspector`.
e.g., for lines::
{'markerfacecolor': 'mfc',
'linewidth' : 'lw',
}
"""
names = [name for name in dir(self.o) if
(name.startswith('set_') or name.startswith('get_'))
and six.callable(getattr(self.o, name))]
aliases = {}
for name in names:
func = getattr(self.o, name)
if not self.is_alias(func):
continue
docstring = func.__doc__
fullname = docstring[10:]
aliases.setdefault(fullname[4:], {})[name[4:]] = None
return aliases
示例14: _get_setters_and_targets
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def _get_setters_and_targets(self):
"""
Get the attribute strings and a full path to where the setter
is defined for all setters in an object.
"""
setters = []
for name in dir(self.o):
if not name.startswith('set_'):
continue
o = getattr(self.o, name)
if not six.callable(o):
continue
if len(inspect.getargspec(o)[0]) < 2:
continue
func = o
if self.is_alias(func):
continue
source_class = self.o.__module__ + "." + self.o.__name__
for cls in self.o.mro():
if name in cls.__dict__:
source_class = cls.__module__ + "." + cls.__name__
break
setters.append((name[4:], source_class + "." + name))
return setters
示例15: properties
# 需要導入模塊: import six [as 別名]
# 或者: from six import callable [as 別名]
def properties(self):
"""
return a dictionary mapping property name -> value
"""
o = self.oorig
getters = [name for name in dir(o)
if name.startswith('get_')
and six.callable(getattr(o, name))]
#print getters
getters.sort()
d = dict()
for name in getters:
func = getattr(o, name)
if self.is_alias(func):
continue
try:
val = func()
except:
continue
else:
d[name[4:]] = val
return d