Ë
    ú`jü  ã                  óh   — d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 ddœ	 	 	 	 	 	 	 d	d„Zy)
z<In-memory ZIP archive builder for multi-day C59 XML exports.é    )ÚannotationsN)Údatetime)Útimezone)ÚISTAT_ZIP_CONTENT_TYPEÚIstatZipExportResult)Úgenerated_atc           
     ó’  — t        j                  «       }t        j                  |dt        j                  ¬«      5 }|D ]&  \  }}|j                  ||j                  d«      «       Œ( 	 ddd«       |j                  «       }t        | |t        |xs t        j                  «       t        |«      t        |«      ¬«      S # 1 sw Y   ŒVxY w)u  Pack a list of (filename, xml_content) pairs into an in-memory ZIP.

    Args:
        zip_filename:  Name of the resulting ZIP archive.
        daily_files:   Ordered list of ``(xml_filename, xml_content_str)``
                       tuples â€” one entry per calendar day.
        generated_at:  Optional UTC timestamp; defaults to ``timezone.now()``.

    Returns:
        An :class:`IstatZipExportResult` with the raw ZIP bytes ready for
        an HTTP download response.  No filesystem I/O is performed.
    Úw)ÚmodeÚcompressionzutf-8N)ÚfilenameÚcontentÚcontent_typer   Ú	byte_sizeÚ
file_count)ÚioÚBytesIOÚzipfileÚZipFileÚZIP_DEFLATEDÚwritestrÚencodeÚgetvaluer   r   r   ÚnowÚlen)Úzip_filenameÚdaily_filesr   ÚbufferÚzfÚxml_filenameÚxml_contentÚ	zip_bytess           ú./backend/istat/xml_export/files/zip_builder.pyÚbuild_c59_zip_resultr$      s¡   € ô$ Z‰Z‹\€Fä	‰˜ c´w×7KÑ7KÕ	LÐPRÛ)4Ñ%ˆL˜+ØK‰K˜ k×&8Ñ&8¸Ó&AÕBñ *5÷ 
Mð —‘Ó!€IäØØÜ+Ø!Ò3¤X§\¡\£^Üi“.Ü{Ó#ôð ÷ 
MÐ	Lús   »,B=Â=C)r   Ústrr   zlist[tuple[str, str]]r   zdatetime | NoneÚreturnr   )Ú__doc__Ú
__future__r   r   r   r   Údjango.utilsr   Ú)istat.xml_export.models.zip_export_resultr   r   r$   © ó    r#   Ú<module>r-      sL   ðÙ Bå "ã 	Û Ý å !÷ð %)ñ	!àð!ð 'ð!ð "ð	!ð
 ô!r,   