本文整理汇总了Python中django.utils.inspect.get_func_args方法的典型用法代码示例。如果您正苦于以下问题:Python inspect.get_func_args方法的具体用法?Python inspect.get_func_args怎么用?Python inspect.get_func_args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.inspect
的用法示例。
在下文中一共展示了inspect.get_func_args方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_has_add_permission
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import get_func_args [as 别名]
def _check_has_add_permission(self, obj):
cls = obj.__class__
try:
func = cls.has_add_permission
except AttributeError:
pass
else:
args = get_func_args(func)
if 'obj' not in args:
warnings.warn(
"Update %s.has_add_permission() to accept a positional "
"`obj` argument." % cls.__name__, RemovedInDjango30Warning
)
示例2: _has_add_permission
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import get_func_args [as 别名]
def _has_add_permission(self, request, obj):
# RemovedInDjango30Warning: obj will be a required argument.
args = get_func_args(self.has_add_permission)
return self.has_add_permission(request, obj) if 'obj' in args else self.has_add_permission(request)
示例3: handle
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import get_func_args [as 别名]
def handle(self, *args, **options):
data_source, model_name = options.pop('data_source'), options.pop('model_name')
if not gdal.HAS_GDAL:
raise CommandError('GDAL is required to inspect geospatial data sources.')
# Getting the OGR DataSource from the string parameter.
try:
ds = gdal.DataSource(data_source)
except gdal.GDALException as msg:
raise CommandError(msg)
# Returning the output of ogrinspect with the given arguments
# and options.
from django.contrib.gis.utils.ogrinspect import _ogrinspect, mapping
# Filter options to params accepted by `_ogrinspect`
ogr_options = {k: v for k, v in options.items()
if k in get_func_args(_ogrinspect) and v is not None}
output = [s for s in _ogrinspect(ds, model_name, **ogr_options)]
if options['mapping']:
# Constructing the keyword arguments for `mapping`, and
# calling it on the data source.
kwargs = {'geom_name': options['geom_name'],
'layer_key': options['layer_key'],
'multi_geom': options['multi_geom'],
}
mapping_dict = mapping(ds, **kwargs)
# This extra legwork is so that the dictionary definition comes
# out in the same order as the fields in the model definition.
rev_mapping = {v: k for k, v in mapping_dict.items()}
output.extend(['', '# Auto-generated `LayerMapping` dictionary for %s model' % model_name,
'%s_mapping = {' % model_name.lower()])
output.extend(" '%s' : '%s'," % (
rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields
)
output.extend([" '%s' : '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}'])
return '\n'.join(output) + '\n'
示例4: __init__
# 需要导入模块: from django.utils import inspect [as 别名]
# 或者: from django.utils.inspect import get_func_args [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__)