Get the text of the current source line as a string, with a trailing newline character
(self)
| 1220 | return None |
| 1221 | |
| 1222 | def current_line(self): |
| 1223 | '''Get the text of the current source line as a string, with a trailing |
| 1224 | newline character''' |
| 1225 | if self.is_optimized_out(): |
| 1226 | return FRAME_INFO_OPTIMIZED_OUT |
| 1227 | |
| 1228 | lineno = self.current_line_num() |
| 1229 | if lineno is None: |
| 1230 | return '(failed to get frame line number)' |
| 1231 | |
| 1232 | filename = self.filename() |
| 1233 | try: |
| 1234 | with open(os.fsencode(filename), 'r', encoding="utf-8") as fp: |
| 1235 | lines = fp.readlines() |
| 1236 | except IOError: |
| 1237 | return None |
| 1238 | |
| 1239 | try: |
| 1240 | # Convert from 1-based current_line_num to 0-based list offset |
| 1241 | return lines[lineno - 1] |
| 1242 | except IndexError: |
| 1243 | return None |
| 1244 | |
| 1245 | def write_repr(self, out, visited): |
| 1246 | if self.is_optimized_out(): |
no test coverage detected