本文整理汇总了Python中django.utils.inspect.func_supports_parameter方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.func_supports_parameter方法的具体用法?Python inspect.func_supports_parameter怎么用?Python inspect.func_supports_parameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.inspect
的用法示例。
在下文中一共展示了inspect.func_supports_parameter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_converters
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def get_converters(self, expressions):
converters = {}
for i, expression in enumerate(expressions):
if expression:
backend_converters = self.connection.ops.get_db_converters(expression)
field_converters = expression.get_db_converters(self.connection)
if backend_converters or field_converters:
convs = []
for conv in (backend_converters + field_converters):
if func_supports_parameter(conv, 'context'):
warnings.warn(
'Remove the context parameter from %s.%s(). Support for it '
'will be removed in Django 3.0.' % (
conv.__self__.__class__.__name__,
conv.__name__,
),
RemovedInDjango30Warning,
)
conv = functools.partial(conv, context={})
convs.append(conv)
converters[i] = (convs, expression)
return converters
示例2: get_encrypted_value
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def get_encrypted_value(self, value: FieldFile, encryption_key: str):
file_name = value.name
value.delete(save=False)
file = self.get_replacement_file()
if func_supports_parameter(value.storage.save, 'max_length'):
value.name = value.storage.save(file_name, file, max_length=value.field.max_length)
else:
# Backwards compatibility removed in Django 1.10
value.name = value.storage.save(file_name, file)
setattr(value.instance, value.field.name, value.name)
value._size = file.size # Django 1.8 + 1.9
value._committed = True
file.close()
return value
示例3: save
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def save(self, name, content, save=True):
name = self.field.generate_filename(self.instance, name)
if func_supports_parameter(self.storage.save, 'max_length'):
self.name = self.storage.save(name, content, max_length=self.field.max_length)
else:
warnings.warn(
'Backwards compatibility for storage backends without '
'support for the `max_length` argument in '
'Storage.save() will be removed in Django 1.10.',
RemovedInDjango110Warning, stacklevel=2
)
self.name = self.storage.save(name, content)
setattr(self.instance, self.field.name, self.name)
# Update the filesize cache
self._size = content.size
self._committed = True
# Save the object because it has changed, unless save is False
if save:
self.instance.save()
示例4: _get_connection
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def _get_connection(self):
"""
Returns our cached LDAPObject, which may or may not be bound.
"""
if self._connection is None:
uri = self.settings.SERVER_URI
if callable(uri):
if func_supports_parameter(uri, "request"):
uri = uri(self._request)
else:
warnings.warn(
"Update AUTH_LDAP_SERVER_URI callable %s.%s to accept "
"a positional `request` argument. Support for callables "
"accepting no arguments will be removed in a future "
"version." % (uri.__module__, uri.__name__),
DeprecationWarning,
)
uri = uri()
self._connection = self.backend.ldap.initialize(uri, bytes_mode=False)
for opt, value in self.settings.CONNECTION_OPTIONS.items():
self._connection.set_option(opt, value)
if self.settings.START_TLS:
logger.debug("Initiating TLS")
self._connection.start_tls_s()
return self._connection
示例5: as_widget
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [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
)
示例6: _from_db_value
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def _from_db_value(self, value, expression, connection):
if value is None:
return value
return [
self.base_field.from_db_value(item, expression, connection, {})
if func_supports_parameter(self.base_field.from_db_value, 'context') # RemovedInDjango30Warning
else self.base_field.from_db_value(item, expression, connection)
for item in value
]
示例7: get_template_sources
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def get_template_sources(self, template_name, template_dirs=None):
for loader in self.loaders:
args = [template_name]
# RemovedInDjango20Warning: Add template_dirs for compatibility
# with old loaders
if func_supports_parameter(loader.get_template_sources, 'template_dirs'):
args.append(template_dirs)
for origin in loader.get_template_sources(*args):
yield origin
示例8: get_template
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [as 别名]
def get_template(self, template_name, template_dirs=None, skip=None):
"""
Calls self.get_template_sources() and returns a Template object for
the first template matching template_name. If skip is provided,
template origins in skip are ignored. This is used to avoid recursion
during template extending.
"""
tried = []
args = [template_name]
# RemovedInDjango20Warning: Add template_dirs for compatibility with
# old loaders
if func_supports_parameter(self.get_template_sources, 'template_dirs'):
args.append(template_dirs)
for origin in self.get_template_sources(*args):
if skip is not None and origin in skip:
tried.append((origin, 'Skipped'))
continue
try:
contents = self.get_contents(origin)
except TemplateDoesNotExist:
tried.append((origin, 'Source does not exist'))
continue
else:
return Template(
contents, origin, origin.template_name, self.engine,
)
raise TemplateDoesNotExist(template_name, tried=tried)
示例9: as_widget
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import func_supports_parameter [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)