| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e906df7 commit b86de33
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -383,13 +383,6 @@ def _get_cursor_offset(self) -> int: | |||
| 383 | 383 | def _set_cursor_offset(self, offset: int) -> None: | |
| 384 | 384 | self.cpos = len(self.s) - offset | |
| 385 | 385 | ||
| 386 | - cursor_offset = property( | ||
| 387 | - _get_cursor_offset, | ||
| 388 | - _set_cursor_offset, | ||
| 389 | - None, | ||
| 390 | - "The cursor offset from the beginning of the line", | ||
| 391 | - ) | ||
| 392 | - | ||
| 393 | 386 | def addstr(self, s: str) -> None: | |
| 394 | 387 | """Add a string to the current input line and figure out | |
| 395 | 388 | where it should go, depending on the cursor position.""" | |
@@ -539,13 +532,6 @@ def _get_current_line(self) -> str: | |||
| 539 | 532 | def _set_current_line(self, line: str) -> None: | |
| 540 | 533 | self.s = line | |
| 541 | 534 | ||
| 542 | - current_line = property( | ||
| 543 | - _get_current_line, | ||
| 544 | - _set_current_line, | ||
| 545 | - None, | ||
| 546 | - "The characters of the current line", | ||
| 547 | - ) | ||
| 548 | - | ||
| 549 | 535 | def cut_to_buffer(self) -> None: | |
| 550 | 536 | """Clear from cursor to end of line, placing into cut buffer""" | |
| 551 | 537 | self.cut_buffer = self.s[-self.cpos :] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1866,18 +1866,13 @@ def __repr__(self): | |||
| 1866 | 1866 | lines scrolled down: {self.scroll_offset} | |
| 1867 | 1867 | >""" | |
| 1868 | 1868 | ||
| 1869 | - @property | ||
| 1870 | - def current_line(self): | ||
| 1869 | + def _get_current_line(self) -> str: | ||
| 1871 | 1870 | """The current line""" | |
| 1872 | 1871 | return self._current_line | |
| 1873 | 1872 | ||
| 1874 | - @current_line.setter | ||
| 1875 | - def current_line(self, value): | ||
| 1876 | - self._set_current_line(value) | ||
| 1877 | - | ||
| 1878 | 1873 | def _set_current_line( | |
| 1879 | 1874 | self, | |
| 1880 | - line, | ||
| 1875 | + line: str, | ||
| 1881 | 1876 | update_completion=True, | |
| 1882 | 1877 | reset_rl_history=True, | |
| 1883 | 1878 | clear_special_mode=True, | |
@@ -1895,18 +1890,13 @@ def _set_current_line( | |||
| 1895 | 1890 | self.special_mode = None | |
| 1896 | 1891 | self.unhighlight_paren() | |
| 1897 | 1892 | ||
| 1898 | - @property | ||
| 1899 | - def cursor_offset(self): | ||
| 1893 | + def _get_cursor_offset(self) -> int: | ||
| 1900 | 1894 | """The current cursor offset from the front of the "line".""" | |
| 1901 | 1895 | return self._cursor_offset | |
| 1902 | 1896 | ||
| 1903 | - @cursor_offset.setter | ||
| 1904 | - def cursor_offset(self, value): | ||
| 1905 | - self._set_cursor_offset(value) | ||
| 1906 | - | ||
| 1907 | 1897 | def _set_cursor_offset( | |
| 1908 | 1898 | self, | |
| 1909 | - offset, | ||
| 1899 | + offset: int, | ||
| 1910 | 1900 | update_completion=True, | |
| 1911 | 1901 | reset_rl_history=False, | |
| 1912 | 1902 | clear_special_mode=True, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -392,7 +392,7 @@ class _FuncExpr: | |||
| 392 | 392 | keyword: Optional[str] = None | |
| 393 | 393 | ||
| 394 | 394 | ||
| 395 | - class Repl: | ||
| 395 | + class Repl(metaclass=abc.ABCMeta): | ||
| 396 | 396 | """Implements the necessary guff for a Python-repl-alike interface | |
| 397 | 397 | ||
| 398 | 398 | The execution of the code entered and all that stuff was taken from the | |
@@ -425,27 +425,51 @@ class Repl: | |||
| 425 | 425 | XXX Subclasses should implement echo, current_line, cw | |
| 426 | 426 | """ | |
| 427 | 427 | ||
| 428 | - if TYPE_CHECKING: | ||
| 428 | + @abc.abstractmethod | ||
| 429 | + def reevaluate(self): | ||
| 430 | + pass | ||
| 429 | 431 | ||
| 430 | - @property | ||
| 431 | - @abstractmethod | ||
| 432 | - def current_line(self) -> str: | ||
| 433 | - pass | ||
| 432 | + @abc.abstractmethod | ||
| 433 | + def reprint_line( | ||
| 434 | + self, lineno: int, tokens: List[Tuple[_TokenType, str]] | ||
| 435 | + ) -> None: | ||
| 436 | + pass | ||
| 434 | 437 | ||
| 435 | - @property | ||
| 436 | - @abstractmethod | ||
| 437 | - def cursor_offset(self) -> int: | ||
| 438 | - pass | ||
| 438 | + @abc.abstractmethod | ||
| 439 | + def _get_current_line(self) -> str: | ||
| 440 | + pass | ||
| 439 | 441 | ||
| 440 | - @abstractmethod | ||
| 441 | - def reevaluate(self): | ||
| 442 | - pass | ||
| 442 | + @abc.abstractmethod | ||
| 443 | + def _set_current_line(self, val: str) -> None: | ||
| 444 | + pass | ||
| 443 | 445 | ||
| 444 | - @abstractmethod | ||
| 445 | - def reprint_line( | ||
| 446 | - self, lineno: int, tokens: List[Tuple[_TokenType, str]] | ||
| 447 | - ) -> None: | ||
| 448 | - pass | ||
| 446 | + @property | ||
| 447 | + def current_line(self) -> str: | ||
| 448 | + """The current line""" | ||
| 449 | + return self._get_current_line() | ||
| 450 | + | ||
| 451 | + @current_line.setter | ||
| 452 | + def current_line(self, value: str) -> None: | ||
| 453 | + self._set_current_line(value) | ||
| 454 | + | ||
| 455 | + @abc.abstractmethod | ||
| 456 | + def _get_cursor_offset(self) -> int: | ||
| 457 | + pass | ||
| 458 | + | ||
| 459 | + @abc.abstractmethod | ||
| 460 | + def _set_cursor_offset(self, val: int) -> None: | ||
| 461 | + pass | ||
| 462 | + | ||
| 463 | + @property | ||
| 464 | + def cursor_offset(self) -> int: | ||
| 465 | + """The current cursor offset from the front of the "line".""" | ||
| 466 | + return self._get_cursor_offset() | ||
| 467 | + | ||
| 468 | + @cursor_offset.setter | ||
| 469 | + def cursor_offset(self, value: int) -> None: | ||
| 470 | + self._set_cursor_offset(value) | ||
| 471 | + | ||
| 472 | + if TYPE_CHECKING: | ||
| 449 | 473 | ||
| 450 | 474 | # not actually defined, subclasses must define | |
| 451 | 475 | cpos: int | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ | |||
| 5 | 5 | import tempfile | |
| 6 | 6 | import unittest | |
| 7 | 7 | ||
| 8 | + from typing import List, Tuple | ||
| 8 | 9 | from itertools import islice | |
| 9 | 10 | from pathlib import Path | |
| 10 | 11 | from unittest import mock | |
@@ -38,9 +39,32 @@ def reset(self): | |||
| 38 | 39 | ||
| 39 | 40 | class FakeRepl(repl.Repl): | |
| 40 | 41 | def __init__(self, conf=None): | |
| 41 | - repl.Repl.__init__(self, repl.Interpreter(), setup_config(conf)) | ||
| 42 | - self.current_line = "" | ||
| 43 | - self.cursor_offset = 0 | ||
| 42 | + super().__init__(repl.Interpreter(), setup_config(conf)) | ||
| 43 | + self._current_line = "" | ||
| 44 | + self._cursor_offset = 0 | ||
| 45 | + | ||
| 46 | + def _get_current_line(self) -> str: | ||
| 47 | + return self._current_line | ||
| 48 | + | ||
| 49 | + def _set_current_line(self, val: str) -> None: | ||
| 50 | + self._current_line = val | ||
| 51 | + | ||
| 52 | + def _get_cursor_offset(self) -> int: | ||
| 53 | + return self._cursor_offset | ||
| 54 | + | ||
| 55 | + def _set_cursor_offset(self, val: int) -> None: | ||
| 56 | + self._cursor_offset = val | ||
| 57 | + | ||
| 58 | + def getstdout(self) -> str: | ||
| 59 | + raise NotImplementedError | ||
| 60 | + | ||
| 61 | + def reprint_line( | ||
| 62 | + self, lineno: int, tokens: List[Tuple[repl._TokenType, str]] | ||
| 63 | + ) -> None: | ||
| 64 | + raise NotImplementedError | ||
| 65 | + | ||
| 66 | + def reevaluate(self): | ||
| 67 | + raise NotImplementedError | ||
| 44 | 68 | ||
| 45 | 69 | ||
| 46 | 70 | class FakeCliRepl(cli.CLIRepl, FakeRepl): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments