Python inspect.formatargspec() Examples
The following are 30
code examples of inspect.formatargspec().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
inspect
, or try the search function
.
Example #1
Source File: docscrape.py From ProxImaL with MIT License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature argspec = inspect.getargspec(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*', '\*') signature = '%s%s' % (func_name, argspec) except TypeError, e: signature = '%s()' % func_name self['Signature'] = signature
Example #2
Source File: docscrape.py From skutil with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature argspec = inspect.getargspec(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*', '\*') signature = '%s%s' % (func_name, argspec) except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature
Example #3
Source File: method.py From faces with GNU General Public License v2.0 | 6 votes |
def document_custom_signature(section, name, method, include=None, exclude=None): """Documents the signature of a custom method :param section: The section to write the documentation to. :param name: The name of the method :param method: The handle to the method being documented :type include: Dictionary where keys are parameter names and values are the shapes of the parameter names. :param include: The parameter shapes to include in the documentation. :type exclude: List of the names of the parameters to exclude. :param exclude: The names of the parameters to exclude from documentation. """ args, varargs, keywords, defaults = inspect.getargspec(method) args = args[1:] signature_params = inspect.formatargspec( args, varargs, keywords, defaults) signature_params = signature_params.lstrip('(') signature_params = signature_params.rstrip(')') section.style.start_sphinx_py_method(name, signature_params)
Example #4
Source File: method.py From faces with GNU General Public License v2.0 | 6 votes |
def document_custom_signature(section, name, method, include=None, exclude=None): """Documents the signature of a custom method :param section: The section to write the documentation to. :param name: The name of the method :param method: The handle to the method being documented :type include: Dictionary where keys are parameter names and values are the shapes of the parameter names. :param include: The parameter shapes to include in the documentation. :type exclude: List of the names of the parameters to exclude. :param exclude: The names of the parameters to exclude from documentation. """ args, varargs, keywords, defaults = inspect.getargspec(method) args = args[1:] signature_params = inspect.formatargspec( args, varargs, keywords, defaults) signature_params = signature_params.lstrip('(') signature_params = signature_params.rstrip(')') section.style.start_sphinx_py_method(name, signature_params)
Example #5
Source File: wrapper.py From vnpy_crypto with MIT License | 6 votes |
def make_wrapper(func, how): @functools.wraps(func) def wrapper(self, *args, **kwargs): results = object.__getattribute__(self, '_results') data = results.model.data if how and isinstance(how, tuple): obj = data.wrap_output(func(results, *args, **kwargs), how[0], how[1:]) elif how: obj = data.wrap_output(func(results, *args, **kwargs), how) return obj argspec = getargspec(func) formatted = inspect.formatargspec(argspec[0], varargs=argspec[1], defaults=argspec[3]) func_name = get_function_name(func) wrapper.__doc__ = "%s%s\n%s" % (func_name, formatted, wrapper.__doc__) return wrapper
Example #6
Source File: redismock.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def get_wrapped(func, wrapper_template, evaldict): # Preserve the argspec for the wrapped function so that testing # tools such as pytest can continue to use their fixture injection. args, a, kw, defaults = inspect.getargspec(func) values = args[-len(defaults):] if defaults else None signature = inspect.formatargspec(args, a, kw, defaults) is_bound_method = hasattr(func, '__self__') if is_bound_method: args = args[1:] # Omit 'self' callargs = inspect.formatargspec(args, a, kw, values, formatvalue=lambda v: '=' + v) ctx = {'signature': signature, 'funcargs': callargs} six.exec_(wrapper_template % ctx, evaldict) wrapper = evaldict['wrapper'] update_wrapper(wrapper, func) if is_bound_method: wrapper = wrapper.__get__(func.__self__, type(func.__self__)) return wrapper
Example #7
Source File: ldap3mock.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def get_wrapped(func, wrapper_template, evaldict): # Preserve the argspec for the wrapped function so that testing # tools such as pytest can continue to use their fixture injection. args, a, kw, defaults = inspect.getargspec(func) values = args[-len(defaults):] if defaults else None signature = inspect.formatargspec(args, a, kw, defaults) is_bound_method = hasattr(func, '__self__') if is_bound_method: args = args[1:] # Omit 'self' callargs = inspect.formatargspec(args, a, kw, values, formatvalue=lambda v: '=' + v) ctx = {'signature': signature, 'funcargs': callargs} six.exec_(wrapper_template % ctx, evaldict) wrapper = evaldict['wrapper'] update_wrapper(wrapper, func) if is_bound_method: wrapper = wrapper.__get__(func.__self__, type(func.__self__)) return wrapper
Example #8
Source File: smtpmock.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def get_wrapped(func, wrapper_template, evaldict): # Preserve the argspec for the wrapped function so that testing # tools such as pytest can continue to use their fixture injection. args, a, kw, defaults = inspect.getargspec(func) values = args[-len(defaults):] if defaults else None signature = inspect.formatargspec(args, a, kw, defaults) is_bound_method = hasattr(func, '__self__') if is_bound_method: args = args[1:] # Omit 'self' callargs = inspect.formatargspec(args, a, kw, values, formatvalue=lambda v: '=' + v) ctx = {'signature': signature, 'funcargs': callargs} six.exec_(wrapper_template % ctx, evaldict) wrapper = evaldict['wrapper'] update_wrapper(wrapper, func) if is_bound_method: wrapper = wrapper.__get__(func.__self__, type(func.__self__)) return wrapper
Example #9
Source File: smppmock.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def get_wrapped(func, wrapper_template, evaldict): # Preserve the argspec for the wrapped function so that testing # tools such as pytest can continue to use their fixture injection. args, a, kw, defaults = inspect.getargspec(func) values = args[-len(defaults):] if defaults else None signature = inspect.formatargspec(args, a, kw, defaults) is_bound_method = hasattr(func, '__self__') if is_bound_method: args = args[1:] # Omit 'self' callargs = inspect.formatargspec(args, a, kw, values, formatvalue=lambda v: '=' + v) ctx = {'signature': signature, 'funcargs': callargs} six.exec_(wrapper_template % ctx, evaldict) wrapper = evaldict['wrapper'] update_wrapper(wrapper, func) if is_bound_method: wrapper = wrapper.__get__(func.__self__, type(func.__self__)) return wrapper
Example #10
Source File: radiusmock.py From privacyidea with GNU Affero General Public License v3.0 | 6 votes |
def get_wrapped(func, wrapper_template, evaldict): # Preserve the argspec for the wrapped function so that testing # tools such as pytest can continue to use their fixture injection. args, a, kw, defaults = inspect.getargspec(func) values = args[-len(defaults):] if defaults else None signature = inspect.formatargspec(args, a, kw, defaults) is_bound_method = hasattr(func, '__self__') if is_bound_method: args = args[1:] # Omit 'self' callargs = inspect.formatargspec(args, a, kw, values, formatvalue=lambda v: '=' + v) ctx = {'signature': signature, 'funcargs': callargs} six.exec_(wrapper_template % ctx, evaldict) wrapper = evaldict['wrapper'] update_wrapper(wrapper, func) if is_bound_method: wrapper = wrapper.__get__(func.__self__, type(func.__self__)) return wrapper
Example #11
Source File: _inspect.py From Computable with MIT License | 6 votes |
def formatargspec(args, varargs=None, varkw=None, defaults=None, formatarg=str, formatvarargs=lambda name: '*' + name, formatvarkw=lambda name: '**' + name, formatvalue=lambda value: '=' + repr(value), join=joinseq): """Format an argument spec from the 4 values returned by getargspec. The first four arguments are (args, varargs, varkw, defaults). The other four arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The ninth argument is an optional function to format the sequence of arguments.""" specs = [] if defaults: firstdefault = len(args) - len(defaults) for i in range(len(args)): spec = strseq(args[i], formatarg, join) if defaults and i >= firstdefault: spec = spec + formatvalue(defaults[i - firstdefault]) specs.append(spec) if varargs is not None: specs.append(formatvarargs(varargs)) if varkw is not None: specs.append(formatvarkw(varkw)) return '(' + ', '.join(specs) + ')'
Example #12
Source File: docscrape.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature argspec = inspect.getargspec(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*', '\*') signature = '%s%s' % (func_name, argspec) except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature
Example #13
Source File: func_inspect.py From mlens with MIT License | 6 votes |
def format_signature(func, *args, **kwargs): # XXX: Should this use inspect.formatargvalues/formatargspec? module, name = get_func_name(func) module = [m for m in module if m] if module: module.append(name) module_path = '.'.join(module) else: module_path = name arg_str = list() previous_length = 0 for arg in args: formatted_arg = _format_arg(arg) if previous_length > 80: formatted_arg = '\n%s' % formatted_arg previous_length = len(formatted_arg) arg_str.append(formatted_arg) arg_str.extend(['%s=%s' % (v, _format_arg(i)) for v, i in kwargs.items()]) arg_str = ', '.join(arg_str) signature = '%s(%s)' % (name, arg_str) return module_path, signature
Example #14
Source File: overloading.py From overloading.py with MIT License | 6 votes |
def update_docstring(dispatcher, func=None): """ Inserts a call signature at the beginning of the docstring on `dispatcher`. The signature is taken from `func` if provided; otherwise `(...)` is used. """ doc = dispatcher.__doc__ or '' if inspect.cleandoc(doc).startswith('%s(' % dispatcher.__name__): return sig = '(...)' if func and func.__code__.co_argcount: argspec = inspect.getfullargspec(func) # pylint: disable=deprecated-method if argspec.args and argspec.args[0] in {'self', 'cls'}: argspec.args.pop(0) if any(argspec): sig = inspect.formatargspec(*argspec) # pylint: disable=deprecated-method sig = re.sub(r' at 0x[0-9a-f]{8,16}(?=>)', '', sig) sep = '\n' if doc.startswith('\n') else '\n\n' dispatcher.__doc__ = dispatcher.__name__ + sig + sep + doc
Example #15
Source File: method.py From bash-lambda-layer with MIT License | 6 votes |
def document_custom_signature(section, name, method, include=None, exclude=None): """Documents the signature of a custom method :param section: The section to write the documentation to. :param name: The name of the method :param method: The handle to the method being documented :type include: Dictionary where keys are parameter names and values are the shapes of the parameter names. :param include: The parameter shapes to include in the documentation. :type exclude: List of the names of the parameters to exclude. :param exclude: The names of the parameters to exclude from documentation. """ args, varargs, keywords, defaults = inspect.getargspec(method) args = args[1:] signature_params = inspect.formatargspec( args, varargs, keywords, defaults) signature_params = signature_params.lstrip('(') signature_params = signature_params.rstrip(')') section.style.start_sphinx_py_method(name, signature_params)
Example #16
Source File: test_inspect.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def assertFullArgSpecEquals(self, routine, args_e, varargs_e=None, varkw_e=None, defaults_e=None, kwonlyargs_e=[], kwonlydefaults_e=None, ann_e={}, formatted=None): args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \ inspect.getfullargspec(routine) self.assertEqual(args, args_e) self.assertEqual(varargs, varargs_e) self.assertEqual(varkw, varkw_e) self.assertEqual(defaults, defaults_e) self.assertEqual(kwonlyargs, kwonlyargs_e) self.assertEqual(kwonlydefaults, kwonlydefaults_e) self.assertEqual(ann, ann_e) if formatted is not None: self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann), formatted)
Example #17
Source File: _inspect.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def formatargspec(args, varargs=None, varkw=None, defaults=None, formatarg=str, formatvarargs=lambda name: '*' + name, formatvarkw=lambda name: '**' + name, formatvalue=lambda value: '=' + repr(value), join=joinseq): """Format an argument spec from the 4 values returned by getargspec. The first four arguments are (args, varargs, varkw, defaults). The other four arguments are the corresponding optional formatting functions that are called to turn names and values into strings. The ninth argument is an optional function to format the sequence of arguments.""" specs = [] if defaults: firstdefault = len(args) - len(defaults) for i in range(len(args)): spec = strseq(args[i], formatarg, join) if defaults and i >= firstdefault: spec = spec + formatvalue(defaults[i - firstdefault]) specs.append(spec) if varargs is not None: specs.append(formatvarargs(varargs)) if varkw is not None: specs.append(formatvarkw(varkw)) return '(' + ', '.join(specs) + ')'
Example #18
Source File: docscrape.py From noisyopt with MIT License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature if sys.version_info[0] >= 3: argspec = inspect.getfullargspec(func) else: argspec = inspect.getargspec(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*', '\*') signature = '%s%s' % (func_name, argspec) except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature
Example #19
Source File: docscrape.py From tick with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature argspec = inspect.signature(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*', '\*') signature = '%s%s' % (func_name, argspec) except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature
Example #20
Source File: method.py From deepWordBug with Apache License 2.0 | 6 votes |
def document_custom_signature(section, name, method, include=None, exclude=None): """Documents the signature of a custom method :param section: The section to write the documentation to. :param name: The name of the method :param method: The handle to the method being documented :type include: Dictionary where keys are parameter names and values are the shapes of the parameter names. :param include: The parameter shapes to include in the documentation. :type exclude: List of the names of the parameters to exclude. :param exclude: The names of the parameters to exclude from documentation. """ args, varargs, keywords, defaults = inspect.getargspec(method) args = args[1:] signature_params = inspect.formatargspec( args, varargs, keywords, defaults) signature_params = signature_params.lstrip('(') signature_params = signature_params.rstrip(')') section.style.start_sphinx_py_method(name, signature_params)
Example #21
Source File: docscrape.py From dmipy with MIT License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature if sys.version_info[0] >= 3: argspec = inspect.getfullargspec(func) else: argspec = inspect.getargspec(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*', '\*') signature = '%s%s' % (func_name, argspec) except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature
Example #22
Source File: docscrape.py From supersmoother with BSD 2-Clause "Simplified" License | 6 votes |
def __init__(self, func, role='func', doc=None, config={}): self._f = func self._role = role # e.g. "func" or "meth" if doc is None: if func is None: raise ValueError("No function or docstring given") doc = inspect.getdoc(func) or '' NumpyDocString.__init__(self, doc) if not self['Signature'] and func is not None: func, func_name = self.get_func() try: # try to read signature if sys.version_info[0] >= 3: argspec = inspect.getfullargspec(func) else: argspec = inspect.getargspec(func) argspec = inspect.formatargspec(*argspec) argspec = argspec.replace('*','\*') signature = '%s%s' % (func_name, argspec) except TypeError as e: signature = '%s()' % func_name self['Signature'] = signature
Example #23
Source File: DocXMLRPCServer.py From oss-ftp with MIT License | 5 votes |
def docroutine(self, object, name, mod=None, funcs={}, classes={}, methods={}, cl=None): """Produce HTML documentation for a function or method object.""" anchor = (cl and cl.__name__ or '') + '-' + name note = '' title = '<a name="%s"><strong>%s</strong></a>' % ( self.escape(anchor), self.escape(name)) if inspect.ismethod(object): args, varargs, varkw, defaults = inspect.getargspec(object.im_func) # exclude the argument bound to the instance, it will be # confusing to the non-Python user argspec = inspect.formatargspec ( args[1:], varargs, varkw, defaults, formatvalue=self.formatvalue ) elif inspect.isfunction(object): args, varargs, varkw, defaults = inspect.getargspec(object) argspec = inspect.formatargspec( args, varargs, varkw, defaults, formatvalue=self.formatvalue) else: argspec = '(...)' if isinstance(object, tuple): argspec = object[0] or argspec docstring = object[1] or "" else: docstring = pydoc.getdoc(object) decl = title + argspec + (note and self.grey( '<font face="helvetica, arial">%s</font>' % note)) doc = self.markup( docstring, self.preformat, funcs, classes, methods) doc = doc and '<dd><tt>%s</tt></dd>' % doc return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
Example #24
Source File: _pydev_calltip_util.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def get_description(obj): try: ob_call = obj.__call__ except: ob_call = None if isinstance(obj, type) or type(obj).__name__ == 'classobj': fob = getattr(obj, '__init__', lambda: None) if not isinstance(fob, (types.FunctionType, types.MethodType)): fob = obj elif is_bound_method(ob_call): fob = ob_call else: fob = obj argspec = "" fn_name = None fn_class = None if isinstance(fob, (types.FunctionType, types.MethodType)): spec_info = inspect.getfullargspec(fob) if IS_PY3K else inspect.getargspec(fob) argspec = inspect.formatargspec(*spec_info) fn_name = getattr(fob, '__name__', None) if isinstance(obj, type) or type(obj).__name__ == 'classobj': fn_name = "__init__" fn_class = getattr(obj, "__name__", "UnknownClass") elif is_bound_method(obj) or is_bound_method(ob_call): fn_class = get_bound_class_name(obj) or "UnknownClass" else: fn_name = getattr(fob, '__name__', None) fn_self = getattr(fob, '__self__', None) if fn_self is not None and not isinstance(fn_self, types.ModuleType): fn_class = get_class_name(fn_self) doc_string = get_docstring(ob_call) if is_bound_method(ob_call) else get_docstring(obj) return create_method_stub(fn_name, fn_class, argspec, doc_string)
Example #25
Source File: test_metaclass_and_extensions.py From me-ica with GNU Lesser General Public License v2.1 | 5 votes |
def get_signature(func): regargs, varargs, varkwargs, defaults = inspect.getargspec(func) return inspect.formatargspec(regargs, varargs, varkwargs, defaults, formatvalue=lambda value: "")[1:-1]
Example #26
Source File: workspace.py From pyGSTi with Apache License 2.0 | 5 votes |
def _makefactory(self, cls, autodisplay): # , printer=_objs.VerbosityPrinter(1)): # XXX this indirection is so wild -- can we please rewrite directly? #Manipulate argument list of cls.__init__ argspec = _inspect.getargspec(cls.__init__) argnames = argspec[0] assert(argnames[0] == 'self' and argnames[1] == 'ws'), \ "__init__ must begin with (self, ws, ...)" factoryfn_argnames = argnames[2:] # strip off self & ws args newargspec = (factoryfn_argnames,) + argspec[1:] #Define a new factory function with appropriate signature signature = _inspect.formatargspec( formatvalue=lambda val: "", *newargspec) signature = signature[1:-1] # strip off parenthesis from ends of "(signature)" if autodisplay: factory_func_def = ( 'def factoryfn(%(signature)s):\n' ' ret = cls(self, %(signature)s); ret.display(); return ret' % {'signature': signature}) else: factory_func_def = ( 'def factoryfn(%(signature)s):\n' ' return cls(self, %(signature)s)' % {'signature': signature}) #print("FACTORY FN DEF = \n",new_func) exec_globals = {'cls': cls, 'self': self} exec(factory_func_def, exec_globals) factoryfn = exec_globals['factoryfn'] #Copy cls.__init__ info over to factory function factoryfn.__name__ = cls.__init__.__name__ factoryfn.__doc__ = cls.__init__.__doc__ factoryfn.__module__ = cls.__init__.__module__ factoryfn.__dict__ = cls.__init__.__dict__ factoryfn.__defaults__ = cls.__init__.__defaults__ return factoryfn
Example #27
Source File: test_inspect.py From oss-ftp with MIT License | 5 votes |
def assertArgSpecEquals(self, routine, args_e, varargs_e = None, varkw_e = None, defaults_e = None, formatted = None): args, varargs, varkw, defaults = inspect.getargspec(routine) self.assertEqual(args, args_e) self.assertEqual(varargs, varargs_e) self.assertEqual(varkw, varkw_e) self.assertEqual(defaults, defaults_e) if formatted is not None: self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults), formatted)
Example #28
Source File: DocXMLRPCServer.py From Computable with MIT License | 5 votes |
def docroutine(self, object, name, mod=None, funcs={}, classes={}, methods={}, cl=None): """Produce HTML documentation for a function or method object.""" anchor = (cl and cl.__name__ or '') + '-' + name note = '' title = '<a name="%s"><strong>%s</strong></a>' % ( self.escape(anchor), self.escape(name)) if inspect.ismethod(object): args, varargs, varkw, defaults = inspect.getargspec(object.im_func) # exclude the argument bound to the instance, it will be # confusing to the non-Python user argspec = inspect.formatargspec ( args[1:], varargs, varkw, defaults, formatvalue=self.formatvalue ) elif inspect.isfunction(object): args, varargs, varkw, defaults = inspect.getargspec(object) argspec = inspect.formatargspec( args, varargs, varkw, defaults, formatvalue=self.formatvalue) else: argspec = '(...)' if isinstance(object, tuple): argspec = object[0] or argspec docstring = object[1] or "" else: docstring = pydoc.getdoc(object) decl = title + argspec + (note and self.grey( '<font face="helvetica, arial">%s</font>' % note)) doc = self.markup( docstring, self.preformat, funcs, classes, methods) doc = doc and '<dd><tt>%s</tt></dd>' % doc return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
Example #29
Source File: DocXMLRPCServer.py From BinderFilter with MIT License | 5 votes |
def docroutine(self, object, name, mod=None, funcs={}, classes={}, methods={}, cl=None): """Produce HTML documentation for a function or method object.""" anchor = (cl and cl.__name__ or '') + '-' + name note = '' title = '<a name="%s"><strong>%s</strong></a>' % ( self.escape(anchor), self.escape(name)) if inspect.ismethod(object): args, varargs, varkw, defaults = inspect.getargspec(object.im_func) # exclude the argument bound to the instance, it will be # confusing to the non-Python user argspec = inspect.formatargspec ( args[1:], varargs, varkw, defaults, formatvalue=self.formatvalue ) elif inspect.isfunction(object): args, varargs, varkw, defaults = inspect.getargspec(object) argspec = inspect.formatargspec( args, varargs, varkw, defaults, formatvalue=self.formatvalue) else: argspec = '(...)' if isinstance(object, tuple): argspec = object[0] or argspec docstring = object[1] or "" else: docstring = pydoc.getdoc(object) decl = title + argspec + (note and self.grey( '<font face="helvetica, arial">%s</font>' % note)) doc = self.markup( docstring, self.preformat, funcs, classes, methods) doc = doc and '<dd><tt>%s</tt></dd>' % doc return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
Example #30
Source File: test_inspect.py From BinderFilter with MIT License | 5 votes |
def assertArgSpecEquals(self, routine, args_e, varargs_e = None, varkw_e = None, defaults_e = None, formatted = None): args, varargs, varkw, defaults = inspect.getargspec(routine) self.assertEqual(args, args_e) self.assertEqual(varargs, varargs_e) self.assertEqual(varkw, varkw_e) self.assertEqual(defaults, defaults_e) if formatted is not None: self.assertEqual(inspect.formatargspec(args, varargs, varkw, defaults), formatted)