def get_next_block(self): """ Get the next item block from the docstring. The method reads the next item block in the docstring. The first line is assumed to be the Item header and the following lines to belong to the definition body:: <header line> <definition> The end of the field is designated by a line with the same indent as the field header or two empty lines in sequence. """ item_header = self.pop() sub_indent = get_indent(item_header) + ' ' block = [item_header] while not self.eod: current = self.peek() next = self.peek(1) if is_empty(current) and is_empty(next): self.seek_to_next_non_empty_line() break elif is_empty(current) and not next.startswith(sub_indent): self.pop() break elif not is_empty(current) and not current.startswith(sub_indent): break else: line = self.pop() block += [line.rstrip()] return block
def remove_if_empty(self, index=None): """ Remove the line from the docstring if it is empty. """ index = self.index if index is None else index if is_empty(self.docstring[index]): self.remove_lines(index)
def get_next_paragraph(self): """ Get the next paragraph designated by an empty line. """ lines = [] while (not self.eod) and (not is_empty(self.peek())): line = self.pop() lines.append(line) return lines
def seek_to_next_non_empty_line(self): """ Goto the next non_empty line. """ docstring = self.docstring for line in docstring[self.index:]: if not is_empty(line): break self.index += 1
def test_is_empty(self): output = is_empty(' ') self.assertTrue(output) output = is_empty(' . ') self.assertFalse(output)