def add_metadata_from_var(api_doc, field): for varname in field.varnames: # Check if api_doc has a variable w/ the given name. if varname not in api_doc.variables: continue # Check moved here from before the for loop because we expect to # reach rarely this point. The loop below is to be performed more than # once only for fields with more than one varname, which currently is # only 'author'. for md in api_doc.metadata: if field == md[0]: return # We already have a value for this metadata. var_doc = api_doc.variables[varname] if var_doc.value is UNKNOWN: continue val_doc = var_doc.value value = [] # Try extracting the value from the pyval. ok_types = (basestring, int, float, bool, type(None)) if val_doc.pyval is not UNKNOWN: if isinstance(val_doc.pyval, ok_types): value = [val_doc.pyval] elif field.multivalue: if isinstance(val_doc.pyval, (tuple, list)): for elt in val_doc.pyval: if not isinstance(elt, ok_types): break else: value = list(val_doc.pyval) # Try extracting the value from the parse tree. elif val_doc.toktree is not UNKNOWN: try: value = [epydoc.docparser.parse_string(val_doc.toktree)] except KeyboardInterrupt: raise except: pass if field.multivalue and not value: try: value = epydoc.docparser.parse_string_list(val_doc.toktree) except KeyboardInterrupt: raise except: raise # Add any values that we found. for elt in value: if isinstance(elt, str): elt = decode_with_backslashreplace(elt) else: elt = unicode(elt) elt = epytext.ParsedEpytextDocstring( epytext.parse_as_para(elt), inline=True) # Add in the metadata and remove from the variables api_doc.metadata.append( (field, varname, elt) ) # Remove the variable itself (unless it's documented) if var_doc.docstring in (None, UNKNOWN): del api_doc.variables[varname] if api_doc.sort_spec is not UNKNOWN: try: api_doc.sort_spec.remove(varname) except ValueError: pass
def add_metadata_from_var(api_doc, field): if not field.multivalue: for (f, a, d) in api_doc.metadata: if field == f: return # We already have a value for this metadata. for varname in field.varnames: # Check if api_doc has a variable w/ the given name. if varname not in api_doc.variables: continue var_doc = api_doc.variables[varname] if var_doc.value is UNKNOWN: continue val_doc = var_doc.value value = [] # Try extracting the value from the pyval. ok_types = (basestring, int, float, bool, type(None)) if val_doc.pyval is not UNKNOWN: if isinstance(val_doc.pyval, ok_types): value = [val_doc.pyval] elif field.multivalue: if isinstance(val_doc.pyval, (tuple, list)): for elt in val_doc.pyval: if not isinstance(elt, ok_types): break else: value = list(val_doc.pyval) # Try extracting the value from the parse tree. elif val_doc.toktree is not UNKNOWN: try: value = [epydoc.docparser.parse_string(val_doc.toktree)] except KeyboardInterrupt: raise except: pass if field.multivalue and not value: try: value = epydoc.docparser.parse_string_list(val_doc.toktree) except KeyboardInterrupt: raise except: raise # Add any values that we found. for elt in value: if isinstance(elt, str): elt = decode_with_backslashreplace(elt) else: elt = unicode(elt) elt = epytext.ParsedEpytextDocstring(epytext.parse_as_para(elt)) # Add in the metadata and remove from the variables api_doc.metadata.append((field, varname, elt)) if var_doc.docstring in (None, UNKNOWN): del api_doc.variables[varname]
def add_metadata_from_var(api_doc, field): if not field.multivalue: for (f,a,d) in api_doc.metadata: if field == f: return # We already have a value for this metadata. for varname in field.varnames: # Check if api_doc has a variable w/ the given name. if varname not in api_doc.variables: continue var_doc = api_doc.variables[varname] if var_doc.value is UNKNOWN: continue val_doc = var_doc.value value = [] # Try extracting the value from the pyval. ok_types = (basestring, int, float, bool, type(None)) if val_doc.pyval is not UNKNOWN: if isinstance(val_doc.pyval, ok_types): value = [val_doc.pyval] elif field.multivalue: if isinstance(val_doc.pyval, (tuple, list)): for elt in val_doc.pyval: if not isinstance(elt, ok_types): break else: value = list(val_doc.pyval) # Try extracting the value from the parse tree. elif val_doc.toktree is not UNKNOWN: try: value = [epydoc.docparser.parse_string(val_doc.toktree)] except KeyboardInterrupt: raise except: pass if field.multivalue and not value: try: value = epydoc.docparser.parse_string_list(val_doc.toktree) except KeyboardInterrupt: raise except: raise # Add any values that we found. for elt in value: if isinstance(elt, str): elt = decode_with_backslashreplace(elt) else: elt = unicode(elt) elt = epytext.ParsedEpytextDocstring( epytext.parse_as_para(elt)) # Add in the metadata and remove from the variables api_doc.metadata.append( (field, varname, elt) ) if var_doc.docstring in (None, UNKNOWN): del api_doc.variables[varname]