本文整理汇总了Python中django.utils.inspect.func_accepts_kwargs方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.func_accepts_kwargs方法的具体用法?Python inspect.func_accepts_kwargs怎么用?Python inspect.func_accepts_kwargs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.inspect
的用法示例。
在下文中一共展示了inspect.func_accepts_kwargs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: as_widget
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_accepts_kwargs [as 别名]
def as_widget(self, widget=None, attrs=None, only_initial=False):
"""
Render the field by rendering the passed widget, adding any HTML
attributes passed as attrs. If a widget isn't specified, use the
field's default widget.
"""
if not widget:
widget = self.field.widget
if self.field.localize:
widget.is_localized = True
attrs = attrs or {}
attrs = self.build_widget_attrs(attrs, widget)
auto_id = self.auto_id
if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
if not only_initial:
attrs['id'] = auto_id
else:
attrs['id'] = self.html_initial_id
if not only_initial:
name = self.html_name
else:
name = self.html_initial_name
kwargs = {}
if func_supports_parameter(widget.render, 'renderer') or func_accepts_kwargs(widget.render):
kwargs['renderer'] = self.form.renderer
else:
warnings.warn(
'Add the `renderer` argument to the render() method of %s. '
'It will be mandatory in Django 2.1.' % widget.__class__,
RemovedInDjango21Warning, stacklevel=2,
)
return widget.render(
name=name,
value=self.value(),
attrs=attrs,
**kwargs
)
示例2: __init__
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_accepts_kwargs [as 别名]
def __init__(self, func):
# Store the reference to the registered function
self.function = func
# @rpc_method decorator parameters
self._external_name = getattr(func, 'modernrpc_name', func.__name__)
self.entry_point = getattr(func, 'modernrpc_entry_point')
self.protocol = getattr(func, 'modernrpc_protocol')
self.str_standardization = getattr(func, 'str_standardization')
self.str_std_encoding = getattr(func, 'str_standardization_encoding')
# Authentication related attributes
self.predicates = getattr(func, 'modernrpc_auth_predicates', None)
self.predicates_params = getattr(func, 'modernrpc_auth_predicates_params', ())
# List method's positional arguments
# We can't use django.utils.inspect.get_func_args() with Python 2, because this function remove the first
# argument in returned list. This is supposed to remove the first 'self' argument, but doesn't fork well
# for global functions.
# For Python 2, we will prefer django.utils.inspect.getargspec(func)[0]. This will work as expected, even if
# the function has been removed in Django 2.0, since Django 2 doesn't work with Python 2
self.args = get_func_args(func) if six.PY3 else getargspec(func)[0]
# Does the method accept additional kwargs dict?
self.accept_kwargs = func_accepts_kwargs(func)
# Contains the signature of the method, as returned by "system.methodSignature"
self.signature = []
# Contains doc about arguments and their type. We store this in an ordered dict, so the args documentation
# keep the order defined in docstring
self.args_doc = collections.OrderedDict()
# Contains doc about return type and return value
self.return_doc = {}
# Docstring parsing. This will initialize self.signature, self.args_doc and self.return_doc
self.raw_docstring = self.parse_docstring(self.function.__doc__)
示例3: as_widget
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_accepts_kwargs [as 别名]
def as_widget(self, widget=None, attrs=None, only_initial=False):
"""
Renders the field by rendering the passed widget, adding any HTML
attributes passed as attrs. If no widget is specified, then the
field's default widget will be used.
"""
if not widget:
widget = self.field.widget
if self.field.localize:
widget.is_localized = True
attrs = attrs or {}
attrs = self.build_widget_attrs(attrs, widget)
auto_id = self.auto_id
if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
if not only_initial:
attrs['id'] = auto_id
else:
attrs['id'] = self.html_initial_id
if not only_initial:
name = self.html_name
else:
name = self.html_initial_name
kwargs = {}
if func_supports_parameter(widget.render, 'renderer') or func_accepts_kwargs(widget.render):
kwargs['renderer'] = self.form.renderer
else:
warnings.warn(
'Add the `renderer` argument to the render() method of %s. '
'It will be mandatory in Django 2.1.' % widget.__class__,
RemovedInDjango21Warning, stacklevel=2,
)
html = widget.render(
name=name,
value=self.value(),
attrs=attrs,
**kwargs
)
return force_text(html)