process block from the block_parser and return a list of processed lines
(self, block)
| 710 | self.clear_cout() |
| 711 | |
| 712 | def process_block(self, block): |
| 713 | """ |
| 714 | process block from the block_parser and return a list of processed lines |
| 715 | """ |
| 716 | ret = [] |
| 717 | output = None |
| 718 | input_lines = None |
| 719 | lineno = self.IP.execution_count |
| 720 | |
| 721 | input_prompt = self.promptin % lineno |
| 722 | output_prompt = self.promptout % lineno |
| 723 | image_file = None |
| 724 | image_directive = None |
| 725 | |
| 726 | found_input = False |
| 727 | for token, data in block: |
| 728 | if token == COMMENT: |
| 729 | out_data = self.process_comment(data) |
| 730 | elif token == INPUT: |
| 731 | found_input = True |
| 732 | (out_data, input_lines, output, is_doctest, |
| 733 | decorator, image_file, image_directive) = \ |
| 734 | self.process_input(data, input_prompt, lineno) |
| 735 | elif token == OUTPUT: |
| 736 | if not found_input: |
| 737 | |
| 738 | TAB = ' ' * 4 |
| 739 | linenumber = 0 |
| 740 | source = 'Unavailable' |
| 741 | content = 'Unavailable' |
| 742 | if self.directive: |
| 743 | linenumber = self.directive.state.document.current_line |
| 744 | source = self.directive.state.document.current_source |
| 745 | content = self.directive.content |
| 746 | # Add tabs and join into a single string. |
| 747 | content = '\n'.join([TAB + line for line in content]) |
| 748 | |
| 749 | e = ('\n\nInvalid block: Block contains an output prompt ' |
| 750 | 'without an input prompt.\n\n' |
| 751 | 'Document source: {0}\n\n' |
| 752 | 'Content begins at line {1}: \n\n{2}\n\n' |
| 753 | 'Problematic block within content: \n\n{TAB}{3}\n\n') |
| 754 | e = e.format(source, linenumber, content, block, TAB=TAB) |
| 755 | |
| 756 | # Write, rather than include in exception, since Sphinx |
| 757 | # will truncate tracebacks. |
| 758 | sys.stdout.write(e) |
| 759 | raise RuntimeError('An invalid block was detected.') |
| 760 | out_data = \ |
| 761 | self.process_output(data, output_prompt, input_lines, |
| 762 | output, is_doctest, decorator, |
| 763 | image_file) |
| 764 | if out_data: |
| 765 | # Then there was user submitted output in verbatim mode. |
| 766 | # We need to remove the last element of `ret` that was |
| 767 | # added in `process_input`, as it is '' and would introduce |
| 768 | # an undesirable newline. |
| 769 | assert(ret[-1] == '') |
no test coverage detected