MCPcopy Create free account
hub / github.com/ipython/ipython / process_block

Method process_block

IPython/sphinxext/ipython_directive.py:692–759  ·  view source on GitHub ↗

process block from the block_parser and return a list of processed lines

(self, block)

Source from the content-addressed store, hash-verified

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

Callers 1

runMethod · 0.80

Calls 6

process_commentMethod · 0.95
process_inputMethod · 0.95
process_outputMethod · 0.95
save_imageMethod · 0.95
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected