FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-158172: Preserve struct.error for non-ASCII bytes formats by Ai-Eastern · Pull Request #158185 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (1) .rst  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
17 changes: 17 additions & 0 deletions Lib/test/test_struct.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,23 @@ def test_issue35714(self):
'embedded null character'):
struct.calcsize(s)

def test_non_ascii_bytes_format(self):
calls = (
(struct.Struct, ()),
(struct.calcsize, ()),
(struct.pack, ()),
(struct.pack_into, (bytearray(), 0)),
(struct.unpack, (b'',)),
(struct.unpack_from, (b'',)),
(struct.iter_unpack, (b'',)),
)
for format in (b'\xc5', b'<\xc5'):
for func, args in calls:
with self.subTest(format=format, func=func):
with self.assertRaisesRegex(struct.error,
'bad char in struct format'):
func(format, *args)

@support.cpython_only
def test_issue98248(self):
def test_error_msg(prefix, int_type, is_unsigned):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :mod:`struct` functions to raise :exc:`struct.error` instead of
:exc:`UnicodeEncodeError` for non-ASCII bytes format strings.
2 changes: 1 addition & 1 deletion Modules/_struct.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ cache_struct_converter(PyObject *module, PyObject *fmt, PyStructObject **ptr)
return Py_CLEANUP_SUPPORTED;
}

s_object = PyObject_CallOneArg(state->PyStructType, key);
s_object = PyObject_CallOneArg(state->PyStructType, fmt);
if (s_object != NULL) {
if (PyDict_GET_SIZE(state->cache) >= MAXCACHE)
PyDict_Clear(state->cache);
Expand Down
Loading

Back | FazBrowse Home | New Git URL