(self, mark_library: bool)
| 392 | return self.console.eval(code) |
| 393 | |
| 394 | def render_html(self, mark_library: bool) -> str: |
| 395 | context = 5 |
| 396 | lines = linecache.getlines(self.filename) |
| 397 | line_idx = self.lineno - 1 # type: ignore[operator] |
| 398 | start_idx = max(0, line_idx - context) |
| 399 | stop_idx = min(len(lines), line_idx + context + 1) |
| 400 | rendered_lines = [] |
| 401 | |
| 402 | def render_line(line: str, cls: str) -> None: |
| 403 | line = line.expandtabs().rstrip() |
| 404 | stripped_line = line.strip() |
| 405 | prefix = len(line) - len(stripped_line) |
| 406 | colno = getattr(self, "colno", 0) |
| 407 | end_colno = getattr(self, "end_colno", 0) |
| 408 | |
| 409 | if cls == "current" and colno and end_colno: |
| 410 | arrow = ( |
| 411 | f'\n<span class="ws">{" " * prefix}</span>' |
| 412 | f"{' ' * (colno - prefix)}{'^' * (end_colno - colno)}" |
| 413 | ) |
| 414 | else: |
| 415 | arrow = "" |
| 416 | |
| 417 | rendered_lines.append( |
| 418 | f'<pre class="line {cls}"><span class="ws">{" " * prefix}</span>' |
| 419 | f"{escape(stripped_line) if stripped_line else ' '}" |
| 420 | f"{arrow if arrow else ''}</pre>" |
| 421 | ) |
| 422 | |
| 423 | if line_idx < len(lines): |
| 424 | for line in lines[start_idx:line_idx]: |
| 425 | render_line(line, "before") |
| 426 | |
| 427 | render_line(lines[line_idx], "current") |
| 428 | |
| 429 | for line in lines[line_idx + 1 : stop_idx]: |
| 430 | render_line(line, "after") |
| 431 | |
| 432 | return FRAME_HTML % { |
| 433 | "id": id(self), |
| 434 | "filename": escape(self.filename), |
| 435 | "lineno": self.lineno, |
| 436 | "function_name": escape(self.name), |
| 437 | "lines": "\n".join(rendered_lines), |
| 438 | "library": "library" if mark_library and self.is_library else "", |
| 439 | } |
| 440 | |
| 441 | |
| 442 | def render_console_html(secret: str, evalex_trusted: bool) -> str: |
no outgoing calls
no test coverage detected