Skip to content

Commit d6ca546

Browse files
committed
Make test_zipfile pass.
The zipfile module now does all I/O in binary mode using bytes. (Maybe we should support wrapping a TextIOWrapper around it when text mode reading is requested?) Even the password is a bytes array now. Had to fix py_compile.py to use bytes while I was at it. The _struct needed a patch to support bytes, str8 and str for the 's' and 'p' formats.
1 parent 94ca1c6 commit d6ca546

File tree

4 files changed

+177
-146
lines changed

4 files changed

+177
-146
lines changed

Lib/py_compile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def set_creator_type(file):
7272

7373
def wr_long(f, x):
7474
"""Internal; write a 32-bit int to a file in little-endian order."""
75-
f.write(chr( x & 0xff))
76-
f.write(chr((x >> 8) & 0xff))
77-
f.write(chr((x >> 16) & 0xff))
78-
f.write(chr((x >> 24) & 0xff))
75+
f.write(bytes([x & 0xff,
76+
(x >> 8) & 0xff,
77+
(x >> 16) & 0xff,
78+
(x >> 24) & 0xff]))
7979

8080
def compile(file, cfile=None, dfile=None, doraise=False):
8181
"""Byte-compile one Python source file to Python bytecode.
@@ -133,7 +133,7 @@ def compile(file, cfile=None, dfile=None, doraise=False):
133133
if cfile is None:
134134
cfile = file + (__debug__ and 'c' or 'o')
135135
fc = open(cfile, 'wb')
136-
fc.write('\0\0\0\0')
136+
fc.write(b'\0\0\0\0')
137137
wr_long(fc, timestamp)
138138
marshal.dump(codeobject, fc)
139139
fc.flush()

0 commit comments

Comments
 (0)