[Epydoc-commits] SF.net SVN: epydoc: [1490] trunk/epydoc/src/epydoc/docstringparser.py
Brought to you by:
edloper
From: <ed...@us...> - 2007-02-14 01:33:31
|
Revision: 1490 http://svn.sourceforge.net/epydoc/?rev=1490&view=rev Author: edloper Date: 2007-02-13 17:33:29 -0800 (Tue, 13 Feb 2007) Log Message: ----------- - Extendedd support for extracting metadata fields from __variables__. List & tuple values for multival fields are now supported, as are int, float, bool, and None values (for introspection only -- parsing still requires string values). Also added several more __varaibles__. Modified Paths: -------------- trunk/epydoc/src/epydoc/docstringparser.py Modified: trunk/epydoc/src/epydoc/docstringparser.py =================================================================== --- trunk/epydoc/src/epydoc/docstringparser.py 2007-02-14 01:20:09 UTC (rev 1489) +++ trunk/epydoc/src/epydoc/docstringparser.py 2007-02-14 01:33:29 UTC (rev 1490) @@ -105,7 +105,7 @@ # If it's deprecated, put that first. DocstringField(['deprecated', 'depreciated'], - 'Deprecated', multivalue=0), + 'Deprecated', multivalue=0, varnames=['__deprecated__']), # Status info DocstringField(['version'], 'Version', multivalue=0, @@ -117,10 +117,12 @@ # Bibliographic Info DocstringField(['author', 'authors'], 'Author', 'Authors', short=1, varnames=['__author__', '__authors__']), - DocstringField(['contact'], 'Contact', 'Contacts', short=1), + DocstringField(['contact'], 'Contact', 'Contacts', short=1, + varnames=['__contact__']), DocstringField(['organization', 'org'], 'Organization', 'Organizations'), - DocstringField(['copyright', '(c)'], 'Copyright', multivalue=0), + DocstringField(['copyright', '(c)'], 'Copyright', multivalue=0, + varnames=['__copyright__']), DocstringField(['license'], 'License', multivalue=0, varnames=['__license__']), @@ -274,22 +276,39 @@ if varname not in api_doc.variables: continue if api_doc.variables[varname].value is UNKNOWN: continue val_doc = api_doc.variables[varname].value - # Extract the value from the variable. - value = None + 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, basestring): - value = val_doc.pyval + 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) + try: value = [epydoc.docparser.parse_string(val_doc.toktree)] except KeyboardInterrupt: raise except: pass - # If we found a value, then add it. - if value is not None: - if isinstance(value, str): - value = decode_with_backslashreplace(value) - value = epytext.ParsedEpytextDocstring( - epytext.parse_as_para(value)) - api_doc.metadata.append( (field, varname, value) ) + 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)) + api_doc.metadata.append( (field, varname, elt) ) def initialize_api_doc(api_doc): """A helper function for L{parse_docstring()} that initializes This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |