ソースを参照

refactor: use .remove(prefix|suffix) str methods (py39)

Thomas Waldmann 1 ヶ月 前
コミット
6157c4b968
2 ファイル変更3 行追加6 行削除
  1. 2 2
      src/borg/archiver/debug_cmd.py
  2. 1 4
      src/borg/remote.py

+ 2 - 2
src/borg/archiver/debug_cmd.py

@@ -152,9 +152,9 @@ class DebugMixIn:
         wanted = args.wanted
         try:
             if wanted.startswith("hex:"):
-                wanted = hex_to_bin(wanted[4:])
+                wanted = hex_to_bin(wanted.removeprefix("hex:"))
             elif wanted.startswith("str:"):
-                wanted = wanted[4:].encode()
+                wanted = wanted.removeprefix("str:").encode()
             else:
                 raise ValueError("unsupported search term")
         except (ValueError, UnicodeEncodeError):

+ 1 - 4
src/borg/remote.py

@@ -311,10 +311,7 @@ class RepositoryServer:  # pragma: no cover
                     raise
             sock_dir = os.path.dirname(self.socket_path)
             os.makedirs(sock_dir, exist_ok=True)
-            if self.socket_path.endswith(".sock"):
-                pid_file = self.socket_path.replace(".sock", ".pid")
-            else:
-                pid_file = self.socket_path + ".pid"
+            pid_file = self.socket_path.removesuffix(".sock") + ".pid"
             pid = os.getpid()
             with open(pid_file, "w") as f:
                 f.write(str(pid))