Skip to content

Modification to enable producing consistent binary output for the same data #810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docx/opc/phys_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import os

from zipfile import ZipFile, is_zipfile, ZIP_DEFLATED
from zipfile import ZipFile, ZipInfo, is_zipfile, ZIP_DEFLATED

from .compat import is_string
from .exceptions import PackageNotFoundError
Expand Down Expand Up @@ -152,4 +152,5 @@ def write(self, pack_uri, blob):
Write *blob* to this zip package with the membername corresponding to
*pack_uri*.
"""
self._zipf.writestr(pack_uri.membername, blob)
zinfo = ZipInfo(filename=pack_uri.membername, date_time=(1980, 1, 1, 0, 0, 0))
self._zipf.writestr(zinfo, blob)
5 changes: 3 additions & 2 deletions docx/opc/pkgwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def write(pkg_file, pkg_rels, parts):
content types of the parts.
"""
phys_writer = PhysPkgWriter(pkg_file)
PackageWriter._write_content_types_stream(phys_writer, parts)
sorted_parts = sorted(parts, key=lambda p: p.partname)
PackageWriter._write_content_types_stream(phys_writer, sorted_parts)
PackageWriter._write_pkg_rels(phys_writer, pkg_rels)
PackageWriter._write_parts(phys_writer, parts)
PackageWriter._write_parts(phys_writer, sorted_parts)
phys_writer.close()

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion docx/opc/rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def xml(self):
as a .rels file in an OPC package.
"""
rels_elm = CT_Relationships.new()
for rel in self.values():
for rel in sorted(self.values(), key=lambda r: r._rId):
rels_elm.add_rel(
rel.rId, rel.reltype, rel.target_ref, rel.is_external
)
Expand Down