Exemple #1
0
def make_command_def(full_name):
    return CommandDefinition({},
                             full_name,
                             [Parameter('self', object, True, False, None, None),
                              Parameter('a', tatypes.int32, False, False, None, None),
                              Parameter('b', tatypes.int32, False, False, None, None)],
                              ReturnInfo(list, False, None))
Exemple #2
0
    def __init__(self, name, prop, intermediate_class, parent_name):

        self.parent_name = parent_name

        function = prop.fget
        function.command = self  # make command def accessible from function, just like functions gen'd from server info

        json_schema = {
        }  # make empty, since this command didn't come from json, and there is no need to generate it
        full_name = self._generate_full_name(parent_name, name)

        params = []
        params.append(
            Parameter(name='self',
                      data_type='object',
                      use_self=True,
                      optional=False,
                      default=None,
                      doc=None))
        return_info = ReturnInfo(intermediate_class,
                                 use_self=False,
                                 doc='%s object' % intermediate_class.__name__)

        maturity = function.maturity if hasattr(function, "maturity") else None

        super(IntermediatePropertyCommandDefinition,
              self).__init__(json_schema,
                             full_name,
                             params,
                             return_info,
                             is_property=True,
                             doc=prop.__doc__,
                             maturity=maturity)

        function.__doc__ = get_spa_docstring(self)
Exemple #3
0
def get_parameters(argument_schema):
    """Builds list of Parameter tuples as represented by the 'argument_schema'"""
    # Note - using the common convention that "parameters" are the variables in function definitions
    # and arguments are the values being passed in.  'argument_schema' is used in the rest API however.
    parameters = []
    if 'order' in argument_schema:
        for name in argument_schema['order']:
            properties = argument_schema['properties'][name]
            data_type = get_data_type(properties)
            use_self = properties.get('self', False)
            optional = name not in argument_schema['required']
            default = properties.get('default_value', None)
            doc = get_parameter_description(properties)
            parameters.append(
                Parameter(name, data_type, use_self, optional, default, doc))
    return parameters
Exemple #4
0
    def __init__(self, class_name, member, is_property, override_name=None):
        # Note: this code runs during package init (before connect)

        self.client_member = member
        self.parent_name = class_name

        function = member.fget if is_property else member
        function.command = self  # make command def accessible from function, just like functions gen'd from server info

        json_schema = {
        }  # make empty, since this command didn't come from json, and there is no need to generate it
        full_name = self._generate_full_name(
            class_name, override_name or function.__name__)

        params = []
        return_info = None

        args, kwargs, varargs, varkwargs = get_args_spec_from_function(
            function, ignore_private_args=True)
        num_args = len(args) + len(kwargs) + (1 if varargs else
                                              0) + (1 if varkwargs else 0)

        if hasattr(function, "arg_docs"):
            arg_docs = function.arg_docs
            num_arg_docs = len(arg_docs)
            if num_arg_docs > num_args:  # only check for greater than, the code after will give a better exception message for less than case
                raise ValueError(
                    "function received %d @arg decorators, expected %d for function %s."
                    % (num_arg_docs, num_args, function.__name__))

            def _get_arg_doc(name):
                arg_name = name

                def name_matches(arg_doc):
                    doc_name = arg_doc.name
                    while doc_name.startswith('*'):
                        doc_name = doc_name[1:]
                    return doc_name == arg_name

                try:
                    arg_doc = filter(name_matches, arg_docs)[0]
                except IndexError:
                    raise ValueError(
                        "Function missing @arg decorator for argument '%s' in function %s"
                        % (name, function.__name__))
                if not isinstance(arg_doc, ArgDoc):
                    raise TypeError(
                        "InternalError - @api decorator expected an ArgDoc for argument '%s' in function %s.  Received type %s"
                        % (name, function.__name__, type(arg_doc)))
                return arg_doc
        else:

            def _get_arg_doc(name):
                return ArgDoc(name, '', '')

        if args and args[0] == "self":
            params.append(
                Parameter(name='self',
                          data_type='object',
                          use_self=True,
                          optional=False,
                          default=None,
                          doc=''))
            args.pop(0)

        for arg_name in args:
            arg_doc = _get_arg_doc(arg_name)
            params.append(
                Parameter(name=arg_doc.name,
                          data_type=arg_doc.data_type,
                          use_self=False,
                          optional=False,
                          default=None,
                          doc=arg_doc.description))

        for arg_name, default in kwargs:
            arg_doc = _get_arg_doc(arg_name)
            params.append(
                Parameter(name=arg_doc.name,
                          data_type=arg_doc.data_type,
                          use_self=False,
                          optional=True,
                          default=default,
                          doc=arg_doc.description))

        for arg_name in [varargs, varkwargs]:
            if arg_name:
                arg_doc = _get_arg_doc(arg_name)
                params.append(
                    Parameter(name=arg_doc.name,
                              data_type=arg_doc.data_type,
                              use_self=False,
                              optional=True,
                              default=None,
                              doc=arg_doc.description))

        if hasattr(function, "return_doc"):
            return_doc = function.return_doc
            if not isinstance(return_doc, ReturnDoc):
                raise TypeError(
                    "InternalError - @returns decorator expected an ReturnDoc in function %s.  Received type %s."
                    % (function.__name__, type(return_doc)))
            return_info = ReturnInfo(return_doc.data_type,
                                     use_self=False,
                                     doc=return_doc.description
                                     )  # todo: remove use_self from ReturnInfo

        maturity = function.maturity if hasattr(function, "maturity") else None

        doc_string = parse_for_doc(function.__doc__)

        super(ClientCommandDefinition, self).__init__(json_schema,
                                                      full_name,
                                                      params,
                                                      return_info,
                                                      is_property,
                                                      doc_string,
                                                      maturity=maturity)

        spa_doc = get_spa_docstring(self)  # todo: make this numpydoc/googledoc
        function.__doc__ = spa_doc