|
5 | 5 | .. codeauthor:: Johannes Wienke |
6 | 6 | """ |
7 | 7 |
|
8 | | - |
9 | 8 | import abc |
10 | 9 | import argparse |
11 | 10 | import configparser |
12 | 11 | import fnmatch |
13 | 12 | import logging |
14 | 13 | import os |
15 | | -import os.path |
16 | 14 | from pathlib import Path |
17 | 15 | import re |
18 | 16 | import subprocess |
19 | 17 | import sys |
20 | | -from typing import Dict, IO, Mapping, Optional, Pattern, Sequence, Text |
| 18 | +from typing import IO, Mapping, Optional, Pattern, Sequence, Text |
21 | 19 |
|
22 | 20 | import xdg.BaseDirectory |
23 | 21 |
|
@@ -108,7 +106,7 @@ def parse(mapping_file: IO) -> configparser.ConfigParser: |
108 | 106 | return parse(file_handle) |
109 | 107 |
|
110 | 108 |
|
111 | | -def parse_request() -> Dict[str, str]: |
| 109 | +def parse_request() -> dict[str, str]: |
112 | 110 | """Parse the request of the git credential API from stdin. |
113 | 111 |
|
114 | 112 | Returns: |
@@ -189,11 +187,10 @@ def __init__(self, prefix_length: int, option_suffix: Text = "") -> None: |
189 | 187 | super().__init__(option_suffix) |
190 | 188 | self._prefix_length = prefix_length |
191 | 189 |
|
192 | | - @abc.abstractmethod |
193 | 190 | def configure(self, config: configparser.SectionProxy) -> None: |
194 | 191 | """Configure the amount of characters to skip.""" |
195 | 192 | self._prefix_length = config.getint( |
196 | | - "skip{suffix}".format(suffix=self._option_suffix), |
| 193 | + f"skip{self._option_suffix}", |
197 | 194 | fallback=self._prefix_length, |
198 | 195 | ) |
199 | 196 |
|
@@ -232,9 +229,7 @@ def __init__(self, line: int, prefix_length: int, option_suffix: Text = "") -> N |
232 | 229 | def configure(self, config: configparser.SectionProxy) -> None: |
233 | 230 | """See base class method.""" |
234 | 231 | super().configure(config) |
235 | | - self._line = config.getint( |
236 | | - "line{suffix}".format(suffix=self._option_suffix), fallback=self._line |
237 | | - ) |
| 232 | + self._line = config.getint(f"line{self._option_suffix}", fallback=self._line) |
238 | 233 |
|
239 | 234 | def _get_raw( |
240 | 235 | self, entry_name: Text, entry_lines: Sequence[Text] # noqa: ARG002 |
@@ -266,16 +261,16 @@ def _build_matcher(self, regex: str) -> Pattern: |
266 | 261 | matcher = re.compile(regex) |
267 | 262 | if matcher.groups != 1: |
268 | 263 | raise ValueError( |
269 | | - 'Provided regex "{regex}" must contain a single ' |
270 | | - "capture group for the value to return.".format(regex=regex) |
| 264 | + f'Provided regex "{regex}" must contain a single ' |
| 265 | + "capture group for the value to return." |
271 | 266 | ) |
272 | 267 | return matcher |
273 | 268 |
|
274 | 269 | def configure(self, config: configparser.SectionProxy) -> None: |
275 | 270 | """See base class method.""" |
276 | 271 | self._regex = self._build_matcher( |
277 | 272 | config.get( |
278 | | - "regex{suffix}".format(suffix=self._option_suffix), |
| 273 | + f"regex{self._option_suffix}", |
279 | 274 | fallback=self._regex.pattern, |
280 | 275 | ) |
281 | 276 | ) |
@@ -446,9 +441,9 @@ def get_password( |
446 | 441 | password = password_extractor.get_value(pass_target, lines) |
447 | 442 | username = username_extractor.get_value(pass_target, lines) |
448 | 443 | if password: |
449 | | - print("password={password}".format(password=password)) # noqa: T201 |
| 444 | + print(f"password={password}") # noqa: T201 |
450 | 445 | if "username" not in request and username: |
451 | | - print("username={username}".format(username=username)) # noqa: T201 |
| 446 | + print(f"username={username}") # noqa: T201 |
452 | 447 |
|
453 | 448 |
|
454 | 449 | def handle_skip() -> None: |
@@ -481,18 +476,14 @@ def main(argv: Optional[Sequence[str]] = None) -> None: |
481 | 476 | mapping = parse_mapping(args.mapping) |
482 | 477 | except Exception as error: # ok'ish for the main function |
483 | 478 | LOGGER.critical("Unable to parse mapping file", exc_info=True) |
484 | | - print( # noqa: T201 |
485 | | - "Unable to parse mapping file: {error}".format(error=error), file=sys.stderr |
486 | | - ) |
| 479 | + print(f"Unable to parse mapping file: {error}", file=sys.stderr) # noqa: T201 |
487 | 480 | sys.exit(1) |
488 | 481 |
|
489 | 482 | if action == "get": |
490 | 483 | try: |
491 | 484 | get_password(request, mapping) |
492 | 485 | except Exception as error: # ok'ish for the main function |
493 | | - print( # noqa: T201 |
494 | | - "Unable to retrieve entry: {error}".format(error=error), file=sys.stderr |
495 | | - ) |
| 486 | + print(f"Unable to retrieve entry: {error}", file=sys.stderr) # noqa: T201 |
496 | 487 | sys.exit(1) |
497 | 488 | else: |
498 | 489 | LOGGER.info("Action %s is currently not supported", action) |
|
0 commit comments