2026년 11월 30일 월요일

How can I preserve both files when one ZIP contains two members with the same name?

Save each matching member to a different file. Iterate the ZIP’s ZipInfo entries, open each entry by its ZipInfo object, and assign an indexed output name. Use exclusive file creation so an existing output is never silently replaced. The recorded fixture demonstrates this result for one small synthetic ZIP; check your own archive before treating its copies as preserved.

How can I preserve both files when one ZIP contains two members with the same name?
A reading map of the checks explained below.

Why give the copies different names?

If two entries named same.txt are extracted to the same directory under that name, they compete for one destination path. Python documents that extraction can overwrite files without asking. Names such as same-0.txt and same-1.txt give the entries separate destinations while retaining their order for later comparison. Keep the original archive until you have checked the saved files.

Sources: zipfile — Work with ZIP archives — Decompression pitfalls — Default behaviors of extraction

How do I save every matching entry?

Create an empty directory named saved, then adapt archive.zip and same.txt below. This documentation-based streaming example has not been executed as part of the recorded fixture.

from pathlib import Path from shutil import copyfileobj from zipfile import ZipFile output_dir = Path("saved") with ZipFile("archive.zip") as archive: for index, member in enumerate(archive.infolist()): if member.filename != "same.txt" or member.is_dir(): continue target = output_dir / f"same-{index}.txt" created = False try: with archive.open(member) as source: with target.open("xb") as destination: created = True copyfileobj(source, destination) except Exception: if created: target.unlink() raise

ZipFile.infolist() supplies a ZipInfo object for each entry in archive order. Passing that object to ZipFile.open() selects the particular entry even when names repeat; shutil.copyfileobj() transfers its contents to the output stream. The created flag limits cleanup to a destination opened by this run. If the destination already exists, exclusive creation raises an error and the existing file is left in place. After any failure, stop and inspect the output directory before trying again.

Sources: zipfile — Work with ZIP archives — ZipFile objects — ZipFile.infolist(); ZipFile objects — ZipFile.open(); ZipInfo objects — ZipInfo.is_dir(), shutil — High-level file operations — Directory and files operations — shutil.copyfileobj()

How do I verify the saved copies?

The recorded zip-extract-local-v1 fixture used archive.read(member) and Path.write_bytes, not the streaming example above. On Python 3.12.13 on Darwin, its fixed synthetic ZIP held two same.txt entries. The recorded output was same-0.txt first and same-1.txt second. That establishes separate names and contents for that fixture only; the renderer supplies its exact code and output.

For your ZIP, count ZipInfo entries with the requested filename, excluding directories as the example does. Count the new indexed output files and require the totals to match. Then, for each matching entry in archive order, compare the bytes of its indexed output with archive.read(member). A matching file count alone cannot establish that both contents survived. Preserve the ZIP and investigate any missing file or byte mismatch.

Sources: zipfile — Work with ZIP archives — ZipFile objects — ZipFile.infolist(); ZipFile objects — ZipFile.read()

What limits matter for an unfamiliar ZIP?

Keep archive supplied names out of destination paths; the fixed basename in the example prevents a member path from choosing where the output is written. Inspect an untrusted archive before processing it. Password or CRC problems, unsupported compression, filesystem limits, or insufficient disk space can interrupt a copy. The example removes only its current, newly created destination when an error occurs; do not count a partial run as complete. The fixture did not test production archives, other operating systems or Python versions, or performance.

Sources: zipfile — Work with ZIP archives — ZipFile objects — ZipFile.extractall(); Decompression pitfalls — From file itself; Decompression pitfalls — File system limitations; Decompression pitfalls — Resources limitations; Decompression pitfalls — Interruption

Primary sources checked: 2026-11-29. Only the explicitly recorded fixture was tested locally; other guidance is documentation-based. No performance benchmark was performed.

Reproduce the locally verified result

zip-extract-local-v1

Recorded environment: 3.12.13 / Darwin. Checked: 2026-11-29T16:10:13.988193+00:00

import io
import warnings
import zipfile
from pathlib import Path
from tempfile import TemporaryDirectory

buffer = io.BytesIO()
with warnings.catch_warnings():
    warnings.simplefilter("ignore", UserWarning)
    with zipfile.ZipFile(buffer, "w") as archive:
        archive.writestr("same.txt", b"first")
        archive.writestr("same.txt", b"second")

with TemporaryDirectory() as directory:
    with zipfile.ZipFile(io.BytesIO(buffer.getvalue())) as archive:
        for index, member in enumerate(archive.infolist()):
            if member.filename == "same.txt":
                target = Path(directory) / f"same-{index}.txt"
                target.write_bytes(archive.read(member))
    for target in sorted(Path(directory).glob("same-*.txt")):
        print(target.name, target.read_text(encoding="ascii"))

Observed output

same-0.txt first
same-1.txt second

Only this fixed synthetic fixture was tested on the recorded runtime. No production files, other OS/version combinations, UI applications, throughput or performance were tested.

2026년 11월 26일 목요일

Why does my all-day ICS event end a day early?

If an all-day event runs through January 2, its calendar file should say January 3 in DTEND. That field marks the first day outside the event. You can check an export before importing it by comparing two dates in the file with the last day in the event listing.

Why does my all-day ICS event end a day early?
A reading map of the checks explained below.

Find the dates for one event

Open a copy of the .ics file in a text editor. Find the event you want and stay inside its BEGIN:VEVENT and END:VEVENT lines. Look for DTSTART;VALUE=DATE and DTEND;VALUE=DATE. Copy the eight digits after each property. Then write the last day shown in the original listing in the same year-month-day order, using eight digits and no separators.

For an event advertised as December 30 through January 2, use 20261230 for the start and 20270102 for the advertised last day. Take the exported end from the file itself. Keeping the listing and file values separate lets you check whether they agree.

Sources: RFC 5545, iCalendar — RFC 5545 §3.6.1, Event Component, including the multi-day event example

Check the exported end against the listing

First confirm that the advertised last day is on or after the start. Add one calendar day to that last day to get the expected DTEND. This works across month and year boundaries. If the end in the file equals or precedes the start, check that you copied both properties from the same event.

To try your own dates, copy the Python example below and replace one row in its list. Enter the start first, the exported end second and the advertised last day third. The program prints a verdict and the expected DTEND line. It reads only the three values you supply.

Check the exported end against the listing
Reported resultWhat to inspect or change
MATCHThe exported end matches the listing. Keep it.
Days shortConfirm the final date with the organizer and compare it with the expected DTEND line.
Days longCheck whether the exporter added a day to a date that was already exclusive.
INVALID RANGECheck the start and end fields. The explicit end must follow the start.

Sources: RFC 5545, iCalendar — RFC 5545 §3.6.1, Event Component, Python 3.12 datetime — Python 3.12 datetime documentation, date supported operations

Try three possible end dates for the same event

In the synthetic examples run with Python 3.12.13 below, an end value of 20270102 left January 2 out. An end of 20270103 included all four advertised days. An end of 20270104 included January 3 too. All three runs used the same start and advertised last day. Only the test value for DTEND changed.

The example also checks a one-day event and an end equal to its start. To report a problem to the calendar publisher, send the three dates, the result and the expected DTEND line. Those details let the publisher repeat the comparison without sharing the rest of your calendar.

Sources: RFC 5545, iCalendar — RFC 5545 §3.6.1, Event Component, Python 3.12 datetime — Python 3.12 datetime documentation, date supported operations

Check whether the event uses a different format

This check is for a single all-day event with explicit DATE values for both start and end. An all-day event can also have a start with neither DTEND nor DURATION. RFC 5545 gives that form a one-day duration. A recurring event, a DURATION field or a timestamp with a clock time needs a different interpretation. The examples here test calendar-date arithmetic locally.

Sources: RFC 5545, iCalendar — RFC 5545 §3.6.1, Event Component

Primary sources checked: 2026-11-26. Only the explicitly recorded fixture was tested locally; other guidance is documentation-based. No performance benchmark was performed.

Reproduce the locally verified result

ics-all-day-local-v1

Recorded environment: 3.12.13 / Darwin. Checked: 2026-11-26T06:04:11.365552+00:00

from datetime import date, timedelta

def read_date(value):
    if len(value) != 8 or not value.isascii() or not value.isdigit():
        raise ValueError("Use the eight digits from a VALUE=DATE property")
    return date(int(value[:4]), int(value[4:6]), int(value[6:]))

def check(start, exported_end, advertised_last):
    first, end, last = map(read_date, (start, exported_end, advertised_last))
    if last < first:
        raise ValueError("The advertised last day is before the start")
    expected = last + timedelta(days=1)
    if end <= first:
        status = "INVALID RANGE"
    else:
        delta = (end - expected).days
        status = "MATCH" if delta == 0 else f"{abs(delta)} day(s) " + ("short" if delta < 0 else "long")
    return f"{status} | expected DTEND;VALUE=DATE:{expected:%Y%m%d}"

# Each row: DTSTART, exported DTEND, last day shown in the listing.
for case in [
    ("20261230", "20261231", "20261230"),  # one day
    ("20261230", "20270102", "20270102"),  # advertised through Jan 2
    ("20261230", "20270103", "20270102"),  # already correct
    ("20261230", "20270104", "20270102"),  # an extra day was added twice
    ("20261230", "20261230", "20261230"),  # end equals start
]:
    print(*case, "|", check(*case))

Observed output

20261230 20261231 20261230 | MATCH | expected DTEND;VALUE=DATE:20261231
20261230 20270102 20270102 | 1 day(s) short | expected DTEND;VALUE=DATE:20270103
20261230 20270103 20270102 | MATCH | expected DTEND;VALUE=DATE:20270103
20261230 20270104 20270102 | 1 day(s) long | expected DTEND;VALUE=DATE:20270103
20261230 20261230 20261230 | INVALID RANGE | expected DTEND;VALUE=DATE:20261231

Only this fixed synthetic fixture was tested on the recorded runtime. No production files, other OS/version combinations, UI applications, throughput or performance were tested.