(self, receiver, *args, convert_args=True, convert_result=True)
return result
Call the method on an object with the given arguments.

        The passed arguments are automatically converted to the expected argument types as needed:

        * :class:`enum.Enum` objects are replaced by their :attr:`~enum.Enum.value` before further conversion
        * For parameters that expect a block, Python callables are converted to :class:`Block`\\s
        * For parameters that expect an Objective-C object, Python objects are converted using :func:`ns_from_py`
        * For parameters that expect a C structure, Python sequences are converted
          using :func:`~rubicon.objc.types.compound_value_for_sequence`.
        * Finally, :mod:`ctypes` applies its normal function argument conversions.

        The above argument conversions (except those performed by :mod:`ctypes`) can be disabled
        by setting the ``convert_args`` keyword argument to ``False``.

        If the method returns an Objective-C object, it is automatically converted to an :class:`ObjCInstance`.
        This conversion can be disabled by setting the ``convert_result`` keyword argument to ``False``,
        in which case the object is returned as a raw :class:`~rubicon.objc.runtime.objc_id` value.

        The ``_cmd`` selector argument does *not* need to be passed in manually ---
        the method's :attr:`selector` is automatically added between the receiver and the method arguments.
Call the method on an object with the given arguments.
Call the method on an object with the given arguments .
def __call__(self, receiver, *args, convert_args=True, convert_result=True):
        """Call the method on an object with the given arguments.

        The passed arguments are automatically converted to the expected argument types as needed:

        * :class:`enum.Enum` objects are replaced by their :attr:`~enum.Enum.value` before further conversion
        * For parameters that expect a block, Python callables are converted to :class:`Block`\\s
        * For parameters that expect an Objective-C object, Python objects are converted using :func:`ns_from_py`
        * For parameters that expect a C structure, Python sequences are converted
          using :func:`~rubicon.objc.types.compound_value_for_sequence`.
        * Finally, :mod:`ctypes` applies its normal function argument conversions.

        The above argument conversions (except those performed by :mod:`ctypes`) can be disabled
        by setting the ``convert_args`` keyword argument to ``False``.

        If the method returns an Objective-C object, it is automatically converted to an :class:`ObjCInstance`.
        This conversion can be disabled by setting the ``convert_result`` keyword argument to ``False``,
        in which case the object is returned as a raw :class:`~rubicon.objc.runtime.objc_id` value.

        The ``_cmd`` selector argument does *not* need to be passed in manually ---
        the method's :attr:`selector` is automatically added between the receiver and the method arguments.
        """

        if len(args) != len(self.method_argtypes):
            raise TypeError(
                'Method {} takes {} arguments, but got {} arguments'
                .format(self.name, len(args), len(self.method_argtypes))
            )

        if convert_args:
            converted_args = []
            for argtype, arg in zip(self.method_argtypes, args):
                if isinstance(arg, enum.Enum):
                    # Convert Python enum objects to their values
                    arg = arg.value

                if issubclass(argtype, objc_block):
                    if arg is None:
                        # allow for 'nil' block args, which some objc methods accept
                        arg = ns_from_py(arg)
                    elif (callable(arg)
                          and not isinstance(arg, Block)):  # <-- guard against someone someday making Block callable
                        # Note: We need to keep the temp. Block instance
                        # around at least until the objc method is called.
                        # _as_parameter_ is used in the actual ctypes marshalling below.
                        arg = Block(arg)
                    # ^ For blocks at this point either arg is a Block instance
                    # (making use of _as_parameter_), is None, or if it isn't either of
                    # those two, an ArgumentError will be raised below.
                elif issubclass(argtype, objc_id):
                    # Convert Python objects to Foundation objects
                    arg = ns_from_py(arg)
                elif isinstance(arg, collections.abc.Sequence) and issubclass(argtype, (Structure, Array)):
                    arg = compound_value_for_sequence(arg, argtype)

                converted_args.append(arg)
        else:
            converted_args = args

        result = send_message(
            receiver, self.selector, *converted_args,
            restype=self.restype, argtypes=self.method_argtypes,
        )

        if not convert_result:
            return result

        # Convert result to python type if it is a instance or class pointer.
        if self.restype is not None and issubclass(self.restype, objc_id):
            result = ObjCInstance(result)

        # Mark for release if we acquire ownership of an object. Do not autorelease here because
        # we might retain a Python reference while the Obj-C reference goes out of scope.
        if self.name.startswith((b'alloc', b'new', b'copy', b'mutableCopy')):
            result._needs_release = True

        return result
def __call__ ( self , receiver , * args , convert_args = True , convert_result = True ) : if len ( args ) != len ( self . method_argtypes ) : raise TypeError ( 'Method {} takes {} arguments, but got {} arguments' . format ( self . name , len ( args ) , len ( self . method_argtypes ) ) ) if convert_args : converted_args = [ ] for argtype , arg in zip ( self . method_argtypes , args ) : if isinstance ( arg , enum . Enum ) : # Convert Python enum objects to their values arg = arg . value if issubclass ( argtype , objc_block ) : if arg is None : # allow for 'nil' block args, which some objc methods accept arg = ns_from_py ( arg ) elif ( callable ( arg ) and not isinstance ( arg , Block ) ) : # <-- guard against someone someday making Block callable # Note: We need to keep the temp. Block instance # around at least until the objc method is called. # _as_parameter_ is used in the actual ctypes marshalling below. arg = Block ( arg ) # ^ For blocks at this point either arg is a Block instance # (making use of _as_parameter_), is None, or if it isn't either of # those two, an ArgumentError will be raised below. elif issubclass ( argtype , objc_id ) : # Convert Python objects to Foundation objects arg = ns_from_py ( arg ) elif isinstance ( arg , collections . abc . Sequence ) and issubclass ( argtype , ( Structure , Array ) ) : arg = compound_value_for_sequence ( arg , argtype ) converted_args . append ( arg ) else : converted_args = args result = send_message ( receiver , self . selector , * converted_args , restype = self . restype , argtypes = self . method_argtypes , ) if not convert_result : return result # Convert result to python type if it is a instance or class pointer. if self . restype is not None and issubclass ( self . restype , objc_id ) : result = ObjCInstance ( result ) # Mark for release if we acquire ownership of an object. Do not autorelease here because # we might retain a Python reference while the Obj-C reference goes out of scope. if self . name . startswith ( ( b'alloc' , b'new' , b'copy' , b'mutableCopy' ) ) : result . _needs_release = True return result