Guest User

json_generator_line_profiler_output

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