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)
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))
def get_return_info(return_schema): """Returns a Return tuple according to the return_schema""" # Get the definition of what happens with the return --TODO, enhance for Complex Types, etc... # 1. return Simple/Primitive Type # 2. return Frame or Graph reference # 3. return Complex Type # 4. return None (no return value) data_type = get_data_type(return_schema) use_self = return_schema.get('self', False) #if use_self and data_type not in [Frame, Graph]: # raise TypeError("Error loading commands: use_self is True, but data_type is %s" % data_type) doc = get_return_description(return_schema) return ReturnInfo(data_type, use_self, doc)
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