本文整理匯總了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)