Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: guard-compatible Changeset: r85473:900ff3842617 Date: 2016-06-30 14:46 +0200 http://bitbucket.org/pypy/pypy/changeset/900ff3842617/
Log: merge default diff too long, truncating to 2000 out of 2999 lines diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py --- a/pypy/interpreter/baseobjspace.py +++ b/pypy/interpreter/baseobjspace.py @@ -1036,7 +1036,7 @@ return (None, None) def newlist_bytes(self, list_s): - return self.newlist([self.wrap(s) for s in list_s]) + return self.newlist([self.newbytes(s) for s in list_s]) def newlist_unicode(self, list_u): return self.newlist([self.wrap(u) for u in list_u]) @@ -1535,7 +1535,7 @@ # unclear if there is any use at all for getting the bytes in # the unicode buffer.) try: - return self.str_w(w_obj) + return self.bytes_w(w_obj) except OperationError as e: if not e.match(self, self.w_TypeError): raise diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py --- a/pypy/interpreter/pycode.py +++ b/pypy/interpreter/pycode.py @@ -408,14 +408,14 @@ w(self.co_nlocals), w(self.co_stacksize), w(self.co_flags), - w(self.co_code), + space.newbytes(self.co_code), space.newtuple(self.co_consts_w), space.newtuple(self.co_names_w), space.newtuple([w(v) for v in self.co_varnames]), w(self.co_filename), w(self.co_name), w(self.co_firstlineno), - w(self.co_lnotab), + space.newbytes(self.co_lnotab), space.newtuple([w(v) for v in self.co_freevars]), space.newtuple([w(v) for v in self.co_cellvars]), w(self.magic), diff --git a/pypy/interpreter/pyparser/automata.py b/pypy/interpreter/pyparser/automata.py --- a/pypy/interpreter/pyparser/automata.py +++ b/pypy/interpreter/pyparser/automata.py @@ -13,12 +13,11 @@ # PYPY Modification: removed the EMPTY class as it's not needed here -# PYPY Modification: we don't need a particuliar DEFAULT class here -# a simple None works fine. -# (Having a DefaultClass inheriting from str makes -# the annotator crash) -DEFAULT = "\00default" # XXX hack, the rtyper does not support dict of with str|None keys - # anyway using dicts doesn't seem the best final way to store these char indexed tables +# PYPY Modification: DEFAULT is a singleton, used only in the pre-RPython +# dicts (see pytokenize.py). Then DFA.__init__() turns these dicts into +# more compact strings. +DEFAULT = object() + # PYPY Modification : removed all automata functions (any, maybe, # newArcPair, etc.) diff --git a/pypy/interpreter/pyparser/genpytokenize.py b/pypy/interpreter/pyparser/genpytokenize.py --- a/pypy/interpreter/pyparser/genpytokenize.py +++ b/pypy/interpreter/pyparser/genpytokenize.py @@ -293,7 +293,7 @@ i = 0 for k, v in sorted(state.items()): i += 1 - if k == '\x00default': + if k == DEFAULT: k = "automata.DEFAULT" else: k = repr(k) diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py --- a/pypy/interpreter/pyparser/parsestring.py +++ b/pypy/interpreter/pyparser/parsestring.py @@ -81,7 +81,7 @@ if need_encoding: enc = encoding v = PyString_DecodeEscape(space, substr, 'strict', enc) - return space.wrap(v) + return space.newbytes(v) def decode_unicode_utf8(space, s, ps, q): # ****The Python 2.7 version, producing UTF-32 escapes**** diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py --- a/pypy/module/_cffi_backend/ctypeprim.py +++ b/pypy/module/_cffi_backend/ctypeprim.py @@ -84,7 +84,7 @@ if self.size == 1: with cdataobj as ptr: s = ptr[0] - return self.space.wrap(s) + return self.space.newbytes(s) return W_CType.string(self, cdataobj, maxlen) def unpack_ptr(self, w_ctypeptr, ptr, length): @@ -126,12 +126,12 @@ return self.space.wrap(ord(cdata[0])) def convert_to_object(self, cdata): - return self.space.wrap(cdata[0]) + return self.space.newbytes(cdata[0]) def _convert_to_char(self, w_ob): space = self.space if space.isinstance_w(w_ob, space.w_str): - s = space.str_w(w_ob) + s = space.bytes_w(w_ob) if len(s) == 1: return s[0] if (isinstance(w_ob, cdataobj.W_CData) and @@ -146,7 +146,7 @@ def unpack_ptr(self, w_ctypeptr, ptr, length): s = rffi.charpsize2str(ptr, length) - return self.space.wrapbytes(s) + return self.space.newbytes(s) # XXX explicitly use an integer type instead of lltype.UniChar here, diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py --- a/pypy/module/_cffi_backend/ctypeptr.py +++ b/pypy/module/_cffi_backend/ctypeptr.py @@ -120,7 +120,7 @@ s = rffi.charp2str(ptr) else: s = rffi.charp2strn(ptr, length) - return space.wrapbytes(s) + return space.newbytes(s) # # pointer to a wchar_t: builds and returns a unicode if self.is_unichar_ptr_or_array(): @@ -129,7 +129,7 @@ u = rffi.wcharp2unicode(cdata) else: u = rffi.wcharp2unicoden(cdata, length) - return space.wrap(u) + return space.newunicode(u) # return W_CType.string(self, cdataobj, maxlen) diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py --- a/pypy/module/_codecs/interp_codecs.py +++ b/pypy/module/_codecs/interp_codecs.py @@ -36,12 +36,14 @@ w_errorhandler = lookup_error(space, errors) if decode: w_cls = space.w_UnicodeDecodeError + w_input = space.newbytes(input) else: w_cls = space.w_UnicodeEncodeError + w_input = space.newunicode(input) w_exc = space.call_function( w_cls, space.wrap(encoding), - space.wrap(input), + w_input, space.wrap(startpos), space.wrap(endpos), space.wrap(reason)) @@ -314,7 +316,7 @@ @unwrap_spec(errors='str_or_None') def readbuffer_encode(space, w_data, errors='strict'): s = space.getarg_w('s#', w_data) - return space.newtuple([space.wrap(s), space.wrap(len(s))]) + return space.newtuple([space.newbytes(s), space.wrap(len(s))]) @unwrap_spec(errors='str_or_None') def charbuffer_encode(space, w_data, errors='strict'): @@ -377,7 +379,7 @@ state = space.fromcache(CodecState) func = getattr(runicode, rname) result = func(uni, len(uni), errors, state.encode_error_handler) - return space.newtuple([space.wrap(result), space.wrap(len(uni))]) + return space.newtuple([space.newbytes(result), space.wrap(len(uni))]) wrap_encoder.func_name = rname globals()[name] = wrap_encoder @@ -398,7 +400,7 @@ wrap_decoder.func_name = rname globals()[name] = wrap_decoder -for encoders in [ +for encoder in [ "ascii_encode", "latin_1_encode", "utf_7_encode", @@ -412,9 +414,9 @@ "raw_unicode_escape_encode", "unicode_internal_encode", ]: - make_encoder_wrapper(encoders) + make_encoder_wrapper(encoder) -for decoders in [ +for decoder in [ "ascii_decode", "latin_1_decode", "utf_7_decode", @@ -426,7 +428,7 @@ "utf_32_le_decode", "raw_unicode_escape_decode", ]: - make_decoder_wrapper(decoders) + make_decoder_wrapper(decoder) if hasattr(runicode, 'str_decode_mbcs'): make_encoder_wrapper('mbcs_encode') @@ -560,7 +562,7 @@ if space.isinstance_w(w_ch, space.w_str): # Charmap may return a string - return space.str_w(w_ch) + return space.bytes_w(w_ch) elif space.isinstance_w(w_ch, space.w_int): # Charmap may return a number x = space.int_w(w_ch) @@ -608,7 +610,7 @@ result = runicode.unicode_encode_charmap( uni, len(uni), errors, state.encode_error_handler, mapping) - return space.newtuple([space.wrap(result), space.wrap(len(uni))]) + return space.newtuple([space.newbytes(result), space.wrap(len(uni))]) @unwrap_spec(chars=unicode) @@ -696,4 +698,4 @@ def escape_decode(space, data, errors='strict'): from pypy.interpreter.pyparser.parsestring import PyString_DecodeEscape result = PyString_DecodeEscape(space, data, errors, None) - return space.newtuple([space.wrap(result), space.wrap(len(data))]) + return space.newtuple([space.newbytes(result), space.wrap(len(data))]) diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py --- a/pypy/module/_hashlib/interp_hashlib.py +++ b/pypy/module/_hashlib/interp_hashlib.py @@ -111,7 +111,7 @@ def digest(self, space): "Return the digest value as a string of binary data." digest = self._digest(space) - return space.wrap(digest) + return space.newbytes(digest) def hexdigest(self, space): "Return the digest value as a string of hexadecimal digits." diff --git a/pypy/module/_io/interp_bufferedio.py b/pypy/module/_io/interp_bufferedio.py --- a/pypy/module/_io/interp_bufferedio.py +++ b/pypy/module/_io/interp_bufferedio.py @@ -343,7 +343,7 @@ self._writer_reset_buf() def _write(self, space, data): - w_data = space.wrap(data) + w_data = space.newbytes(data) while True: try: w_written = space.call_method(self.w_raw, "write", w_data) @@ -415,7 +415,7 @@ else: raise oefmt(space.w_ValueError, "read length must be positive or -1") - return space.wrap(res) + return space.newbytes(res) @unwrap_spec(size=int) def peek_w(self, space, size=0): @@ -432,7 +432,7 @@ have = self._readahead() if have > 0: data = ''.join(self.buffer[self.pos:self.pos+have]) - return space.wrap(data) + return space.newbytes(data) # Fill the buffer from the raw stream, and copy it to the result self._reader_reset_buf() @@ -442,7 +442,7 @@ size = 0 self.pos = 0 data = ''.join(self.buffer[:size]) - return space.wrap(data) + return space.newbytes(data) @unwrap_spec(size=int) def read1_w(self, space, size): @@ -452,7 +452,7 @@ if size < 0: raise oefmt(space.w_ValueError, "read length must be positive") if size == 0: - return space.wrap("") + return space.newbytes("") with self.lock: # Return up to n bytes. If at least one byte is buffered, we only @@ -480,7 +480,7 @@ endpos = self.pos + size data = ''.join(self.buffer[self.pos:endpos]) self.pos = endpos - return space.wrap(data) + return space.newbytes(data) def _read_all(self, space): "Read all the file, don't update the cache" @@ -505,7 +505,7 @@ if current_size == 0: return w_data break - data = space.str_w(w_data) + data = space.bytes_w(w_data) size = len(data) if size == 0: break @@ -513,7 +513,7 @@ current_size += size if self.abs_pos != -1: self.abs_pos += size - return space.wrap(builder.build()) + return space.newbytes(builder.build()) def _raw_read(self, space, buffer, start, length): length = intmask(length) @@ -644,11 +644,11 @@ else: pos = -1 if pos >= 0: - w_res = space.wrap(''.join(self.buffer[self.pos:pos+1])) + w_res = space.newbytes(''.join(self.buffer[self.pos:pos+1])) self.pos = pos + 1 return w_res if have == limit: - w_res = space.wrap(''.join(self.buffer[self.pos:self.pos+have])) + w_res = space.newbytes(''.join(self.buffer[self.pos:self.pos+have])) self.pos += have return w_res @@ -690,7 +690,7 @@ written += have if limit >= 0: limit -= have - return space.wrap(''.join(chunks)) + return space.newbytes(''.join(chunks)) # ____________________________________________________ # Write methods @@ -1024,7 +1024,6 @@ self._deprecated_max_buffer_size(space) self.state = STATE_ZERO - check_readable_w(space, w_raw) check_writable_w(space, w_raw) check_seekable_w(space, w_raw) diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py --- a/pypy/module/_io/interp_bytesio.py +++ b/pypy/module/_io/interp_bytesio.py @@ -32,12 +32,12 @@ def read_w(self, space, w_size=None): self._check_closed(space) size = convert_size(space, w_size) - return space.wrap(self.read(size)) + return space.newbytes(self.read(size)) def readline_w(self, space, w_limit=None): self._check_closed(space) limit = convert_size(space, w_limit) - return space.wrap(self.readline(limit)) + return space.newbytes(self.readline(limit)) def read1_w(self, space, w_size): return self.read_w(space, w_size) @@ -81,7 +81,7 @@ def getvalue_w(self, space): self._check_closed(space) - return space.wrap(self.getvalue()) + return space.newbytes(self.getvalue()) def tell_w(self, space): self._check_closed(space) @@ -128,7 +128,7 @@ def getstate_w(self, space): self._check_closed(space) return space.newtuple([ - space.wrap(self.getvalue()), + space.newbytes(self.getvalue()), space.wrap(self.tell()), self.getdict(space)]) diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py --- a/pypy/module/_io/interp_fileio.py +++ b/pypy/module/_io/interp_fileio.py @@ -361,7 +361,7 @@ raise wrap_oserror(space, e, exception_name='w_IOError') - return space.wrap(s) + return space.newbytes(s) def readinto_w(self, space, w_buffer): self._check_closed(space) @@ -405,7 +405,7 @@ break builder.append(chunk) total += len(chunk) - return space.wrap(builder.build()) + return space.newbytes(builder.build()) if sys.platform == "win32": def _truncate(self, size): diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py --- a/pypy/module/_io/interp_iobase.py +++ b/pypy/module/_io/interp_iobase.py @@ -192,7 +192,7 @@ length = space.len_w(w_readahead) if length > 0: n = 0 - buf = space.str_w(w_readahead) + buf = space.bytes_w(w_readahead) if limit >= 0: while True: if n >= length or n >= limit: @@ -219,7 +219,7 @@ raise oefmt(space.w_IOError, "peek() should have returned a bytes object, not " "'%T'", w_read) - read = space.str_w(w_read) + read = space.bytes_w(w_read) if not read: break @@ -229,7 +229,7 @@ if read[-1] == '\n': break - return space.wrap(builder.build()) + return space.newbytes(builder.build()) def readlines_w(self, space, w_hint=None): hint = convert_size(space, w_hint) @@ -339,11 +339,11 @@ if not space.isinstance_w(w_data, space.w_str): raise oefmt(space.w_TypeError, "read() should return bytes") - data = space.str_w(w_data) + data = space.bytes_w(w_data) if not data: break builder.append(data) - return space.wrap(builder.build()) + return space.newbytes(builder.build()) W_RawIOBase.typedef = TypeDef( '_io._RawIOBase', W_IOBase.typedef, diff --git a/pypy/module/_io/interp_textio.py b/pypy/module/_io/interp_textio.py --- a/pypy/module/_io/interp_textio.py +++ b/pypy/module/_io/interp_textio.py @@ -160,7 +160,7 @@ w_buffer, w_flag = space.unpackiterable(w_state, 2) flag = space.r_longlong_w(w_flag) else: - w_buffer = space.wrap("") + w_buffer = space.newbytes("") flag = 0 flag <<= 1 if self.pendingcr: @@ -556,7 +556,7 @@ # Given this, we know there was a valid snapshot point # len(dec_buffer) bytes ago with decoder state (b'', dec_flags). w_dec_buffer, w_dec_flags = space.unpackiterable(w_state, 2) - dec_buffer = space.str_w(w_dec_buffer) + dec_buffer = space.bytes_w(w_dec_buffer) dec_flags = space.int_w(w_dec_flags) else: dec_buffer = None @@ -582,7 +582,7 @@ if self.telling: # At the snapshot point, len(dec_buffer) bytes before the read, # the next input to be decoded is dec_buffer + input_chunk. - next_input = dec_buffer + space.str_w(w_input) + next_input = dec_buffer + space.bytes_w(w_input) self.snapshot = PositionSnapshot(dec_flags, next_input) return not eof @@ -769,7 +769,7 @@ else: w_bytes = space.call_method(self.w_encoder, "encode", w_text) - b = space.str_w(w_bytes) + b = space.bytes_w(w_bytes) if not self.pending_bytes: self.pending_bytes = [] self.pending_bytes_count = 0 @@ -799,7 +799,8 @@ while True: try: - space.call_method(self.w_buffer, "write", space.wrap(pending_bytes)) + space.call_method(self.w_buffer, "write", + space.newbytes(pending_bytes)) except OperationError as e: if trap_eintr(space, e): continue @@ -828,7 +829,7 @@ space.call_method(self.w_decoder, "reset") else: space.call_method(self.w_decoder, "setstate", - space.newtuple([space.wrap(""), + space.newtuple([space.newbytes(""), space.wrap(cookie.dec_flags)])) def _encoder_setstate(self, space, cookie): @@ -904,7 +905,7 @@ raise oefmt(space.w_TypeError, msg, w_chunk) self.snapshot = PositionSnapshot(cookie.dec_flags, - space.str_w(w_chunk)) + space.bytes_w(w_chunk)) w_decoded = space.call_method(self.w_decoder, "decode", w_chunk, space.wrap(cookie.need_eof)) @@ -975,7 +976,7 @@ i = 0 while i < len(input): w_decoded = space.call_method(self.w_decoder, "decode", - space.wrap(input[i])) + space.newbytes(input[i])) check_decoded(space, w_decoded) chars_decoded += len(space.unicode_w(w_decoded)) diff --git a/pypy/module/_md5/interp_md5.py b/pypy/module/_md5/interp_md5.py --- a/pypy/module/_md5/interp_md5.py +++ b/pypy/module/_md5/interp_md5.py @@ -20,7 +20,7 @@ self.update(string) def digest_w(self): - return self.space.wrap(self.digest()) + return self.space.newbytes(self.digest()) def hexdigest_w(self): return self.space.wrap(self.hexdigest()) diff --git a/pypy/module/_minimal_curses/interp_curses.py b/pypy/module/_minimal_curses/interp_curses.py --- a/pypy/module/_minimal_curses/interp_curses.py +++ b/pypy/module/_minimal_curses/interp_curses.py @@ -83,12 +83,12 @@ return space.w_None except curses_error as e: raise convert_error(space, e) - return space.wrap(result) + return space.newbytes(result) @unwrap_spec(s=str) def tparm(space, s, args_w): args = [space.int_w(a) for a in args_w] try: - return space.wrap(_curses_tparm(s, args)) + return space.newbytes(_curses_tparm(s, args)) except curses_error as e: raise convert_error(space, e) diff --git a/pypy/module/_multibytecodec/interp_incremental.py b/pypy/module/_multibytecodec/interp_incremental.py --- a/pypy/module/_multibytecodec/interp_incremental.py +++ b/pypy/module/_multibytecodec/interp_incremental.py @@ -113,7 +113,7 @@ pos = c_codecs.pypy_cjk_enc_inbuf_consumed(self.encodebuf) assert 0 <= pos <= len(object) self.pending = object[pos:] - return space.wrap(output) + return space.newbytes(output) @unwrap_spec(errors="str_or_None") diff --git a/pypy/module/_multibytecodec/interp_multibytecodec.py b/pypy/module/_multibytecodec/interp_multibytecodec.py --- a/pypy/module/_multibytecodec/interp_multibytecodec.py +++ b/pypy/module/_multibytecodec/interp_multibytecodec.py @@ -40,7 +40,7 @@ raise wrap_unicodeencodeerror(space, e, input, self.name) except RuntimeError: raise wrap_runtimeerror(space) - return space.newtuple([space.wrap(output), + return space.newtuple([space.newbytes(output), space.wrap(len(input))]) @@ -66,7 +66,7 @@ space.w_UnicodeDecodeError, space.newtuple([ space.wrap(name), - space.wrap(input), + space.newbytes(input), space.wrap(e.start), space.wrap(e.end), space.wrap(e.reason)])) diff --git a/pypy/module/_multiprocessing/interp_connection.py b/pypy/module/_multiprocessing/interp_connection.py --- a/pypy/module/_multiprocessing/interp_connection.py +++ b/pypy/module/_multiprocessing/interp_connection.py @@ -122,9 +122,9 @@ space, self.BUFFER_SIZE, maxlength) try: if newbuf: - return space.wrap(rffi.charpsize2str(newbuf, res)) + return space.newbytes(rffi.charpsize2str(newbuf, res)) else: - return space.wrap(rffi.charpsize2str(self.buffer, res)) + return space.newbytes(rffi.charpsize2str(self.buffer, res)) finally: if newbuf: rffi.free_charp(newbuf) @@ -138,7 +138,7 @@ space, length - offset, PY_SSIZE_T_MAX) try: if newbuf: - raise BufferTooShort(space, space.wrap( + raise BufferTooShort(space, space.newbytes( rffi.charpsize2str(newbuf, res))) rwbuffer.setslice(offset, rffi.charpsize2str(self.buffer, res)) finally: @@ -166,9 +166,9 @@ space, self.BUFFER_SIZE, PY_SSIZE_T_MAX) try: if newbuf: - w_received = space.wrap(rffi.charpsize2str(newbuf, res)) + w_received = space.newbytes(rffi.charpsize2str(newbuf, res)) else: - w_received = space.wrap(rffi.charpsize2str(self.buffer, res)) + w_received = space.newbytes(rffi.charpsize2str(self.buffer, res)) finally: if newbuf: rffi.free_charp(newbuf) diff --git a/pypy/module/_rawffi/alt/test/test_type_converter.py b/pypy/module/_rawffi/alt/test/test_type_converter.py --- a/pypy/module/_rawffi/alt/test/test_type_converter.py +++ b/pypy/module/_rawffi/alt/test/test_type_converter.py @@ -12,14 +12,14 @@ handle_signed = handle_all handle_unsigned = handle_all handle_pointer = handle_all - handle_char = handle_all + handle_char = handle_all handle_unichar = handle_all handle_longlong = handle_all handle_char_p = handle_all handle_unichar_p = handle_all handle_float = handle_all handle_singlefloat = handle_all - + def handle_struct(self, w_ffitype, w_structinstance): self.lastval = w_structinstance @@ -119,12 +119,12 @@ def test_strings(self): # first, try automatic conversion from applevel - self.check(app_types.char_p, self.space.wrap('foo'), 'foo') - self.check(app_types.unichar_p, self.space.wrap(u'foo\u1234'), u'foo\u1234') - self.check(app_types.unichar_p, self.space.wrap('foo'), u'foo') + self.check(app_types.char_p, self.space.newbytes('foo'), 'foo') + self.check(app_types.unichar_p, self.space.wrap(u'foo\u1234'), u'foo\u1234') + self.check(app_types.unichar_p, self.space.wrap('foo'), u'foo') # then, try to pass explicit pointers self.check(app_types.char_p, self.space.wrap(42), 42) - self.check(app_types.unichar_p, self.space.wrap(42), 42) + self.check(app_types.unichar_p, self.space.wrap(42), 42) @@ -136,7 +136,7 @@ get_signed = get_all get_unsigned = get_all get_pointer = get_all - get_char = get_all + get_char = get_all get_unichar = get_all get_longlong = get_all get_char_p = get_all @@ -144,7 +144,7 @@ get_float = get_all get_singlefloat = get_all get_unsigned_which_fits_into_a_signed = get_all - + def convert(self, w_ffitype, val): self.val = val return self.do_and_wrap(w_ffitype) diff --git a/pypy/module/_rawffi/array.py b/pypy/module/_rawffi/array.py --- a/pypy/module/_rawffi/array.py +++ b/pypy/module/_rawffi/array.py @@ -181,7 +181,7 @@ start, stop = self.decodeslice(space, w_slice) ll_buffer = self.ll_buffer result = [ll_buffer[i] for i in range(start, stop)] - return space.wrap(''.join(result)) + return space.newbytes(''.join(result)) def setslice(self, space, w_slice, w_value): start, stop = self.decodeslice(space, w_slice) diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -570,7 +570,7 @@ s = rffi.charp2str(charp_addr) else: s = rffi.charp2strn(charp_addr, maxlength) - return space.wrap(s) + return space.newbytes(s) @unwrap_spec(address=r_uint, maxlength=int) def wcharp2unicode(space, address, maxlength=-1): @@ -588,7 +588,7 @@ if maxlength == -1: return charp2string(space, address) s = rffi.charpsize2str(rffi.cast(rffi.CCHARP, address), maxlength) - return space.wrap(s) + return space.newbytes(s) @unwrap_spec(address=r_uint, maxlength=int) def wcharp2rawunicode(space, address, maxlength=-1): diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py --- a/pypy/module/_socket/interp_func.py +++ b/pypy/module/_socket/interp_func.py @@ -209,7 +209,7 @@ buf = rsocket.inet_aton(ip) except SocketError as e: raise converted_error(space, e) - return space.wrap(buf) + return space.newbytes(buf) @unwrap_spec(packed=str) def inet_ntoa(space, packed): @@ -234,7 +234,7 @@ buf = rsocket.inet_pton(family, ip) except SocketError as e: raise converted_error(space, e) - return space.wrap(buf) + return space.newbytes(buf) @unwrap_spec(family=int, packed=str) def inet_ntop(space, family, packed): @@ -263,10 +263,10 @@ if space.is_w(w_host, space.w_None): host = None elif space.isinstance_w(w_host, space.w_str): - host = space.str_w(w_host) + host = space.bytes_w(w_host) elif space.isinstance_w(w_host, space.w_unicode): w_shost = space.call_method(w_host, "encode", space.wrap("idna")) - host = space.str_w(w_shost) + host = space.bytes_w(w_shost) else: raise oefmt(space.w_TypeError, "getaddrinfo() argument 1 must be string or None") @@ -277,7 +277,7 @@ elif space.isinstance_w(w_port, space.w_int) or space.isinstance_w(w_port, space.w_long): port = str(space.int_w(w_port)) elif space.isinstance_w(w_port, space.w_str): - port = space.str_w(w_port) + port = space.bytes_w(w_port) else: raise oefmt(space.w_TypeError, "getaddrinfo() argument 2 must be integer or string") diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py --- a/pypy/module/_socket/interp_socket.py +++ b/pypy/module/_socket/interp_socket.py @@ -296,7 +296,7 @@ except SocketError as e: raise converted_error(space, e) buflen = space.int_w(w_buflen) - return space.wrap(self.sock.getsockopt(level, optname, buflen)) + return space.newbytes(self.sock.getsockopt(level, optname, buflen)) def gettimeout_w(self, space): """gettimeout() -> timeout @@ -345,7 +345,7 @@ data = self.sock.recv(buffersize, flags) except SocketError as e: raise converted_error(space, e) - return space.wrap(data) + return space.newbytes(data) @unwrap_spec(buffersize='nonnegint', flags=int) def recvfrom_w(self, space, buffersize, flags=0): @@ -359,7 +359,7 @@ w_addr = addr_as_object(addr, self.sock.fd, space) else: w_addr = space.w_None - return space.newtuple([space.wrap(data), w_addr]) + return space.newtuple([space.newbytes(data), w_addr]) except SocketError as e: raise converted_error(space, e) @@ -436,7 +436,7 @@ except OperationError as e: if e.async(space): raise - optval = space.str_w(w_optval) + optval = space.bytes_w(w_optval) try: self.sock.setsockopt(level, optname, optval) except SocketError as e: diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py --- a/pypy/module/_sre/interp_sre.py +++ b/pypy/module/_sre/interp_sre.py @@ -36,11 +36,12 @@ def slice_w(space, ctx, start, end, w_default): if 0 <= start <= end: if isinstance(ctx, rsre_core.BufMatchContext): - return space.wrap(ctx._buffer.getslice(start, end, 1, end-start)) + return space.newbytes(ctx._buffer.getslice(start, end, 1, + end-start)) if isinstance(ctx, rsre_core.StrMatchContext): - return space.wrap(ctx._string[start:end]) + return space.newbytes(ctx._string[start:end]) elif isinstance(ctx, rsre_core.UnicodeMatchContext): - return space.wrap(ctx._unicodestr[start:end]) + return space.newunicode(ctx._unicodestr[start:end]) else: # unreachable raise SystemError @@ -242,7 +243,7 @@ space.isinstance_w(w_string, space.w_unicode) and literal) else: try: - filter_as_string = space.str_w(w_ptemplate) + filter_as_string = space.bytes_w(w_ptemplate) except OperationError as e: if e.async(space): raise @@ -331,15 +332,15 @@ strbuilder, unicodebuilder, last_pos, ctx.end) if use_builder: if strbuilder is not None: - return space.wrap(strbuilder.build()), n + return space.newbytes(strbuilder.build()), n else: assert unicodebuilder is not None - return space.wrap(unicodebuilder.build()), n + return space.newunicode(unicodebuilder.build()), n else: if space.isinstance_w(w_string, space.w_unicode): - w_emptystr = space.wrap(u'') + w_emptystr = space.newunicode(u'') else: - w_emptystr = space.wrap('') + w_emptystr = space.newbytes('') w_item = space.call_method(w_emptystr, 'join', space.newlist(sublist_w)) return w_item, n @@ -565,11 +566,11 @@ def fget_string(self, space): ctx = self.ctx if isinstance(ctx, rsre_core.BufMatchContext): - return space.wrap(ctx._buffer.as_str()) + return space.newbytes(ctx._buffer.as_str()) elif isinstance(ctx, rsre_core.StrMatchContext): - return space.wrap(ctx._string) + return space.newbytes(ctx._string) elif isinstance(ctx, rsre_core.UnicodeMatchContext): - return space.wrap(ctx._unicodestr) + return space.newunicode(ctx._unicodestr) else: raise SystemError diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py --- a/pypy/module/_ssl/interp_ssl.py +++ b/pypy/module/_ssl/interp_ssl.py @@ -666,7 +666,7 @@ length = libssl_SSL_get_peer_finished(self.ssl, buf, CB_MAXLEN) if length > 0: - return space.wrap(rffi.charpsize2str(buf, intmask(length))) + return space.newbytes(rffi.charpsize2str(buf, intmask(length))) def descr_get_context(self, space): return self.w_ctx @@ -707,7 +707,7 @@ if length < 0: raise _ssl_seterror(space, None, 0) try: - return space.wrap(rffi.charpsize2str(buf_ptr[0], length)) + return space.newbytes(rffi.charpsize2str(buf_ptr[0], length)) finally: libssl_OPENSSL_free(buf_ptr[0]) @@ -926,7 +926,7 @@ if length < 0: raise _ssl_seterror(space, None, 0) try: - w_value = space.wrap(rffi.charpsize2str(buf_ptr[0], length)) + w_value = space.newbytes(rffi.charpsize2str(buf_ptr[0], length)) w_value = space.call_method(w_value, "decode", space.wrap("utf-8")) finally: libssl_OPENSSL_free(buf_ptr[0]) @@ -1232,7 +1232,7 @@ w_ssl_socket, space.w_None, w_ctx) else: - w_servername = space.wrapbytes(rffi.charp2str(servername)) + w_servername = space.newbytes(rffi.charp2str(servername)) try: w_servername_idna = space.call_method( w_servername, 'decode', space.wrap('idna')) @@ -1778,7 +1778,7 @@ if not path: return space.w_None else: - return space.wrapbytes(rffi.charp2str(path)) + return space.newbytes(rffi.charp2str(path)) def get_default_verify_paths(space): return space.newtuple([ diff --git a/pypy/module/_ssl/interp_win32.py b/pypy/module/_ssl/interp_win32.py --- a/pypy/module/_ssl/interp_win32.py +++ b/pypy/module/_ssl/interp_win32.py @@ -74,7 +74,7 @@ def w_parseKeyUsage(space, pCertCtx, flags): with lltype.scoped_alloc(rwin32.LPDWORD.TO, 1) as size_ptr: - if not CertGetEnhancedKeyUsage(pCertCtx, flags, + if not CertGetEnhancedKeyUsage(pCertCtx, flags, lltype.nullptr(CERT_ENHKEY_USAGE), size_ptr): last_error = rwin32.lastSavedWindowsError() if last_error.winerror == CRYPT_E_NOT_FOUND: @@ -120,7 +120,7 @@ pCertCtx = CertEnumCertificatesInStore(hStore, pCertCtx) if not pCertCtx: break - w_cert = space.wrapbytes( + w_cert = space.newbytes( rffi.charpsize2str(pCertCtx.c_pbCertEncoded, intmask(pCertCtx.c_cbCertEncoded))) w_enc = w_certEncodingType(space, pCertCtx.c_dwCertEncodingType) @@ -162,7 +162,7 @@ pCrlCtx = CertEnumCRLsInStore(hStore, pCrlCtx) if not pCrlCtx: break - w_crl = space.wrapbytes( + w_crl = space.newbytes( rffi.charpsize2str(pCrlCtx.c_pbCrlEncoded, intmask(pCrlCtx.c_cbCrlEncoded))) w_enc = w_certEncodingType(space, pCrlCtx.c_dwCertEncodingType) diff --git a/pypy/module/_winreg/interp_winreg.py b/pypy/module/_winreg/interp_winreg.py --- a/pypy/module/_winreg/interp_winreg.py +++ b/pypy/module/_winreg/interp_winreg.py @@ -380,7 +380,7 @@ return space.newlist(l) else: # REG_BINARY and all other types - return space.wrap(rffi.charpsize2str(buf, buflen)) + return space.newbytes(rffi.charpsize2str(buf, buflen)) @unwrap_spec(value_name=str, typ=int) def SetValueEx(space, w_hkey, value_name, w_reserved, typ, w_value): diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py --- a/pypy/module/array/interp_array.py +++ b/pypy/module/array/interp_array.py @@ -225,11 +225,11 @@ """ size = self.len if size == 0: - return space.wrap('') + return space.newbytes('') cbuf = self._charbuf_start() s = rffi.charpsize2str(cbuf, size * self.itemsize) self._charbuf_stop() - return self.space.wrap(s) + return self.space.newbytes(s) def descr_fromstring(self, space, w_s): """ fromstring(string) @@ -263,7 +263,7 @@ except OverflowError: raise MemoryError w_item = space.call_method(w_f, 'read', space.wrap(size)) - item = space.str_w(w_item) + item = space.bytes_w(w_item) if len(item) < size: n = len(item) % self.itemsize elems = max(0, len(item) - (len(item) % self.itemsize)) @@ -338,10 +338,10 @@ else: args = [space.wrap(self.typecode)] try: - dct = space.getattr(self, space.wrap('__dict__')) + w_dict = space.getattr(self, space.wrap('__dict__')) except OperationError: - dct = space.w_None - return space.newtuple([space.type(self), space.newtuple(args), dct]) + w_dict = space.w_None + return space.newtuple([space.type(self), space.newtuple(args), w_dict]) def descr_copy(self, space): """ copy(array) diff --git a/pypy/module/binascii/interp_base64.py b/pypy/module/binascii/interp_base64.py --- a/pypy/module/binascii/interp_base64.py +++ b/pypy/module/binascii/interp_base64.py @@ -71,7 +71,7 @@ if leftbits != 0: raise_Error(space, "Incorrect padding") - return space.wrap(res.build()) + return space.newbytes(res.build()) # ____________________________________________________________ @@ -110,4 +110,4 @@ res.append(table_b2a_base64[(leftchar & 0xf) << 2]) res.append(PAD) res.append('\n') - return space.wrap(res.build()) + return space.newbytes(res.build()) diff --git a/pypy/module/binascii/interp_hexlify.py b/pypy/module/binascii/interp_hexlify.py --- a/pypy/module/binascii/interp_hexlify.py +++ b/pypy/module/binascii/interp_hexlify.py @@ -24,7 +24,7 @@ for c in data: res.append(_value2char(ord(c) >> 4)) res.append(_value2char(ord(c) & 0xf)) - return space.wrap(res.build()) + return space.newbytes(res.build()) # ____________________________________________________________ @@ -53,4 +53,4 @@ a = _char2value(space, hexstr[i]) b = _char2value(space, hexstr[i+1]) res.append(chr((a << 4) | b)) - return space.wrap(res.build()) + return space.newbytes(res.build()) diff --git a/pypy/module/binascii/interp_hqx.py b/pypy/module/binascii/interp_hqx.py --- a/pypy/module/binascii/interp_hqx.py +++ b/pypy/module/binascii/interp_hqx.py @@ -11,37 +11,37 @@ FAIL = 0x7d table_a2b_hqx = [ - #^@ ^A ^B ^C ^D ^E ^F ^G + #^@ ^A ^B ^C ^D ^E ^F ^G FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, - #\b \t \n ^K ^L \r ^N ^O + #\b \t \n ^K ^L \r ^N ^O FAIL, FAIL, SKIP, FAIL, FAIL, SKIP, FAIL, FAIL, - #^P ^Q ^R ^S ^T ^U ^V ^W + #^P ^Q ^R ^S ^T ^U ^V ^W FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, - #^X ^Y ^Z ^[ ^\ ^] ^^ ^_ + #^X ^Y ^Z ^[ ^\ ^] ^^ ^_ FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, - # ! " # $ % & ' + # ! " # $ % & ' FAIL, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - #( ) * + , - . / + #( ) * + , - . / 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, FAIL, FAIL, - #0 1 2 3 4 5 6 7 + #0 1 2 3 4 5 6 7 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, FAIL, - #8 9 : ; < = > ? + #8 9 : ; < = > ? 0x14, 0x15, DONE, FAIL, FAIL, FAIL, FAIL, FAIL, - #@ A B C D E F G + #@ A B C D E F G 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, - #H I J K L M N O + #H I J K L M N O 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, FAIL, - #P Q R S T U V W + #P Q R S T U V W 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, FAIL, - #X Y Z [ \ ] ^ _ + #X Y Z [ \ ] ^ _ 0x2C, 0x2D, 0x2E, 0x2F, FAIL, FAIL, FAIL, FAIL, - #` a b c d e f g + #` a b c d e f g 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, FAIL, - #h i j k l m n o + #h i j k l m n o 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, FAIL, FAIL, - #p q r s t u v w + #p q r s t u v w 0x3D, 0x3E, 0x3F, FAIL, FAIL, FAIL, FAIL, FAIL, - #x y z { | } ~ ^? + #x y z { | } ~ ^? FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, @@ -97,7 +97,7 @@ else: if pending_bits > 0: raise_Incomplete(space, 'String has incomplete number of bytes') - return space.newtuple([space.wrap(res.build()), space.wrap(done)]) + return space.newtuple([space.newbytes(res.build()), space.wrap(done)]) # ____________________________________________________________ @@ -128,7 +128,7 @@ if leftbits > 0: leftchar <<= (6 - leftbits) res.append(hqx_encoding[leftchar & 0x3f]) - return space.wrap(res.build()) + return space.newbytes(res.build()) # ____________________________________________________________ @@ -150,7 +150,7 @@ lastpushed = ord(c) else: if i == end: - raise_Incomplete(space, 'String ends with the RLE code \x90') + raise_Incomplete(space, 'String ends with the RLE code \\x90') count = ord(hexbin[i]) - 1 i += 1 if count < 0: @@ -158,9 +158,9 @@ lastpushed = 0x90 else: if lastpushed < 0: - raise_Error(space, 'String starts with the RLE code \x90') + raise_Error(space, 'String starts with the RLE code \\x90') res.append_multiple_char(chr(lastpushed), count) - return space.wrap(res.build()) + return space.newbytes(res.build()) # ____________________________________________________________ @@ -197,7 +197,7 @@ # string that rledecode_hqx() would expand back to 'data', there are # some programs somewhere that would start failing obscurely in rare # cases. - return space.wrap(res.build()) + return space.newbytes(res.build()) # ____________________________________________________________ diff --git a/pypy/module/binascii/interp_qp.py b/pypy/module/binascii/interp_qp.py --- a/pypy/module/binascii/interp_qp.py +++ b/pypy/module/binascii/interp_qp.py @@ -56,7 +56,7 @@ if header and c == '_': c = ' ' odata.append(c) - return space.wrap(odata.build()) + return space.newbytes(odata.build()) # ____________________________________________________________ @@ -159,4 +159,4 @@ odata.append(c) inp += 1 - return space.wrap(odata.build()) + return space.newbytes(odata.build()) diff --git a/pypy/module/binascii/interp_uu.py b/pypy/module/binascii/interp_uu.py --- a/pypy/module/binascii/interp_uu.py +++ b/pypy/module/binascii/interp_uu.py @@ -54,7 +54,7 @@ remaining = length - res.getlength() if remaining > 0: res.append_multiple_char('\x00', remaining) - return space.wrap(res.build()) + return space.newbytes(res.build()) # ____________________________________________________________ @@ -86,4 +86,4 @@ res.append(chr(0x20 + (C & 0x3F))) res.append('\n') - return space.wrap(res.build()) + return space.newbytes(res.build()) 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 @@ -557,7 +557,7 @@ datasize = len(data) if datasize == 0: - return self.space.wrap("") + return self.space.newbytes("") if not self.running: raise oefmt(self.space.w_ValueError, @@ -582,7 +582,7 @@ out.prepare_next_chunk() res = out.make_result_string() - return self.space.wrap(res) + return self.space.newbytes(res) def flush(self): if not self.running: @@ -602,7 +602,7 @@ out.prepare_next_chunk() res = out.make_result_string() - return self.space.wrap(res) + return self.space.newbytes(res) W_BZ2Compressor.typedef = TypeDef("BZ2Compressor", __doc__ = W_BZ2Compressor.__doc__, @@ -669,7 +669,7 @@ raise oefmt(self.space.w_EOFError, "end of stream was already found") if data == '': - return self.space.wrap('') + return self.space.newbytes('') in_bufsize = len(data) @@ -698,7 +698,7 @@ out.prepare_next_chunk() res = out.make_result_string() - return self.space.wrap(res) + return self.space.newbytes(res) W_BZ2Decompressor.typedef = TypeDef("BZ2Decompressor", diff --git a/pypy/module/cpyext/bytearrayobject.py b/pypy/module/cpyext/bytearrayobject.py --- a/pypy/module/cpyext/bytearrayobject.py +++ b/pypy/module/cpyext/bytearrayobject.py @@ -25,7 +25,7 @@ PyByteArrayObjectStruct = lltype.ForwardReference() PyByteArrayObject = lltype.Ptr(PyByteArrayObjectStruct) -PyByteArrayObjectFields = PyVarObjectFields +PyByteArrayObjectFields = PyVarObjectFields cpython_struct("PyByteArrayObject", PyByteArrayObjectFields, PyByteArrayObjectStruct) PyByteArray_Check, PyByteArray_CheckExact = build_type_checkers("ByteArray", "w_bytearray") @@ -46,9 +46,9 @@ """Create a new bytearray object from string and its length, len. On failure, NULL is returned.""" if char_p: - w_s = space.wrap(rffi.charpsize2str(char_p, length)) + w_s = space.newbytes(rffi.charpsize2str(char_p, length)) else: - w_s = space.wrap(length) + w_s = space.newint(length) w_buffer = space.call_function(space.w_bytearray, w_s) return make_ref(space, w_buffer) @@ -80,7 +80,7 @@ if space.isinstance_w(w_obj, space.w_bytearray): oldlen = space.len_w(w_obj) if newlen > oldlen: - space.call_method(w_obj, 'extend', space.wrap('\x00' * (newlen - oldlen))) + space.call_method(w_obj, 'extend', space.newbytes('\x00' * (newlen - oldlen))) elif oldlen > newlen: assert newlen >= 0 space.delslice(w_obj, space.wrap(newlen), space.wrap(oldlen)) diff --git a/pypy/module/cpyext/eval.py b/pypy/module/cpyext/eval.py --- a/pypy/module/cpyext/eval.py +++ b/pypy/module/cpyext/eval.py @@ -13,7 +13,7 @@ "PyCompilerFlags", (("cf_flags", rffi.INT),)) PyCompilerFlagsPtr = lltype.Ptr(PyCompilerFlags) -PyCF_MASK = (consts.CO_FUTURE_DIVISION | +PyCF_MASK = (consts.CO_FUTURE_DIVISION | consts.CO_FUTURE_ABSOLUTE_IMPORT | consts.CO_FUTURE_WITH_STATEMENT | consts.CO_FUTURE_PRINT_FUNCTION | @@ -94,7 +94,7 @@ Py_eval_input = 258 def compile_string(space, source, filename, start, flags=0): - w_source = space.wrap(source) + w_source = space.newbytes(source) start = rffi.cast(lltype.Signed, start) if start == Py_file_input: mode = 'exec' @@ -227,4 +227,4 @@ cf.c_cf_flags = rffi.cast(rffi.INT, flags) return result - + diff --git a/pypy/module/cpyext/pyfile.py b/pypy/module/cpyext/pyfile.py --- a/pypy/module/cpyext/pyfile.py +++ b/pypy/module/cpyext/pyfile.py @@ -23,7 +23,7 @@ try: w_readline = space.getattr(w_obj, space.wrap('readline')) except OperationError: - raise oefmt(space.w_TypeError, + raise oefmt(space.w_TypeError, "argument must be a file, or have a readline() method.") n = rffi.cast(lltype.Signed, n) @@ -41,7 +41,7 @@ On success, return a new file object that is opened on the file given by filename, with a file mode given by mode, where mode has the same semantics as the standard C routine fopen(). On failure, return NULL.""" - w_filename = space.wrap(rffi.charp2str(filename)) + w_filename = space.newbytes(rffi.charp2str(filename)) w_mode = space.wrap(rffi.charp2str(mode)) return space.call_method(space.builtin, 'file', w_filename, w_mode) diff --git a/pypy/module/cpyext/test/test_memoryobject.py b/pypy/module/cpyext/test/test_memoryobject.py --- a/pypy/module/cpyext/test/test_memoryobject.py +++ b/pypy/module/cpyext/test/test_memoryobject.py @@ -7,7 +7,7 @@ space.wrap((2, 7)))): py.test.skip("unsupported before Python 2.7") - w_hello = space.wrap("hello") + w_hello = space.newbytes("hello") w_view = api.PyMemoryView_FromObject(w_hello) w_bytes = space.call_method(w_view, "tobytes") assert space.unwrap(w_bytes) == "hello" diff --git a/pypy/module/cpyext/test/test_pyfile.py b/pypy/module/cpyext/test/test_pyfile.py --- a/pypy/module/cpyext/test/test_pyfile.py +++ b/pypy/module/cpyext/test/test_pyfile.py @@ -20,7 +20,7 @@ assert api.PyFile_CheckExact(w_file) assert not api.PyFile_Check(space.wrap("text")) - space.call_method(w_file, "write", space.wrap("text")) + space.call_method(w_file, "write", space.newbytes("text")) space.call_method(w_file, "close") assert (udir / "_test_file").read() == "text" diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py --- a/pypy/module/cpyext/unicodeobject.py +++ b/pypy/module/cpyext/unicodeobject.py @@ -372,10 +372,10 @@ if not encoding: # This tracks CPython 2.7, in CPython 3.4 'utf-8' is hardcoded instead encoding = PyUnicode_GetDefaultEncoding(space) + w_str = space.newbytes(rffi.charpsize2str(s, size)) w_encoding = space.wrap(rffi.charp2str(encoding)) - w_str = space.wrap(rffi.charpsize2str(s, size)) if errors: - w_errors = space.wrap(rffi.charp2str(errors)) + w_errors = space.newbytes(rffi.charp2str(errors)) else: w_errors = None return space.call_method(w_str, 'decode', w_encoding, w_errors) @@ -427,7 +427,7 @@ @cpython_api([CONST_STRING], PyObject) def PyUnicode_FromString(space, s): """Create a Unicode object from an UTF-8 encoded null-terminated char buffer""" - w_str = space.wrap(rffi.charp2str(s)) + w_str = space.newbytes(rffi.charp2str(s)) return space.call_method(w_str, 'decode', space.wrap("utf-8")) @cpython_api([CONST_STRING, Py_ssize_t], PyObject, result_is_ll=True) @@ -495,7 +495,7 @@ encoded string s. Return NULL if an exception was raised by the codec. """ - w_s = space.wrap(rffi.charpsize2str(s, size)) + w_s = space.newbytes(rffi.charpsize2str(s, size)) if errors: w_errors = space.wrap(rffi.charp2str(errors)) else: diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -44,6 +44,7 @@ def str_w(self, space): return NonConstant("foobar") + identifier_w = bytes_w = str_w def unicode_w(self, space): return NonConstant(u"foobar") @@ -195,7 +196,7 @@ "NOT_RPYTHON" raise NotImplementedError - def wrapbytes(self, x): + def newbytes(self, x): return w_some_obj() def wrap(self, x): diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py --- a/pypy/objspace/std/bytesobject.py +++ b/pypy/objspace/std/bytesobject.py @@ -578,7 +578,7 @@ def descr_str(self, space): if type(self) is W_BytesObject: return self - return wrapstr(space, self._value) + return W_BytesObject(self._value) def descr_hash(self, space): x = compute_hash(self._value) @@ -724,8 +724,8 @@ l = space.listview_bytes(w_list) if l is not None: if len(l) == 1: - return space.wrap(l[0]) - return space.wrap(self._val(space).join(l)) + return space.newbytes(l[0]) + return space.newbytes(self._val(space).join(l)) return self._StringMethods_descr_join(space, w_list) _StringMethods_descr_split = descr_split @@ -857,10 +857,6 @@ W_BytesObject.EMPTY = W_BytesObject('') -def wrapstr(space, s): - return W_BytesObject(s) - - W_BytesObject.typedef = TypeDef( "str", basestring_typedef, None, "read", __new__ = interp2app(W_BytesObject.descr_new), diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py --- a/pypy/objspace/std/objspace.py +++ b/pypy/objspace/std/objspace.py @@ -16,7 +16,7 @@ from pypy.objspace.std.boolobject import W_BoolObject from pypy.objspace.std.bufferobject import W_Buffer from pypy.objspace.std.bytearrayobject import W_BytearrayObject -from pypy.objspace.std.bytesobject import W_AbstractBytesObject, W_BytesObject, wrapstr +from pypy.objspace.std.bytesobject import W_AbstractBytesObject, W_BytesObject from pypy.objspace.std.complexobject import W_ComplexObject from pypy.objspace.std.dictmultiobject import W_DictMultiObject, W_DictObject from pypy.objspace.std.floatobject import W_FloatObject @@ -31,7 +31,7 @@ from pypy.objspace.std.sliceobject import W_SliceObject from pypy.objspace.std.tupleobject import W_AbstractTupleObject, W_TupleObject from pypy.objspace.std.typeobject import W_TypeObject, TypeCache -from pypy.objspace.std.unicodeobject import W_UnicodeObject, wrapunicode +from pypy.objspace.std.unicodeobject import W_UnicodeObject class StdObjSpace(ObjSpace): @@ -128,9 +128,6 @@ assert typedef is not None return self.fromcache(TypeCache).getorbuild(typedef) - def wrapbytes(self, x): - return wrapstr(self, x) - @specialize.argtype(1) def wrap(self, x): "Wraps the Python value 'x' into one of the wrapper classes." @@ -151,9 +148,9 @@ else: return self.newint(x) if isinstance(x, str): - return wrapstr(self, x) + return self.newbytes(x) if isinstance(x, unicode): - return wrapunicode(self, x) + return self.newunicode(x) if isinstance(x, float): return W_FloatObject(x) if isinstance(x, W_Root): @@ -323,6 +320,12 @@ def newbuffer(self, w_obj): return W_Buffer(w_obj) + def newbytes(self, s): + return W_BytesObject(s) + + def newunicode(self, uni): + return W_UnicodeObject(uni) + def type(self, w_obj): jit.promote(w_obj.__class__) return w_obj.getclass(self) diff --git a/pypy/objspace/std/test/test_bytesobject.py b/pypy/objspace/std/test/test_bytesobject.py --- a/pypy/objspace/std/test/test_bytesobject.py +++ b/pypy/objspace/std/test/test_bytesobject.py @@ -3,31 +3,31 @@ def teardown_method(self, method): pass - def test_str_w(self): - assert self.space.str_w(self.space.wrap("foo")) == "foo" + def test_bytes_w(self): + assert self.space.bytes_w(self.space.newbytes("foo")) == "foo" def test_equality(self): - w = self.space.wrap + w = self.space.newbytes assert self.space.eq_w(w('abc'), w('abc')) assert not self.space.eq_w(w('abc'), w('def')) def test_order_cmp(self): space = self.space - w = space.wrap + w = space.newbytes assert self.space.is_true(space.lt(w('a'), w('b'))) assert self.space.is_true(space.lt(w('a'), w('ab'))) assert self.space.is_true(space.le(w('a'), w('a'))) assert self.space.is_true(space.gt(w('a'), w(''))) def test_truth(self): - w = self.space.wrap + w = self.space.newbytes assert self.space.is_true(w('non-empty')) assert not self.space.is_true(w('')) def test_getitem(self): space = self.space w = space.wrap - w_str = w('abc') + w_str = space.newbytes('abc') assert self.space.eq_w(space.getitem(w_str, w(0)), w('a')) assert self.space.eq_w(space.getitem(w_str, w(-1)), w('c')) self.space.raises_w(space.w_IndexError, @@ -38,25 +38,26 @@ def test_slice(self): space = self.space w = space.wrap - w_str = w('abc') + wb = space.newbytes + w_str = wb('abc') w_slice = space.newslice(w(0), w(0), space.w_None) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('')) w_slice = space.newslice(w(0), w(1), space.w_None) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('a')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('a')) w_slice = space.newslice(w(0), w(10), space.w_None) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('abc')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('abc')) w_slice = space.newslice(space.w_None, space.w_None, space.w_None) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('abc')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('abc')) w_slice = space.newslice(space.w_None, w(-1), space.w_None) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('ab')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('ab')) w_slice = space.newslice(w(-1), space.w_None, space.w_None) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('c')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('c')) def test_extended_slice(self): space = self.space @@ -66,23 +67,24 @@ return w_None = space.w_None w = space.wrap - w_str = w('hello') + wb = space.newbytes + w_str = wb('hello') w_slice = space.newslice(w_None, w_None, w(1)) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('hello')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('hello')) w_slice = space.newslice(w_None, w_None, w(-1)) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('olleh')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('olleh')) w_slice = space.newslice(w_None, w_None, w(2)) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('hlo')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('hlo')) w_slice = space.newslice(w(1), w_None, w(2)) - assert self.space.eq_w(space.getitem(w_str, w_slice), w('el')) + assert self.space.eq_w(space.getitem(w_str, w_slice), wb('el')) def test_listview_bytes(self): - w_str = self.space.wrap('abcd') - assert self.space.listview_bytes(w_str) == list("abcd") + w_bytes = self.space.newbytes('abcd') + assert self.space.listview_bytes(w_bytes) == list("abcd") class AppTestBytesObject: @@ -110,28 +112,29 @@ assert str(exc_info.value) == expected def test_split(self): - assert "".split() == [] - assert "".split('x') == [''] - assert " ".split() == [] - assert "a".split() == ['a'] + assert b"".split() == [] + assert b"".split(b'x') == [b''] + assert b" ".split() == [] + assert b"a".split() == [b'a'] assert "a".split("a", 1) == ['', ''] - assert " ".split(" ", 1) == ['', ''] - assert "aa".split("a", 2) == ['', '', ''] - assert " a ".split() == ['a'] - assert "a b c".split() == ['a','b','c'] - assert 'this is the split function'.split() == ['this', 'is', 'the', 'split', 'function'] - assert 'a|b|c|d'.split('|') == ['a', 'b', 'c', 'd'] - assert 'a|b|c|d'.split('|', 2) == ['a', 'b', 'c|d'] - assert 'a b c d'.split(None, 1) == ['a', 'b c d'] - assert 'a b c d'.split(None, 2) == ['a', 'b', 'c d'] - assert 'a b c d'.split(None, 3) == ['a', 'b', 'c', 'd'] - assert 'a b c d'.split(None, 4) == ['a', 'b', 'c', 'd'] - assert 'a b c d'.split(None, 0) == ['a b c d'] - assert 'a b c d'.split(None, 2) == ['a', 'b', 'c d'] - assert 'a b c d '.split() == ['a', 'b', 'c', 'd'] - assert 'a//b//c//d'.split('//') == ['a', 'b', 'c', 'd'] - assert 'endcase test'.split('test') == ['endcase ', ''] - raises(ValueError, 'abc'.split, '') + assert b" ".split(b" ", 1) == [b'', b''] + assert b"aa".split(b"a", 2) == [b'', b'', b''] + assert b" a ".split() == [b'a'] + assert b"a b c".split() == [b'a',b'b',b'c'] + assert b'this is the split function'.split() == [ + b'this', b'is', b'the', b'split', b'function'] + assert b'a|b|c|d'.split(b'|') == [b'a', b'b', b'c', b'd'] + assert b'a|b|c|d'.split(b'|', 2) == [b'a', b'b', b'c|d'] + assert b'a b c d'.split(None, 1) == [b'a', b'b c d'] + assert b'a b c d'.split(None, 2) == [b'a', b'b', b'c d'] + assert b'a b c d'.split(None, 3) == [b'a', b'b', b'c', b'd'] + assert b'a b c d'.split(None, 4) == [b'a', b'b', b'c', b'd'] + assert b'a b c d'.split(None, 0) == [b'a b c d'] + assert b'a b c d'.split(None, 2) == [b'a', b'b', b'c d'] + assert b'a b c d '.split() == [b'a', b'b', b'c', b'd'] + assert b'a//b//c//d'.split(b'//') == [b'a', b'b', b'c', b'd'] + assert b'endcase test'.split(b'test') == [b'endcase ', b''] + raises(ValueError, b'abc'.split, b'') def test_rsplit(self): assert "".rsplit() == [] @@ -141,100 +144,100 @@ assert " ".rsplit(" ", 1) == ['', ''] assert "aa".rsplit("a", 2) == ['', '', ''] assert " a ".rsplit() == ['a'] - assert "a b c".rsplit() == ['a','b','c'] + assert b"a b c".rsplit() == [b'a',b'b',b'c'] assert 'this is the rsplit function'.rsplit() == ['this', 'is', 'the', 'rsplit', 'function'] - assert 'a|b|c|d'.rsplit('|') == ['a', 'b', 'c', 'd'] - assert 'a|b|c|d'.rsplit('|', 2) == ['a|b', 'c', 'd'] - assert 'a b c d'.rsplit(None, 1) == ['a b c', 'd'] - assert 'a b c d'.rsplit(None, 2) == ['a b', 'c', 'd'] - assert 'a b c d'.rsplit(None, 3) == ['a', 'b', 'c', 'd'] - assert 'a b c d'.rsplit(None, 4) == ['a', 'b', 'c', 'd'] - assert 'a b c d'.rsplit(None, 0) == ['a b c d'] - assert 'a b c d'.rsplit(None, 2) == ['a b', 'c', 'd'] - assert 'a b c d '.rsplit() == ['a', 'b', 'c', 'd'] - assert 'a//b//c//d'.rsplit('//') == ['a', 'b', 'c', 'd'] - assert 'endcase test'.rsplit('test') == ['endcase ', ''] - raises(ValueError, 'abc'.rsplit, '') + assert b'a|b|c|d'.rsplit(b'|') == [b'a', b'b', b'c', b'd'] + assert b'a|b|c|d'.rsplit(b'|', 2) == [b'a|b', b'c', b'd'] + assert b'a b c d'.rsplit(None, 1) == [b'a b c', b'd'] + assert b'a b c d'.rsplit(None, 2) == [b'a b', b'c', b'd'] + assert b'a b c d'.rsplit(None, 3) == [b'a', b'b', b'c', b'd'] + assert b'a b c d'.rsplit(None, 4) == [b'a', b'b', b'c', b'd'] + assert b'a b c d'.rsplit(None, 0) == [b'a b c d'] + assert b'a b c d'.rsplit(None, 2) == [b'a b', b'c', b'd'] + assert b'a b c d '.rsplit() == [b'a', b'b', b'c', b'd'] + assert b'a//b//c//d'.rsplit(b'//') == [b'a', b'b', b'c', b'd'] + assert b'endcase test'.rsplit(b'test') == [b'endcase ', b''] + raises(ValueError, b'abc'.rsplit, b'') def test_split_splitchar(self): assert "/a/b/c".split('/') == ['','a','b','c'] def test_title(self): - assert "brown fox".title() == "Brown Fox" - assert "!brown fox".title() == "!Brown Fox" - assert "bROWN fOX".title() == "Brown Fox" - assert "Brown Fox".title() == "Brown Fox" - assert "bro!wn fox".title() == "Bro!Wn Fox" + assert b"brown fox".title() == b"Brown Fox" + assert b"!brown fox".title() == b"!Brown Fox" + assert b"bROWN fOX".title() == b"Brown Fox" + assert b"Brown Fox".title() == b"Brown Fox" + assert b"bro!wn fox".title() == b"Bro!Wn Fox" def test_istitle(self): - assert "".istitle() == False - assert "!".istitle() == False - assert "!!".istitle() == False - assert "brown fox".istitle() == False - assert "!brown fox".istitle() == False - assert "bROWN fOX".istitle() == False - assert "Brown Fox".istitle() == True - assert "bro!wn fox".istitle() == False - assert "Bro!wn fox".istitle() == False - assert "!brown Fox".istitle() == False - assert "!Brown Fox".istitle() == True - assert "Brow&&&&N Fox".istitle() == True - assert "!Brow&&&&n Fox".istitle() == False + assert b"".istitle() == False + assert b"!".istitle() == False + assert b"!!".istitle() == False + assert b"brown fox".istitle() == False + assert b"!brown fox".istitle() == False + assert b"bROWN fOX".istitle() == False + assert b"Brown Fox".istitle() == True + assert b"bro!wn fox".istitle() == False + assert b"Bro!wn fox".istitle() == False + assert b"!brown Fox".istitle() == False + assert b"!Brown Fox".istitle() == True + assert b"Brow&&&&N Fox".istitle() == True + assert b"!Brow&&&&n Fox".istitle() == False def test_capitalize(self): - assert "brown fox".capitalize() == "Brown fox" - assert ' hello '.capitalize() == ' hello ' - assert 'Hello '.capitalize() == 'Hello ' - assert 'hello '.capitalize() == 'Hello ' - assert 'aaaa'.capitalize() == 'Aaaa' - assert 'AaAa'.capitalize() == 'Aaaa' + assert b"brown fox".capitalize() == b"Brown fox" + assert b' hello '.capitalize() == b' hello ' + assert b'Hello '.capitalize() == b'Hello ' + assert b'hello '.capitalize() == b'Hello ' + assert b'aaaa'.capitalize() == b'Aaaa' + assert b'AaAa'.capitalize() == b'Aaaa' def test_rjust(self): - s = "abc" + s = b"abc" assert s.rjust(2) == s assert s.rjust(3) == s - assert s.rjust(4) == " " + s - assert s.rjust(5) == " " + s - assert 'abc'.rjust(10) == ' abc' - assert 'abc'.rjust(6) == ' abc' - assert 'abc'.rjust(3) == 'abc' - assert 'abc'.rjust(2) == 'abc' - assert 'abc'.rjust(5, '*') == '**abc' # Python 2.4 + assert s.rjust(4) == b" " + s + assert s.rjust(5) == b" " + s + assert b'abc'.rjust(10) == b' abc' + assert b'abc'.rjust(6) == b' abc' + assert b'abc'.rjust(3) == b'abc' + assert b'abc'.rjust(2) == b'abc' + assert b'abc'.rjust(5, b'*') == b'**abc' # Python 2.4 raises(TypeError, 'abc'.rjust, 5, 'xx') def test_ljust(self): - s = "abc" + s = b"abc" assert s.ljust(2) == s assert s.ljust(3) == s - assert s.ljust(4) == s + " " - assert s.ljust(5) == s + " " - assert 'abc'.ljust(10) == 'abc ' - assert 'abc'.ljust(6) == 'abc ' - assert 'abc'.ljust(3) == 'abc' - assert 'abc'.ljust(2) == 'abc' - assert 'abc'.ljust(5, '*') == 'abc**' # Python 2.4 + assert s.ljust(4) == s + b" " + assert s.ljust(5) == s + b" " + assert b'abc'.ljust(10) == b'abc ' + assert b'abc'.ljust(6) == b'abc ' + assert b'abc'.ljust(3) == b'abc' + assert b'abc'.ljust(2) == b'abc' + assert b'abc'.ljust(5, b'*') == b'abc**' # Python 2.4 raises(TypeError, 'abc'.ljust, 6, '') def test_replace(self): - assert 'one!two!three!'.replace('!', '@', 1) == 'one@two!three!' - assert 'one!two!three!'.replace('!', '') == 'onetwothree' - assert 'one!two!three!'.replace('!', '@', 2) == 'one@two@three!' - assert 'one!two!three!'.replace('!', '@', 3) == 'one@two@three@' - assert 'one!two!three!'.replace('!', '@', 4) == 'one@two@three@' - assert 'one!two!three!'.replace('!', '@', 0) == 'one!two!three!' - assert 'one!two!three!'.replace('!', '@') == 'one@two@three@' - assert 'one!two!three!'.replace('x', '@') == 'one!two!three!' - assert 'one!two!three!'.replace('x', '@', 2) == 'one!two!three!' - assert 'abc'.replace('', '-') == '-a-b-c-' - assert 'abc'.replace('', '-', 3) == '-a-b-c' - assert 'abc'.replace('', '-', 0) == 'abc' - assert ''.replace('', '') == '' - assert ''.replace('', 'a') == 'a' - assert 'abc'.replace('ab', '--', 0) == 'abc' - assert 'abc'.replace('xy', '--') == 'abc' - assert '123'.replace('123', '') == '' - assert '123123'.replace('123', '') == '' - assert '123x123'.replace('123', '') == 'x' + assert b'one!two!three!'.replace(b'!', b'@', 1) == b'one@two!three!' + assert b'one!two!three!'.replace(b'!', b'') == b'onetwothree' + assert b'one!two!three!'.replace(b'!', b'@', 2) == b'one@two@three!' + assert b'one!two!three!'.replace(b'!', b'@', 3) == b'one@two@three@' + assert b'one!two!three!'.replace(b'!', b'@', 4) == b'one@two@three@' + assert b'one!two!three!'.replace(b'!', b'@', 0) == b'one!two!three!' + assert b'one!two!three!'.replace(b'!', b'@') == b'one@two@three@' + assert b'one!two!three!'.replace(b'x', b'@') == b'one!two!three!' + assert b'one!two!three!'.replace(b'x', b'@', 2) == b'one!two!three!' + assert b'abc'.replace(b'', b'-') == b'-a-b-c-' + assert b'abc'.replace(b'', b'-', 3) == b'-a-b-c' + assert b'abc'.replace(b'', b'-', 0) == b'abc' + assert b''.replace(b'', b'') == b'' + assert b''.replace(b'', b'a') == b'a' + assert b'abc'.replace(b'ab', b'--', 0) == b'abc' + assert b'abc'.replace(b'xy', b'--') == b'abc' + assert b'123'.replace(b'123', b'') == b'' + assert b'123123'.replace(b'123', b'') == b'' + assert b'123x123'.replace(b'123', b'') == b'x' def test_replace_buffer(self): assert 'one'.replace(buffer('o'), buffer('n'), 1) == 'nne' @@ -245,23 +248,23 @@ assert s.strip() == "a b" assert s.rstrip() == " a b" assert s.lstrip() == "a b " - assert 'xyzzyhelloxyzzy'.strip('xyz') == 'hello' - assert 'xyzzyhelloxyzzy'.lstrip('xyz') == 'helloxyzzy' - assert 'xyzzyhelloxyzzy'.rstrip('xyz') == 'xyzzyhello' + assert b'xyzzyhelloxyzzy'.strip(b'xyz') == b'hello' + assert b'xyzzyhelloxyzzy'.lstrip(b'xyz') == b'helloxyzzy' + assert b'xyzzyhelloxyzzy'.rstrip(b'xyz') == b'xyzzyhello' def test_zfill(self): - assert '123'.zfill(2) == '123' - assert '123'.zfill(3) == '123' - assert '123'.zfill(4) == '0123' - assert '+123'.zfill(3) == '+123' - assert '+123'.zfill(4) == '+123' - assert '+123'.zfill(5) == '+0123' - assert '-123'.zfill(3) == '-123' - assert '-123'.zfill(4) == '-123' - assert '-123'.zfill(5) == '-0123' - assert ''.zfill(3) == '000' - assert '34'.zfill(1) == '34' - assert '34'.zfill(4) == '0034' + assert b'123'.zfill(2) == b'123' + assert b'123'.zfill(3) == b'123' + assert b'123'.zfill(4) == b'0123' + assert b'+123'.zfill(3) == b'+123' + assert b'+123'.zfill(4) == b'+123' + assert b'+123'.zfill(5) == b'+0123' + assert b'-123'.zfill(3) == b'-123' + assert b'-123'.zfill(4) == b'-123' + assert b'-123'.zfill(5) == b'-0123' + assert b''.zfill(3) == b'000' + assert b'34'.zfill(1) == b'34' + assert b'34'.zfill(4) == b'0034' def test_center(self): s="a b" @@ -275,251 +278,251 @@ assert s.center(7) == " a b " assert s.center(8) == " a b " assert s.center(9) == " a b " - assert 'abc'.center(10) == ' abc ' - assert 'abc'.center(6) == ' abc ' - assert 'abc'.center(3) == 'abc' - assert 'abc'.center(2) == 'abc' - assert 'abc'.center(5, '*') == '*abc*' # Python 2.4 - raises(TypeError, 'abc'.center, 4, 'cba') - assert ' abc'.center(7) == ' abc ' + assert b'abc'.center(10) == b' abc ' + assert b'abc'.center(6) == b' abc ' + assert b'abc'.center(3) == b'abc' + assert b'abc'.center(2) == b'abc' + assert b'abc'.center(5, b'*') == b'*abc*' # Python 2.4 + raises(TypeError, b'abc'.center, 4, b'cba') + assert b' abc'.center(7) == b' abc ' def test_count(self): - assert "".count("x") ==0 - assert "".count("") ==1 - assert "Python".count("") ==7 - assert "ab aaba".count("ab") ==2 - assert 'aaa'.count('a') == 3 - assert 'aaa'.count('b') == 0 - assert 'aaa'.count('a', -1) == 1 - assert 'aaa'.count('a', -10) == 3 - assert 'aaa'.count('a', 0, -1) == 2 - assert 'aaa'.count('a', 0, -10) == 0 - assert 'ababa'.count('aba') == 1 + assert b"".count(b"x") ==0 + assert b"".count(b"") ==1 + assert b"Python".count(b"") ==7 + assert b"ab aaba".count(b"ab") ==2 + assert b'aaa'.count(b'a') == 3 + assert b'aaa'.count(b'b') == 0 + assert b'aaa'.count(b'a', -1) == 1 + assert b'aaa'.count(b'a', -10) == 3 + assert b'aaa'.count(b'a', 0, -1) == 2 + assert b'aaa'.count(b'a', 0, -10) == 0 + assert b'ababa'.count(b'aba') == 1 def test_startswith(self): - assert 'ab'.startswith('ab') is True - assert 'ab'.startswith('a') is True - assert 'ab'.startswith('') is True - assert 'x'.startswith('a') is False - assert 'x'.startswith('x') is True - assert ''.startswith('') is True - assert ''.startswith('a') is False - assert 'x'.startswith('xx') is False - assert 'y'.startswith('xx') is False + assert b'ab'.startswith(b'ab') is True + assert b'ab'.startswith(b'a') is True + assert b'ab'.startswith(b'') is True + assert b'x'.startswith(b'a') is False + assert b'x'.startswith(b'x') is True + assert b''.startswith(b'') is True + assert b''.startswith(b'a') is False + assert b'x'.startswith(b'xx') is False + assert b'y'.startswith(b'xx') is False def test_startswith_more(self): - assert 'ab'.startswith('a', 0) is True - assert 'ab'.startswith('a', 1) is False - assert 'ab'.startswith('b', 1) is True - assert 'abc'.startswith('bc', 1, 2) is False - assert 'abc'.startswith('c', -1, 4) is True + assert b'ab'.startswith(b'a', 0) is True + assert b'ab'.startswith(b'a', 1) is False + assert b'ab'.startswith(b'b', 1) is True + assert b'abc'.startswith(b'bc', 1, 2) is False + assert b'abc'.startswith(b'c', -1, 4) is True def test_startswith_too_large(self): - assert 'ab'.startswith('b', 1) is True - assert 'ab'.startswith('', 2) is True - assert 'ab'.startswith('', 3) is False - assert 'ab'.endswith('b', 1) is True - assert 'ab'.endswith('', 2) is True - assert 'ab'.endswith('', 3) is False + assert b'ab'.startswith(b'b', 1) is True + assert b'ab'.startswith(b'', 2) is True + assert b'ab'.startswith(b'', 3) is False + assert b'ab'.endswith(b'b', 1) is True + assert b'ab'.endswith(b'', 2) is True + assert b'ab'.endswith(b'', 3) is False def test_startswith_tuples(self): - assert 'hello'.startswith(('he', 'ha')) - assert not 'hello'.startswith(('lo', 'llo')) - assert 'hello'.startswith(('hellox', 'hello')) - assert not 'hello'.startswith(()) - assert 'helloworld'.startswith(('hellowo', 'rld', 'lowo'), 3) - assert not 'helloworld'.startswith(('hellowo', 'ello', 'rld'), 3) - assert 'hello'.startswith(('lo', 'he'), 0, -1) - assert not 'hello'.startswith(('he', 'hel'), 0, 1) - assert 'hello'.startswith(('he', 'hel'), 0, 2) - raises(TypeError, 'hello'.startswith, (42,)) + assert b'hello'.startswith((b'he', b'ha')) + assert not b'hello'.startswith((b'lo', b'llo')) + assert b'hello'.startswith((b'hellox', b'hello')) + assert not b'hello'.startswith(()) + assert b'helloworld'.startswith((b'hellowo', b'rld', b'lowo'), 3) + assert not b'helloworld'.startswith((b'hellowo', b'ello', b'rld'), 3) + assert b'hello'.startswith((b'lo', b'he'), 0, -1) + assert not b'hello'.startswith((b'he', b'hel'), 0, 1) + assert b'hello'.startswith((b'he', b'hel'), 0, 2) + raises(TypeError, b'hello'.startswith, (42,)) def test_endswith(self): - assert 'ab'.endswith('ab') is True - assert 'ab'.endswith('b') is True - assert 'ab'.endswith('') is True - assert 'x'.endswith('a') is False - assert 'x'.endswith('x') is True - assert ''.endswith('') is True - assert ''.endswith('a') is False - assert 'x'.endswith('xx') is False - assert 'y'.endswith('xx') is False + assert b'ab'.endswith(b'ab') is True + assert b'ab'.endswith(b'b') is True + assert b'ab'.endswith(b'') is True + assert b'x'.endswith(b'a') is False + assert b'x'.endswith(b'x') is True + assert b''.endswith(b'') is True + assert b''.endswith(b'a') is False + assert b'x'.endswith(b'xx') is False + assert b'y'.endswith(b'xx') is False def test_endswith_more(self): - assert 'abc'.endswith('ab', 0, 2) is True - assert 'abc'.endswith('bc', 1) is True - assert 'abc'.endswith('bc', 2) is False - assert 'abc'.endswith('b', -3, -1) is True + assert b'abc'.endswith(b'ab', 0, 2) is True + assert b'abc'.endswith(b'bc', 1) is True + assert b'abc'.endswith(b'bc', 2) is False + assert b'abc'.endswith(b'b', -3, -1) is True def test_endswith_tuple(self): - assert not 'hello'.endswith(('he', 'ha')) - assert 'hello'.endswith(('lo', 'llo')) - assert 'hello'.endswith(('hellox', 'hello')) - assert not 'hello'.endswith(()) - assert 'helloworld'.endswith(('hellowo', 'rld', 'lowo'), 3) - assert not 'helloworld'.endswith(('hellowo', 'ello', 'rld'), 3, -1) - assert 'hello'.endswith(('hell', 'ell'), 0, -1) - assert not 'hello'.endswith(('he', 'hel'), 0, 1) - assert 'hello'.endswith(('he', 'hell'), 0, 4) - raises(TypeError, 'hello'.endswith, (42,)) + assert not b'hello'.endswith((b'he', b'ha')) + assert b'hello'.endswith((b'lo', b'llo')) + assert b'hello'.endswith((b'hellox', b'hello')) + assert not b'hello'.endswith(()) + assert b'helloworld'.endswith((b'hellowo', b'rld', b'lowo'), 3) + assert not b'helloworld'.endswith((b'hellowo', b'ello', b'rld'), 3, -1) + assert b'hello'.endswith((b'hell', b'ell'), 0, -1) + assert not b'hello'.endswith((b'he', b'hel'), 0, 1) + assert b'hello'.endswith((b'he', b'hell'), 0, 4) + raises(TypeError, b'hello'.endswith, (42,)) def test_expandtabs(self): import sys _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit