def _extract_docstring(node):
 doc_node = None
 if (node is None):
  pass
 elif isinstance(node, Nodes.ExprStatNode):
  if node.expr.is_string_literal:
   doc_node = node.expr
   node = Nodes.StatListNode(node.pos, stats=[])
 elif (isinstance(node, Nodes.StatListNode) and node.stats):
  stats = node.stats
  if isinstance(stats[0], Nodes.ExprStatNode):
   if stats[0].expr.is_string_literal:
    doc_node = stats[0].expr
    del stats[0]
 if (doc_node is None):
  doc = None
 elif isinstance(doc_node, ExprNodes.BytesNode):
  warning(node.pos, 'Python 3 requires docstrings to be unicode strings')
  doc = doc_node.value
 elif isinstance(doc_node, ExprNodes.StringNode):
  doc = doc_node.unicode_value
  if (doc is None):
   doc = doc_node.value
 else:
  doc = doc_node.value
 return (doc, node)

def _extract_docstring ( node ) : doc_node = None if ( node is None ) : pass elif isinstance ( node , Nodes . ExprStatNode ) : if node . expr . is_string_literal : doc_node = node . expr node = Nodes . StatListNode ( node . pos , stats = [ ] ) elif ( isinstance ( node , Nodes . StatListNode ) and node . stats ) : stats = node . stats if isinstance ( stats [ 0 ] , Nodes . ExprStatNode ) : if stats [ 0 ] . expr . is_string_literal : doc_node = stats [ 0 ] . expr del stats [ 0 ] if ( doc_node is None ) : doc = None elif isinstance ( doc_node , ExprNodes . BytesNode ) : warning ( node . pos , 'Python 3 requires docstrings to be unicode strings' ) doc = doc_node . value elif isinstance ( doc_node , ExprNodes . StringNode ) : doc = doc_node . unicode_value if ( doc is None ) : doc = doc_node . value else : doc = doc_node . value return ( doc , node )
extract a docstring from a statement or from the first statement in a list .