Parse native Windows and Rust timestamp precision on Python 3.10

This commit is contained in:
2026-11-17 17:34:48 +01:00
parent 8c39e79a79
commit 4f69312bef
2 changed files with 38 additions and 1 deletions
+12 -1
View File
@@ -35,7 +35,13 @@ def utc():
def stamp(value):
result = datetime.fromisoformat(value.replace('Z', '+00:00'))
# Windows emits 100 ns timestamps and Rust may emit nanoseconds. Python
# 3.10 accepts only millisecond or microsecond fractional precision.
match = re.fullmatch(r'(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:\d{2})', value)
require(match is not None, 'A timezone-qualified timestamp is required')
fraction = (match[2] or '').ljust(6, '0')[:6]
offset = '+00:00' if match[3] == 'Z' else match[3]
result = datetime.fromisoformat(match[1] + '.' + fraction + offset)
require(result.tzinfo is not None, 'Timestamp lacks timezone')
return result
@@ -279,6 +285,11 @@ def local():
data.update(agent_sha256=plan['agent_sha256'],helper_binary_sha256=plan['helper_sha256'])
with os.fdopen(os.open(casefile,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600),'wb') as dst:
dst.write(encode(data));dst.flush();os.fsync(dst.fileno())
directory=os.open(state_dir,os.O_RDONLY|os.O_DIRECTORY)
try:
os.fsync(directory)
finally:
os.close(directory)
emit({'preparing_window':data['case_id'],'expires_at':data['expires_at']})
emit(remote_server('prepare',data))
try: