List derivative with a special access attributes. These are normal lists, but with the special attributes: * .l (or .list) : value as list (the list itself). * .n (or .nlstr): value as a string, joined on newlines. * .s (or .spstr): value as a string, joined on spaces. * .p (or
| 97 | |
| 98 | |
| 99 | class SList(list[Any]): |
| 100 | """List derivative with a special access attributes. |
| 101 | |
| 102 | These are normal lists, but with the special attributes: |
| 103 | |
| 104 | * .l (or .list) : value as list (the list itself). |
| 105 | * .n (or .nlstr): value as a string, joined on newlines. |
| 106 | * .s (or .spstr): value as a string, joined on spaces. |
| 107 | * .p (or .paths): list of path objects (requires path.py package) |
| 108 | |
| 109 | Any values which require transformations are computed only once and |
| 110 | cached.""" |
| 111 | |
| 112 | __spstr: str |
| 113 | __nlstr: str |
| 114 | __paths: List[Path] |
| 115 | |
| 116 | def get_list(self) -> Self: |
| 117 | return self |
| 118 | |
| 119 | l = list = property(get_list) |
| 120 | |
| 121 | def get_spstr(self) -> str: |
| 122 | try: |
| 123 | return self.__spstr |
| 124 | except AttributeError: |
| 125 | self.__spstr = ' '.join(self) |
| 126 | return self.__spstr |
| 127 | |
| 128 | s = spstr = property(get_spstr) |
| 129 | |
| 130 | def get_nlstr(self) -> str: |
| 131 | try: |
| 132 | return self.__nlstr |
| 133 | except AttributeError: |
| 134 | self.__nlstr = '\n'.join(self) |
| 135 | return self.__nlstr |
| 136 | |
| 137 | n = nlstr = property(get_nlstr) |
| 138 | |
| 139 | def get_paths(self) -> List[Path]: |
| 140 | try: |
| 141 | return self.__paths |
| 142 | except AttributeError: |
| 143 | self.__paths = [Path(p) for p in self if os.path.exists(p)] |
| 144 | return self.__paths |
| 145 | |
| 146 | p = paths = property(get_paths) |
| 147 | |
| 148 | def grep( |
| 149 | self, |
| 150 | pattern: Union[str, Callable[[Any], re.Match[str] | None]], |
| 151 | prune: bool = False, |
| 152 | field: Optional[int] = None, |
| 153 | ) -> Self: |
| 154 | """Return all strings matching 'pattern' (a regex or callable) |
| 155 | |
| 156 | This is case-insensitive. If prune is true, return all items |
no outgoing calls
no test coverage detected
searching dependent graphs…