python类getcallargs()的实例源码

__init__.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            return None
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))
edit.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 182 收藏 0 点赞 0 评论 0
def __new__(cls, name, bases, attrs):
        get_form = attrs.get('get_form')
        if get_form and inspect.isfunction(get_form):
            try:
                inspect.getcallargs(get_form, None)
            except TypeError:
                warnings.warn(
                    "`%s.%s.get_form` method must define a default value for "
                    "its `form_class` argument." % (attrs['__module__'], name),
                    RemovedInDjango110Warning, stacklevel=2
                )

                def get_form_with_form_class(self, form_class=None):
                    if form_class is None:
                        form_class = self.get_form_class()
                    return get_form(self, form_class=form_class)
                attrs['get_form'] = get_form_with_form_class
        return super(FormMixinBase, cls).__new__(cls, name, bases, attrs)
__init__.py 文件源码 项目:CSCE482-WordcloudPlus 作者: ggaytan00 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            break
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__, credentials=_clean_credentials(credentials))
test_inspect.py 文件源码 项目:kbe_server 作者: xiaohaoppy 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def assertEqualException(self, func, call_param_string, locs=None):
        locs = dict(locs or {}, func=func)
        try:
            eval('func(%s)' % call_param_string, None, locs)
        except Exception as e:
            ex1 = e
        else:
            self.fail('Exception not raised')
        try:
            eval('inspect.getcallargs(func, %s)' % call_param_string, None,
                 locs)
        except Exception as e:
            ex2 = e
        else:
            self.fail('Exception not raised')
        self.assertIs(type(ex1), type(ex2))
        self.assertEqual(str(ex1), str(ex2))
        del ex1, ex2
__init__.py 文件源码 项目:producthunt 作者: davidgengler 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            break
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__, credentials=_clean_credentials(credentials))
api_base.py 文件源码 项目:rqalpha 作者: ricequant 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def api_exc_patch(func):
    if isinstance(func, FunctionType):
        @wraps(func)
        def deco(*args, **kwargs):
            try:
                return func(*args, **kwargs)
            except RQInvalidArgument:
                raise
            except Exception as e:
                if isinstance(e, TypeError):
                    exc_info = sys.exc_info()
                    try:
                        ret = inspect.getcallargs(unwrapper(func), *args, **kwargs)
                    except TypeError:
                        t, v, tb = exc_info
                        raise patch_user_exc(v.with_traceback(tb))

                if getattr(e, EXC_EXT_NAME, EXC_TYPE.NOTSET) == EXC_TYPE.NOTSET:
                    patch_system_exc(e)

                raise

        return deco
    return func
__init__.py 文件源码 项目:geekpoint 作者: Lujinghu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            return None
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))
__init__.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            return None
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))
edit.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def __new__(cls, name, bases, attrs):
        get_form = attrs.get('get_form')
        if get_form and inspect.isfunction(get_form):
            try:
                inspect.getcallargs(get_form, None)
            except TypeError:
                warnings.warn(
                    "`%s.%s.get_form` method must define a default value for "
                    "its `form_class` argument." % (attrs['__module__'], name),
                    RemovedInDjango110Warning, stacklevel=2
                )

                def get_form_with_form_class(self, form_class=None):
                    if form_class is None:
                        form_class = self.get_form_class()
                    return get_form(self, form_class=form_class)
                attrs['get_form'] = get_form_with_form_class
        return super(FormMixinBase, cls).__new__(cls, name, bases, attrs)
__init__.py 文件源码 项目:watcher 作者: nosmokingbandit 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def is_closable_iterator(obj):

    # Not an iterator.
    if not is_iterator(obj):
        return False

    # A generator - the easiest thing to deal with.
    import inspect
    if inspect.isgenerator(obj):
        return True

    # A custom iterator. Look for a close method...
    if not (hasattr(obj, 'close') and callable(obj.close)):
        return False

    #  ... which doesn't require any arguments.
    try:
        inspect.getcallargs(obj.close)
    except TypeError:
        return False
    else:
        return True
__init__.py 文件源码 项目:DjangoZeroToHero 作者: RayParra 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            return None
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))
__init__.py 文件源码 项目:Roboism 作者: markroxor 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            return None
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))
manager.py 文件源码 项目:Trusted-Platform-Module-nova 作者: BU-NU-CLOUD-SP16 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def wrap_instance_event(function):
    """Wraps a method to log the event taken on the instance, and result.

    This decorator wraps a method to log the start and result of an event, as
    part of an action taken on an instance.
    """

    @functools.wraps(function)
    def decorated_function(self, context, *args, **kwargs):
        wrapped_func = safe_utils.get_wrapped_function(function)
        keyed_args = inspect.getcallargs(wrapped_func, self, context, *args,
                                         **kwargs)
        instance_uuid = keyed_args['instance']['uuid']

        event_name = 'compute_{0}'.format(function.__name__)
        with compute_utils.EventReporter(context, event_name, instance_uuid):
            return function(self, context, *args, **kwargs)

    return decorated_function
validators.py 文件源码 项目:packetary 作者: openstack 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def declare_schema(**schemas):
    """Declares data schema for function arguments.

    :param schemas: the mapping, where key is argument name, value is schema
                    the schema may be callable object or method of class
                    in this case the wrapped function should be method of
                    same class
    :raises ValueError: if the passed data does not fit declared schema
    """

    def decorator(func):
        validators = {k: _build_validator(v) for k, v in schemas.items()}
        defaults = _get_default_arguments(func)

        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            bound_args = inspect.getcallargs(func, *args, **kwargs)
            for n, v in bound_args.items():
                if v is not defaults.get(n, _SENTINEL) and n in validators:
                    validators[n](args and args[0] or None, v)
            return func(*args, **kwargs)
        return wrapper
    return decorator
__init__.py 文件源码 项目:django-wechat-api 作者: crazy-canux 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def authenticate(**credentials):
    """
    If the given credentials are valid, return a User object.
    """
    for backend, backend_path in _get_backends(return_tuples=True):
        try:
            inspect.getcallargs(backend.authenticate, **credentials)
        except TypeError:
            # This backend doesn't accept these credentials as arguments. Try the next one.
            continue

        try:
            user = backend.authenticate(**credentials)
        except PermissionDenied:
            # This backend says to stop in our tracks - this user should not be allowed in at all.
            return None
        if user is None:
            continue
        # Annotate the user object with the path of the backend.
        user.backend = backend_path
        return user

    # The credentials supplied are invalid to all backends, fire signal
    user_login_failed.send(sender=__name__,
            credentials=_clean_credentials(credentials))
edit.py 文件源码 项目:django-wechat-api 作者: crazy-canux 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __new__(cls, name, bases, attrs):
        get_form = attrs.get('get_form')
        if get_form and inspect.isfunction(get_form):
            try:
                inspect.getcallargs(get_form, None)
            except TypeError:
                warnings.warn(
                    "`%s.%s.get_form` method must define a default value for "
                    "its `form_class` argument." % (attrs['__module__'], name),
                    RemovedInDjango20Warning, stacklevel=2
                )

                def get_form_with_form_class(self, form_class=None):
                    if form_class is None:
                        form_class = self.get_form_class()
                    return get_form(self, form_class=form_class)
                attrs['get_form'] = get_form_with_form_class
        return super(FormMixinBase, cls).__new__(cls, name, bases, attrs)
quickcache_helper.py 文件源码 项目:quickcache 作者: dimagi 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def skip(self, *args, **kwargs):
        if not self.skip_arg:
            return False
        elif isinstance(self.skip_arg, six.string_types):
            callargs = inspect.getcallargs(self.fn, *args, **kwargs)
            return callargs[self.skip_arg]
        elif isfunction(self.skip_arg):
            return self.skip_arg(*args, **kwargs)
        else:
            assert False, "skip_arg must be None, a string, or a function " \
                          "and this should have been checked in __init__"
arg_validator.py 文件源码 项目:beproudbot 作者: beproud 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def register_arg_validator(cls, extras=[]):
    """?????????????

    .. note::
      - ???????????????????????
      - ?????????????????????????
        ????????????

    :param BaesArgValidator cls: ?????????
    """
    assert issubclass(cls, BaseArgValidator)

    def _inner(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            callargs = getcallargs(func, *args, **kwargs)

            validator = cls(callargs, extras)

            if not validator.is_valid():
                validator.handle_errors()
                return

            # XXX ???????????????????????????
            return func(**validator.cleaned_data)

        return wrapper

    return _inner
__init__.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _authenticate_with_backend(backend, backend_path, request, credentials):
    args = (request,)
    # Does the backend accept a request argument?
    try:
        inspect.getcallargs(backend.authenticate, request, **credentials)
    except TypeError:
        args = ()
        credentials.pop('request', None)
        # Does the backend accept a request keyword argument?
        try:
            inspect.getcallargs(backend.authenticate, request=request, **credentials)
        except TypeError:
            # Does the backend accept credentials without request?
            try:
                inspect.getcallargs(backend.authenticate, **credentials)
            except TypeError:
                # This backend doesn't accept these credentials as arguments. Try the next one.
                return None
            else:
                warnings.warn(
                    "Update %s.authenticate() to accept a positional "
                    "`request` argument." % backend_path,
                    RemovedInDjango21Warning
                )
        else:
            credentials['request'] = request
            warnings.warn(
                "In %s.authenticate(), move the `request` keyword argument "
                "to the first positional argument." % backend_path,
                RemovedInDjango21Warning
            )
    return backend.authenticate(*args, **credentials)
exception.py 文件源码 项目:zun 作者: openstack 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def wrap_exception(notifier=None, event_type=None):
    """This decorator wraps a method to catch any exceptions.

    It logs the exception as well as optionally sending
    it to the notification system.
    """
    def inner(f):
        def wrapped(self, context, *args, **kwargs):
            # Don't store self or context in the payload, it now seems to
            # contain confidential information.
            try:
                return f(self, context, *args, **kwargs)
            except Exception as e:
                with excutils.save_and_reraise_exception():
                    if notifier:
                        call_dict = inspect.getcallargs(f, self, context,
                                                        *args, **kwargs)
                        payload = dict(exception=e,
                                       private=dict(args=call_dict)
                                       )

                        temp_type = event_type
                        if not temp_type:
                            # If f has multiple decorators, they must use
                            # functools.wraps to ensure the name is
                            # propagated.
                            temp_type = f.__name__

                        notifier.error(context, temp_type, payload)

        return functools.wraps(f)(wrapped)
    return inner


问题


面经


文章

微信
公众号

扫码关注公众号