Author: Bernd Schoeller <[email protected]>
Branch: py3.7
Changeset: r97939:dc491b783ef7
Date: 2019-11-02 15:06 +0000
http://bitbucket.org/pypy/pypy/changeset/dc491b783ef7/
Log: Made fromhex ignore all whitespace (see bpo-28927)
diff --git a/pypy/objspace/std/bytearrayobject.py
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -556,7 +556,7 @@
length = len(s)
i = 0
while True:
- while i < length and s[i] == ' ':
+ while i < length and s[i].isspace():
i += 1
if i >= length:
break
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py
b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -439,6 +439,8 @@
b = bytearray([0x1a, 0x2b, 0x30])
assert bytearray.fromhex('1a2B30') == b
assert bytearray.fromhex(' 1A 2B 30 ') == b
+ assert bytearray.fromhex('''\t1a\t2B\n
+ 30\n''') == b
assert bytearray.fromhex('0000') == b'\0\0'
raises(ValueError, bytearray.fromhex, 'a')
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
@@ -137,6 +137,7 @@
assert bytes.fromhex("abcd") == b'\xab\xcd'
assert b''.fromhex("abcd") == b'\xab\xcd'
assert bytes.fromhex("ab cd ef") == b'\xab\xcd\xef'
+ assert bytes.fromhex("\nab\tcd \tef\t") == b'\xab\xcd\xef'
raises(TypeError, bytes.fromhex, b"abcd")
raises(TypeError, bytes.fromhex, True)
raises(ValueError, bytes.fromhex, "hello world")
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit