[pypy-commit] pypy py3.5-bz2-lzma: both bz2 and lzma seem to be in shape for py3.5
plan_rich
pypy.commits at gmail.com
Thu Sep 29 04:27:34 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5-bz2-lzma
Changeset: r87439:2f6b9156a6be
Date: 2016-09-29 10:19 +0200
http://bitbucket.org/pypy/pypy/changeset/2f6b9156a6be/
Log: both bz2 and lzma seem to be in shape for py3.5
diff --git a/pypy/module/bz2/interp_bz2.py b/pypy/module/bz2/interp_bz2.py
--- a/pypy/module/bz2/interp_bz2.py
+++ b/pypy/module/bz2/interp_bz2.py
@@ -203,7 +203,7 @@
self.left = 0
def get_data_size(self):
- return 0
+ return self.current_size - rffi.getintfield(self.bzs, 'c_avail_out')
def _allocate_chunk(self, size):
self.raw_buf, self.gc_buf, self.case_num = rffi.alloc_buffer(size)
@@ -430,14 +430,13 @@
# setup the input and the size it can consume
self.bzs.c_next_in = in_buf
rffi.setintfield(self.bzs, 'c_avail_in', in_bufsize)
- self.left_to_process -= in_bufsize
with OutBuffer(self.bzs, max_length=max_length) as out:
while True:
bzreturn = BZ2_bzDecompress(self.bzs)
# add up the size that has not been processed
avail_in = rffi.getintfield(self.bzs, 'c_avail_in')
- self.left_to_process += avail_in
+ self.left_to_process = avail_in
if bzreturn == BZ_STREAM_END:
self.running = False
break
@@ -474,8 +473,6 @@
if not self.running:
raise oefmt(self.space.w_EOFError,
"end of stream was already found")
- if data == '':
- return self.space.newbytes('')
datalen = len(data)
if len(self.input_buffer) > 0:
input_buffer_in_use = True
@@ -484,7 +481,6 @@
result = self._decompress_buf(data, max_length)
else:
input_buffer_in_use = False
- self.left_to_process = datalen
result = self._decompress_buf(data, max_length)
if self.left_to_process == 0:
@@ -493,7 +489,7 @@
else:
self.needs_input = False
if not input_buffer_in_use:
- start = datalen-self.left_to_process-1
+ start = datalen-self.left_to_process
assert start > 0
self.input_buffer = data[start:]
diff --git a/pypy/module/bz2/test/test_bz2_compdecomp.py b/pypy/module/bz2/test/test_bz2_compdecomp.py
--- a/pypy/module/bz2/test/test_bz2_compdecomp.py
+++ b/pypy/module/bz2/test/test_bz2_compdecomp.py
@@ -39,15 +39,6 @@
mod.OLD_SMALLCHUNK = interp_bz2.INITIAL_BUFFER_SIZE
interp_bz2.INITIAL_BUFFER_SIZE = 32
- test_size = 0
- mod.BIG_TEXT = bytearray(128*1024)
- for fname in glob.glob(os.path.join(os.path.dirname(__file__), '*.py')):
- with open(fname, 'rb') as fh:
- test_size += fh.readinto(memoryview(BIG_TEXT)[test_size:])
- if test_size > 128*1024:
- break
- mod.BIG_DATA = bz2.compress(BIG_TEXT, compresslevel=1)
-
def teardown_module(mod):
interp_bz2.INITIAL_BUFFER_SIZE = mod.OLD_SMALLCHUNK
@@ -133,8 +124,6 @@
def setup_class(cls):
cls.w_TEXT = cls.space.newbytes(TEXT)
cls.w_DATA = cls.space.newbytes(DATA)
- cls.w_BIG_DATA = cls.space.newbytes(BIG_DATA)
- cls.w_BIG_TEXT = cls.space.newbytes(BIG_TEXT)
cls.w_BUGGY_DATA = cls.space.newbytes(BUGGY_DATA)
cls.space.appexec([], """(): import warnings""") # Work around a recursion limit
@@ -219,24 +208,15 @@
bz2d = BZ2Decompressor()
decomp= []
- length = len(self.BIG_DATA)
- decomp.append(bz2d.decompress(self.BIG_DATA[:length-64]), max_length=100)
- assert bz2d.needs_input == False
+ length = len(self.DATA)
+ decomp.append(bz2d.decompress(self.DATA, max_length=100))
assert len(decomp[-1]) == 100
- decomp.append(bz2d.decompress(b"", max_length=50))
- assert bz2d.needs_input == False
- assert len(decomp[-1]) == 50
-
- decomp.append(bz2d.decompress(self.BIG_DATA[length-64:], max_length=50))
- assert bz2d.needs_input == False
- assert len(decomp[-1]) == 50
-
while not bz2d.eof:
decomp.append(bz2d.decompress(b"", max_length=50))
assert len(decomp[-1]) <= 50
- assert ''.join(decomp) == self.BIG_TEXT
+ assert b''.join(decomp) == self.TEXT
class AppTestBZ2ModuleFunctions(CheckAllocation):
diff --git a/rpython/tool/runsubprocess.py b/rpython/tool/runsubprocess.py
--- a/rpython/tool/runsubprocess.py
+++ b/rpython/tool/runsubprocess.py
@@ -8,10 +8,15 @@
import os
from subprocess import PIPE, Popen
+PY3 = sys.version_info[0] >= 3
+
def run_subprocess(executable, args, env=None, cwd=None):
if isinstance(args, list):
- args = [a.encode('latin1') if isinstance(a, unicode) else a
- for a in args]
+ if PY3:
+ args = [a for a in args]
+ else:
+ args = [a.encode('latin1') if isinstance(a, unicode) else a
+ for a in args]
return _run(executable, args, env, cwd)
shell_default = False
@@ -83,7 +88,7 @@
def _run(*args):
try:
- _child.stdin.write('%r\n' % (args,))
+ _child.stdin.write(b'%r\n' % (args,))
except (OSError, IOError):
# lost the child. Try again...
spawn_subprocess()
More information about the pypy-commit
mailing list