Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Timer unit: 1e-06 s
- Total time: 0.012772 s
- File: json_generator.py
- Function: parse_example_parts at line 55
- Line # Hits Time Per Hit % Time Line Contents
- ==============================================================
- 55 @profile
- 56 def parse_example_parts(lines, example_title_line):
- 57 parts = {
- 58 57 30.0 0.5 0.2 "build_up": [],
- 59 57 51.0 0.9 0.4 "explanation": []
- 60 }
- 61 57 30.0 0.5 0.2 content = []
- 62 57 24.0 0.4 0.2 statements_so_far = []
- 63 57 29.0 0.5 0.2 output_so_far = []
- 64 57 27.0 0.5 0.2 next_line = example_title_line
- 65 # store build_up till an H4 (explanation) is encountered
- 66 713 533.0 0.7 4.2 while not next_line.startswith("#### "):
- 67 # Watching out for the snippets
- 68 656 501.0 0.8 3.9 if next_line.startswith("```"):
- 69 # It's a snippet, whatever found until now is text
- 70 140 75.0 0.5 0.6 is_interactive = False
- 71 140 74.0 0.5 0.6 if content:
- 72 140 325.0 2.3 2.5 parts["build_up"].append(generate_markdown_block(content))
- 73 140 74.0 0.5 0.6 content = []
- 74
- 75 140 82.0 0.6 0.6 next_line = next(lines)
- 76
- 77 1077 839.0 0.8 6.6 while not next_line.startswith("```"):
- 78 937 2201.0 2.3 17.2 if is_interactive_statement(next_line):
- 79 262 113.0 0.4 0.9 is_interactive = True
- 80 262 129.0 0.5 1.0 if (output_so_far):
- 81 120 309.0 2.6 2.4 parts["build_up"].append(generate_code_block(statements_so_far, output_so_far))
- 82 120 97.0 0.8 0.8 statements_so_far, output_so_far = [], []
- 83 262 177.0 0.7 1.4 statements_so_far.append(next_line)
- 84 else:
- 85 # can be either output or normal code
- 86 675 379.0 0.6 3.0 if is_interactive:
- 87 255 172.0 0.7 1.3 output_so_far.append(next_line)
- 88 else:
- 89 420 293.0 0.7 2.3 statements_so_far.append(next_line)
- 90 937 653.0 0.7 5.1 next_line = next(lines)
- 91
- 92 # Snippet is over
- 93 140 331.0 2.4 2.6 parts["build_up"].append(generate_code_block(statements_so_far, output_so_far))
- 94 140 280.0 2.0 2.2 statements_so_far, output_so_far = [], []
- 95 140 88.0 0.6 0.7 next_line = next(lines)
- 96 else:
- 97 # It's a text, go on.
- 98 516 317.0 0.6 2.5 content.append(next_line)
- 99 516 353.0 0.7 2.8 next_line = next(lines)
- 100
- 101 # Explanation encountered, save any content till now (if any)
- 102 57 33.0 0.6 0.3 if content:
- 103 57 120.0 2.1 0.9 parts["build_up"].append(generate_markdown_block(content))
- 104
- 105 # Reset stuff
- 106 57 40.0 0.7 0.3 content = []
- 107 57 36.0 0.6 0.3 statements_so_far, output_so_far = [], []
- 108
- 109 # store lines again until --- or another H3 is encountered
- 110 947 727.0 0.8 5.7 while not (next_line.startswith("---") or
- 111 891 676.0 0.8 5.3 next_line.startswith("### ")):
- 112 891 689.0 0.8 5.4 if next_line.startswith("```"):
- 113 # It's a snippet, whatever found until now is text
- 114 6 4.0 0.7 0.0 is_interactive = False
- 115 6 5.0 0.8 0.0 if content:
- 116 6 12.0 2.0 0.1 parts["build_up"].append(generate_markdown_block(content))
- 117 6 3.0 0.5 0.0 content = []
- 118
- 119 6 6.0 1.0 0.0 next_line = next(lines)
- 120
- 121 61 48.0 0.8 0.4 while not next_line.startswith("```"):
- 122 55 118.0 2.1 0.9 if is_interactive_statement(next_line):
- 123 28 12.0 0.4 0.1 is_interactive = True
- 124 28 16.0 0.6 0.1 if (output_so_far):
- 125 12 24.0 2.0 0.2 parts["build_up"].append(generate_code_block(statements_so_far, output_so_far))
- 126 12 6.0 0.5 0.0 statements_so_far, output_so_far = [], []
- 127 28 21.0 0.8 0.2 statements_so_far.append(next_line)
- 128 else:
- 129 # can be either output or normal code
- 130 27 11.0 0.4 0.1 if is_interactive:
- 131 20 14.0 0.7 0.1 output_so_far.append(next_line)
- 132 else:
- 133 7 5.0 0.7 0.0 statements_so_far.append(next_line)
- 134 55 42.0 0.8 0.3 next_line = next(lines)
- 135
- 136 # Snippet is over
- 137 6 16.0 2.7 0.1 parts["build_up"].append(generate_code_block(statements_so_far, output_so_far))
- 138 6 6.0 1.0 0.0 statements_so_far, output_so_far = [], []
- 139 6 5.0 0.8 0.0 next_line = next(lines)
- 140 else:
- 141 # It's a text, go on.
- 142 885 625.0 0.7 4.9 content.append(next_line)
- 143 885 666.0 0.8 5.2 next_line = next(lines)
- 144
- 145 # All done
- 146 56 42.0 0.8 0.3 if content:
- 147 56 129.0 2.3 1.0 parts["explanation"].append(generate_markdown_block(content))
- 148
- 149 56 29.0 0.5 0.2 return next_line, parts
Add Comment
Please, Sign In to add comment