rclone-api 1.3.15__py2.py3-none-any.whl → 1.3.18__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rclone_api/db/db.py CHANGED
@@ -178,7 +178,7 @@ class DBRepo:
178
178
  "size": file.size,
179
179
  "mime_type": file.mime_type,
180
180
  "mod_time": file.mod_time,
181
- "suffix": file.suffix,
181
+ "suffix": file.real_suffix,
182
182
  }
183
183
  for file in is_new
184
184
  ]
@@ -213,7 +213,7 @@ class DBRepo:
213
213
  "size": file.size,
214
214
  "mime_type": file.mime_type,
215
215
  "mod_time": file.mod_time,
216
- "suffix": file.suffix,
216
+ "suffix": file.real_suffix,
217
217
  }
218
218
  )
219
219
  if update_values:
rclone_api/file.py CHANGED
@@ -12,6 +12,53 @@ def _intern(s: str) -> str:
12
12
  return _STRING_INTERNER.setdefault(s, s)
13
13
 
14
14
 
15
+ _SUFFIX_LARGEST_SIZE = len("torrents") + 2
16
+
17
+
18
+ def _suffix_clean_bad_parts(suffix: list[str]) -> list[str]:
19
+ """Remove any bad parts from the suffix list."""
20
+ out = []
21
+ for part in suffix:
22
+ if part in ["", ""]:
23
+ continue
24
+ if " " in part:
25
+ # split on spaces
26
+ continue
27
+ if "--" in part:
28
+ # split on --
29
+ parts = part.split("--")
30
+ parts = [x.strip() for x in parts if x.strip()]
31
+ out.extend(parts)
32
+ out.append(part)
33
+
34
+ out, tmp = [], out
35
+ for part in tmp:
36
+ if len(part) > _SUFFIX_LARGEST_SIZE:
37
+ continue
38
+ out.append(part)
39
+ return out
40
+
41
+
42
+ def _get_suffix(name: str, chop_compressed_suffixes: bool = True) -> str:
43
+ # name.sql.gz -> sql.gz
44
+ try:
45
+ parts = name.split(".")
46
+ if len(parts) == 1:
47
+ return ""
48
+ parts = _suffix_clean_bad_parts(parts)
49
+ last_part = parts[-1]
50
+ if chop_compressed_suffixes:
51
+ if last_part == "gz" and len(parts) > 2:
52
+ parts = parts[:-1]
53
+ return ".".join(parts[-1:])
54
+ except IndexError:
55
+ warnings.warn(f"Invalid name: {name} for normal suffix extraction")
56
+ suffix = Path(name).suffix
57
+ if suffix.startswith("."):
58
+ return suffix[1:]
59
+ return suffix
60
+
61
+
15
62
  # File is too complex, this is a simple dataclass that can be streamed out.
16
63
  @dataclass
17
64
  class FileItem:
@@ -40,14 +87,14 @@ class FileItem:
40
87
  return f"{self.parent}/{self.name}"
41
88
 
42
89
  @property
43
- def suffix(self) -> str:
90
+ def real_suffix(self) -> str:
44
91
  return self._suffix
45
92
 
46
93
  def __post_init__(self):
47
94
  self.parent = _intern(self.parent)
48
95
  self.mime_type = _intern(self.mime_type)
49
96
  self.remote = _intern(self.remote)
50
- self._suffix = _intern(Path(self.name).suffix)
97
+ self._suffix = _intern(_get_suffix(self.name))
51
98
 
52
99
  @staticmethod
53
100
  def from_json(remote: str, data: dict) -> "FileItem | None":