8000 bpo-32035: Fix words about strings and bytes in zipfile documentation… · python/cpython@4bb186d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bb186d

Browse files
bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592)
1 parent 7f4ba4a commit 4bb186d

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

Doc/library/zipfile.rst

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,6 @@ ZipFile Objects
387387
given.
388388
The archive must be open with mode ``'w'``, ``'x'`` or ``'a'``.
389389

390-
.. note::
391-
392-
There is no official file name encoding for ZIP files. If you have unicode file
393-
names, you must convert them to byte strings in your desired encoding before
394-
passing them to :meth:`write`. WinZip interprets all file names as encoded in
395-
CP437, also known as DOS Latin.
396-
397390
.. note::
398391

399392
Archive names should be relative to the archive root, that is, they should not
@@ -413,7 +406,9 @@ ZipFile Objects
413406
.. method:: ZipFile.writestr(zinfo_or_arcname, data, compress_type=None, \
414407
compresslevel=None)
415408

416-
Write the string *data* to the archive; *zinfo_or_arcname* is either the file
409+
Write a file into the archive. The contents is *data*, which may be either
410+
a :class:`str` or a :class:`bytes` instance; if it is a :class:`str`,
411+
it is encoded as UTF-8 first. *zinfo_or_arcname* is either the file
417412
name it will be given in the archive, or a :class:`ZipInfo` instance. If it's
418413
an instance, at least the filename, date, and time must be given. If it's a
419414
name, the date and time is set to the current date and time.
@@ -454,11 +449,11 @@ The following data attributes are also available:
454449

455450
.. attribute:: ZipFile.comment
456451

457-
The comment text associated with the ZIP file. If assigning a comment to a
452+
The comment associated with the ZIP file as a :class:`bytes` object.
453+
If assigning a comment to a
458454
:class:`ZipFile` instance created with mode ``'w'``, ``'x'`` or ``'a'``,
459-
this should be a
460-
string no longer than 65535 bytes. Comments longer than this will be
461-
truncated in the written archive when :meth:`close` is called.
455+
it should be no longer than 65535 bytes. Comments longer than this will be
456+
truncated.
462457

463458

464459
.. _pyzipfile-objects:
@@ -625,13 +620,14 @@ Instances have the following methods and attributes:
625620

626621
.. attribute:: ZipInfo.comment
627622

628-
Comment for the individual archive member.
623+
Comment for the individual archive member as a :class:`bytes` object.
629624

630625

631626
.. attribute:: ZipInfo.extra
632627

633628
Expansion field data. The `PKZIP Application Note`_ contains
634-
some comments on the internal structure of the data contained in this string.
629+
some comments on the internal structure of the data contained in this
630+
:class:`bytes` object.
635631

636632

637633
.. attribute:: ZipInfo.create_system

Lib/zipfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ def __repr__(self):
402402
return ''.join(result)
403403

404404
def FileHeader(self, zip64=None):
405-
"""Return the per-file header as a string."""
405+
"""Return the per-file header as a bytes object."""
406406
dt = self.date_time
407407
dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
408408
dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2)
@@ -1429,7 +1429,7 @@ def comment(self, comment):
14291429
self._didModify = True
14301430

14311431
def read(self, name, pwd=None):
1432-
"""Return file bytes (as a string) for name."""
1432+
"""Return file bytes for name."""
14331433
with self.open(name, "r", pwd) as fp:
14341434
return fp.read()
14351435

0 commit comments

Comments
 (0)
0