Commit Graph

213 Commits

Author SHA1 Message Date
Mark Dickinson ae5259171b
Fix bytes.__bytes__ to not truncate at a zero byte (GH-27902) 2021-08-23 15:24:12 +01:00
Dong-hee Na 24b63c695a
bpo-24234: Implement bytes.__bytes__ (GH-27901) 2021-08-23 19:01:51 +09:00
Nikita Sobolev a2ce538e16
bpo-44891: Tests `id` preserving on `* 1` for `str` and `bytes` (GH-27745)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2021-08-13 12:36:22 +02:00
Tobias Holl 61d8c54f43
bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208)
Before, using the * operator to repeat a bytearray would copy data from the start of
the internal buffer (ob_bytes) and not from the start of the actual data (ob_start).
2021-01-13 18:16:40 +02:00
Ronald Oussoren 41761933c1
bpo-41100: Support macOS 11 and Apple Silicon (GH-22855)
Co-authored-by:  Lawrence D’Anna <lawrence_danna@apple.com>

* Add support for macOS 11 and Apple Silicon (aka arm64)
   
  As a side effect of this work use the system copy of libffi on macOS, and remove the vendored copy

* Support building on recent versions of macOS while deploying to older versions

  This allows building installers on macOS 11 while still supporting macOS 10.9.
2020-11-08 10:05:27 +01:00
Hai Shi fcce8c649a
bpo-40275: Use new test.support helper submodules in tests (GH-21772) 2020-08-07 23:55:35 +02:00
Hai Shi a089d21df1
bpo-40275: Use new test.support helper submodules in tests (GH-21315) 2020-07-06 11:15:08 +02:00
Bruce Merry d07d9f4c43
bpo-36051: Drop GIL during large bytes.join() (GH-17757)
Improve multi-threaded performance by dropping the GIL in the fast path
of bytes.join. To avoid increasing overhead for small joins, it is only
done if the output size exceeds a threshold.
2020-01-29 16:09:24 +09:00
Sergey Fedoseev 92709a263e bpo-37840: Fix handling of negative indices in bytearray_getitem() (GH-15250) 2019-09-09 09:28:34 -07:00
Victor Stinner 22eb689cf3
bpo-37388: Development mode check encoding and errors (GH-14341)
In development mode and in debug build, encoding and errors arguments
are now checked on string encoding and decoding operations. Examples:
open(), str.encode() and bytes.decode().

By default, for best performances, the errors argument is only
checked at the first encoding/decoding error, and the encoding
argument is sometimes ignored for empty strings.
2019-06-26 00:51:05 +02:00
Gregory P. Smith 0c2f930564
bpo-22385: Support output separators in hex methods. (#13578)
* bpo-22385: Support output separators in hex methods.

Also in binascii.hexlify aka b2a_hex.

The underlying implementation behind all hex generation in CPython uses the
same pystrhex.c implementation.  This adds support to bytes, bytearray,
and memoryview objects.

The binascii module functions exist rather than being slated for deprecation
because they return bytes rather than requiring an intermediate step through a
str object.

This change was inspired by MicroPython which supports sep in its binascii
implementation (and does not yet support the .hex methods).

https://bugs.python.org/issue22385
2019-05-29 11:46:58 -07:00
Zackery Spytz 14514d9084 bpo-36946: Fix possible signed integer overflow when handling slices. (GH-13375)
The final addition (cur += step) may overflow, so use size_t for "cur".
"cur" is always positive (even for negative steps), so it is safe to use
size_t here.

Co-Authored-By: Martin Panter <vadmium+py@gmail.com>
2019-05-17 10:13:03 +03:00
Serhiy Storchaka 8e79e6e56f
Fix syntax warnings in tests introduced in bpo-15248. (GH-11932) 2019-02-19 13:49:09 +02:00
Serhiy Storchaka 44cc4822bb
bpo-33817: Fix _PyBytes_Resize() for empty bytes object. (GH-11516)
Add also tests for PyUnicode_FromFormat() and PyBytes_FromFormat()
with empty result.
2019-01-12 09:22:29 +02:00
Serhiy Storchaka 2c2044e789
bpo-34984: Improve error messages for bytes and bytearray constructors. (GH-9874) 2018-10-21 15:29:12 +03:00
Serhiy Storchaka 914f9a078f
bpo-34973: Fix crash in bytes constructor. (GH-9841)
Constructing bytes from mutating list could cause a crash.
2018-10-21 15:25:53 +03:00
Serhiy Storchaka e890421e33
bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852)
bytes and bytearray constructors converted unexpected exceptions
(e.g. MemoryError and KeyboardInterrupt) to TypeError.
2018-10-15 00:02:57 +03:00
Serhiy Storchaka 1a997eb291
Add new tests for bytes and bytearray constructors. (GH-9843)
Covered all special cases: bytes, tuple, list, differend
kinds of iterables and iterators.
2018-10-13 20:39:45 +03:00
Serhiy Storchaka a2314283ff
bpo-20047: Make bytearray methods partition() and rpartition() rejecting (#4158)
separators that are not bytes-like objects.
2017-10-29 02:11:54 +03:00
Serhiy Storchaka 604e74c6be bpo-20552: Use specific asserts in bytes tests (#790) 2017-03-27 12:59:07 +02:00
Xiang Zhang b76ad5121e bpo-29714: Fix a regression that bytes format may fail when containing zero bytes inside. (GH-499) 2017-03-06 17:17:05 +08:00
INADA Naoki 7ed28a8914 Merge 3.6 2017-01-06 17:44:43 +09:00
INADA Naoki a634e23209 Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception. 2017-01-06 17:32:01 +09:00
Serhiy Storchaka dd1da7f74a Issue #28927: bytes.fromhex() and bytearray.fromhex() now ignore all ASCII
whitespace, not only spaces.  Patch by Robert Xiao.
2016-12-19 18:51:37 +02:00
Serhiy Storchaka 7984bff52a Issue #28385: An error message when non-empty format spec is passed to
object.__format__ now contains the name of actual type.
2016-10-30 19:37:46 +02:00
Serhiy Storchaka d1af5effc2 Issue #28385: An error message when non-empty format spec is passed to
object.__format__ now contains the name of actual type.
2016-10-30 19:33:54 +02:00
Serhiy Storchaka c49a516ae9 Remove old typo.
Initially (e0b7e34b5971) it should be \udef0, but after 52a77ef069cd
(issue #3672) lone surrogates are not accepted and should be removed.
2016-09-08 15:47:27 +03:00
Martin Panter 1b6c6da85d Issue #27506: Support bytes/bytearray.translate() delete as keyword argument
Patch by Xiang Zhang.
2016-08-27 08:35:02 +00:00
Guido van Rossum 97c1adf393 Anti-registration of various ABC methods.
- Issue #25958: Support "anti-registration" of special methods from
  various ABCs, like __hash__, __iter__ or __len__.  All these (and
  several more) can be set to None in an implementation class and the
  behavior will be as if the method is not defined at all.
  (Previously, this mechanism existed only for __hash__, to make
  mutable classes unhashable.)  Code contributed by Andrew Barnert and
  Ivan Levkivskyi.
2016-08-18 09:22:23 -07:00
Serhiy Storchaka f9efb8b18b Issue #27474: Unified error messages in the __contains__ method of bytes and
bytearray for integers in and out of the Py_ssize_t range.
Patch by Xiang Zhang.
2016-07-10 12:37:30 +03:00
Serhiy Storchaka 6c94d10a19 Issue #27443: __length_hint__() of bytearray itearator no longer return
negative integer for resized bytearray.
2016-07-03 14:42:17 +03:00
Serhiy Storchaka af65872da2 Issue #27443: __length_hint__() of bytearray itearator no longer return
negative integer for resized bytearray.
2016-07-03 14:41:36 +03:00
Serhiy Storchaka 0855e706aa Issue #27007: The fromhex() class methods of bytes and bytearray subclasses
now return an instance of corresponding subclass.
2016-07-01 17:22:31 +03:00
Serhiy Storchaka 4b23494ded Issue #27039: Fixed bytearray.remove() for values greater than 127.
Based on patch by Joe Jevnik.
2016-05-16 22:24:03 +03:00
Serhiy Storchaka 7bf36dace8 Issue #27039: Fixed bytearray.remove() for values greater than 127.
Patch by Joe Jevnik.
2016-05-16 22:15:38 +03:00
Serhiy Storchaka e78592d42c Make bytes and bytearray subclass tests compatible with base types tests. 2016-05-12 12:33:21 +03:00
Serhiy Storchaka 3fa86a0612 Make bytes and bytearray subclass tests compatible with base types tests. 2016-05-12 12:33:41 +03:00
Victor Stinner e914d41312 Issue #26766: Fix _PyBytesWriter_Finish()
Return a bytearray object when bytearray is requested and when the small buffer
is used.

Fix also test_bytes: bytearray%args must return a bytearray type.
2016-04-15 17:52:27 +02:00
Serhiy Storchaka c9a59e6e4f Issue #26764: Fixed SystemError in bytes.__rmod__. 2016-04-15 14:11:10 +03:00
Martin Panter cfff15d274 Issue #26712: Merge string_tests cleanup from 3.5 2016-04-10 09:16:23 +00:00
Martin Panter 0d0db6cc1e Issue #26712: Unify (r)split, (l/r)strip tests into string_tests
This eliminates a few redundant test cases.
2016-04-10 08:45:26 +00:00
Serhiy Storchaka 3c149a6832 Issue #26764: Bacported tests for bytes formatting. 2016-04-15 14:13:37 +03:00
Martin Panter 747be0805d Issue #26257: Merge buffer_tests cleanup from 3.5 2016-04-08 00:16:33 +00:00
Martin Panter 152a19c6bd Issue #26257: Eliminate buffer_tests.py and fix ByteArrayAsStringTest
ByteArrayAsStringTest.fixtype() was converting test data to bytes, not byte-
array, therefore many of the test cases inherited in this class were not
actually being run on the bytearray type.

The tests in buffer_tests.py were redundant with methods in string_tests
.MixinStrUnicodeUserStringTest and string_tests.CommonTest. These methods are
now moved into string_tests.BaseTest, where they will also get run for bytes
and bytearray.

This change also moves test_additional_split(), test_additional_rsplit(), and
test_strip() from CommonTest to BaseTest, meaning these tests are now run for
bytes and bytearray. I plan to eliminate redundancies with existing tests in
test_bytes.py soon.
2016-04-06 06:37:17 +00:00
Serhiy Storchaka f39c0ac62f Issue #26492: Added additional tests for exhausted iterators of mutable sequences. 2016-03-30 21:01:45 +03:00
Serhiy Storchaka 8dc2ec1513 Issue #26492: Added additional tests for exhausted iterators of mutable sequences. 2016-03-30 21:01:26 +03:00
Serhiy Storchaka ab479c49d3 Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
views and os.scandir() iterator.
2016-03-30 20:41:15 +03:00
Serhiy Storchaka fbb1c5ee06 Issue #26494: Fixed crash on iterating exhausting iterators.
Affected classes are generic sequence iterators, iterators of str, bytes,
bytearray, list, tuple, set, frozenset, dict, OrderedDict, corresponding
views and os.scandir() iterator.
2016-03-30 20:40:02 +03:00
Serhiy Storchaka de128e19e2 Issue #26015: Added new tests for pickling iterators of mutable sequences. 2016-03-06 14:12:04 +02:00
Serhiy Storchaka aabafe7bc2 Issue #26015: Added new tests for pickling iterators of mutable sequences. 2016-03-06 14:10:24 +02:00