objectstore-client 0.2.2__tar.gz → 0.2.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: objectstore-client
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Client SDK for Objectstore, the Sentry object storage platform
5
5
  Author: Sentry
6
6
  Author-email: Sentry <oss@sentry.io>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "objectstore-client"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Client SDK for Objectstore, the Sentry object storage platform"
5
5
  readme = "README.md"
6
6
  authors = [{ name = "Sentry", email = "oss@sentry.io" }]
@@ -148,37 +148,47 @@ def parse_expiration(value: str) -> ExpirationPolicy | None:
148
148
 
149
149
 
150
150
  def format_timedelta(delta: timedelta) -> str:
151
- days = delta.days
152
- output = f"{days} days" if days else ""
153
- if seconds := delta.seconds:
154
- if output:
155
- output += " "
156
- output += f"{seconds} seconds"
151
+ """
152
+ Formats a duration in the wire format, such as `400d 1m 30s`.
153
+
154
+ Days are the largest unit, components that are zero are omitted, and a zero duration
155
+ is written as `0s`. Any sub-second remainder is truncated.
156
+ """
157
+ minutes, seconds = divmod(delta.seconds, 60)
158
+ hours, minutes = divmod(minutes, 60)
159
+
160
+ components = ((delta.days, "d"), (hours, "h"), (minutes, "m"), (seconds, "s"))
161
+ output = " ".join(f"{value}{unit}" for value, unit in components if value)
157
162
 
158
- return output
163
+ return output or "0s"
159
164
 
160
165
 
161
166
  TIME_SPLIT = re.compile(r"[^\W\d_]+|\d+")
162
167
 
163
168
 
164
169
  def parse_timedelta(delta: str) -> timedelta:
170
+ """
171
+ Parses a duration in the wire format, such as `400d 1m 30s`.
172
+
173
+ Units are matched exactly, so anything outside the wire format raises a
174
+ `ValueError` rather than being mistaken for a unit it merely starts with.
175
+ """
165
176
  words = TIME_SPLIT.findall(delta)
166
177
  seconds = 0
167
178
 
168
179
  for num, unit in itertools_batched(words, n=2, strict=True):
169
180
  num = int(num)
170
- multiplier = 0
171
181
 
172
- if unit.startswith("w"):
173
- multiplier = 86400 * 7
174
- elif unit.startswith("d"):
182
+ if unit == "d":
175
183
  multiplier = 86400
176
- elif unit.startswith("h"):
184
+ elif unit == "h":
177
185
  multiplier = 3600
178
- elif unit.startswith("m") and not unit.startswith("ms"):
186
+ elif unit == "m":
179
187
  multiplier = 60
180
- elif unit.startswith("s"):
188
+ elif unit == "s":
181
189
  multiplier = 1
190
+ else:
191
+ raise ValueError(f"unknown time unit {unit!r} in duration {delta!r}")
182
192
 
183
193
  seconds += num * multiplier
184
194