当前位置: 首页>>代码示例>>Python>>正文


Python inspect.get_func_args方法代码示例

本文整理汇总了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
                ) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:15,代码来源:checks.py

示例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) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:6,代码来源:options.py

示例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' 
开发者ID:drexly,项目名称:openhgsenti,代码行数:39,代码来源:ogrinspect.py

示例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__) 
开发者ID:alorence,项目名称:django-modern-rpc,代码行数:36,代码来源:core.py


注:本文中的django.utils.inspect.get_func_args方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。