Function
lookup_lines
(
pth: str,
line_nos: List[int],
strip: bool=True,
encoding: str="utf-8"
)
Source from the content-addressed store, hash-verified
| 151 | |
| 152 | |
| 153 | def lookup_lines( |
| 154 | pth: str, |
| 155 | line_nos: List[int], |
| 156 | strip: bool=True, |
| 157 | encoding: str="utf-8" |
| 158 | ) -> Mapping[int, str]: |
| 159 | line_nos = sorted(line_nos) |
| 160 | lines = {} |
| 161 | if not line_nos: |
| 162 | return lines |
| 163 | |
| 164 | with codecs.open(pth, "r", encoding=encoding) as fd: |
| 165 | for ix, line in enumerate(fd): |
| 166 | if ix > line_nos[-1] + 1: |
| 167 | break |
| 168 | |
| 169 | line_no = ix + 1 |
| 170 | |
| 171 | if line_no in line_nos: |
| 172 | if strip: |
| 173 | line = line.strip() |
| 174 | lines[line_no] = line |
| 175 | return lines |
| 176 | |
| 177 | |
| 178 | def set_function_attr(**kwargs): |
Tested by
no test coverage detected