Skip to content

Commit 2dcac69

Browse files
committed
fix: add ZipInfo timestamp clamp to python-agent for openpyxl compatibility
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 2674b96 commit 2dcac69

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

examples/python-agent/agent.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
import io
2222
import os
2323
import sys
24+
import zipfile
25+
26+
# Unikraft's ramfs reports epoch-0 (1970) for file mtimes. Python's
27+
# zipfile rejects timestamps before 1980, which breaks openpyxl's
28+
# XLSX writer (XLSX is a ZIP container). Clamp pre-1980 dates.
29+
_orig_zi_init = zipfile.ZipInfo.__init__
30+
def _safe_zi_init(self, filename="NoName", date_time=(1980, 1, 1, 0, 0, 0)):
31+
if date_time[0] < 1980:
32+
date_time = (1980, 1, 1, 0, 0, 0)
33+
_orig_zi_init(self, filename, date_time)
34+
zipfile.ZipInfo.__init__ = _safe_zi_init
2435

2536
# 1. YAML config — either from /host or the inline fallback.
2637
import yaml
@@ -164,9 +175,7 @@ def _greet(greeting, who):
164175
print(f"\n[markdown-it] rendered {len(md)} chars of markdown -> {len(html)} chars of HTML")
165176

166177

167-
# 11. openpyxl — write an Excel workbook. The guest gets real wall
168-
# time from the host now (HLWALL0 init_data TLV), so XLSX
169-
# timestamps Just Work.
178+
# 11. openpyxl — write an Excel workbook.
170179
from openpyxl import Workbook
171180

172181
wb = Workbook()

0 commit comments

Comments
 (0)