Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-133968: Add PyUnicodeWriter_WriteASCII() function#133973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2aa2e87fc08c3214c22c333b3276e7ca52f25e9444418c836b01a577File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1776,6 +1776,13 @@ def test_utf8(self): | ||
| self.assertEqual(writer.finish(), | ||
| "ascii-latin1=\xE9-euro=\u20AC.") | ||
| def test_ascii(self): | ||
| writer = self.create_writer(0) | ||
| writer.write_ascii(b"Hello ", -1) | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| writer.write_ascii(b"", 0) | ||
| writer.write_ascii(b"Python! <truncated>", 6) | ||
| self.assertEqual(writer.finish(), "Hello Python") | ||
| def test_invalid_utf8(self): | ||
| writer = self.create_writer(0) | ||
| with self.assertRaises(UnicodeDecodeError): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Add :c:func:`PyUnicodeWriter_WriteASCII` function to write an ASCII string | ||
| into a :c:type:`PyUnicodeWriter`. The function is faster than | ||
| :c:func:`PyUnicodeWriter_WriteUTF8`, but has an undefined behavior if the | ||
| input string contains non-ASCII characters. Patch by Victor Stinner. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14083,6 +14083,20 @@ _PyUnicodeWriter_WriteASCIIString(_PyUnicodeWriter *writer, | ||
| return 0; | ||
| } | ||
| int | ||
| PyUnicodeWriter_WriteASCII(PyUnicodeWriter *writer, | ||
| const char *str, | ||
| Py_ssize_t size) | ||
| { | ||
| assert(writer != NULL); | ||
| _Py_AssertHoldsTstate(); | ||
| _PyUnicodeWriter *priv_writer = (_PyUnicodeWriter*)writer; | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| return _PyUnicodeWriter_WriteASCIIString(priv_writer, str, size); | ||
| } | ||
| int | ||
| PyUnicodeWriter_WriteUTF8(PyUnicodeWriter *writer, | ||
| const char *str, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -290,7 +290,7 @@ union_repr(PyObject *self) | ||
| } | ||
| for (Py_ssize_t i = 0; i < len; i++){ | ||
| if (i > 0 && PyUnicodeWriter_WriteUTF8(writer, " | ", 3) < 0){ | ||
| if (i > 0 && PyUnicodeWriter_WriteASCII(writer, " | ", 3) < 0){ | ||
| goto error; | ||
| } | ||
| PyObject *p = PyTuple_GET_ITEM(alias->args, i); | ||
| @@ -300,12 +300,12 @@ union_repr(PyObject *self) | ||
| } | ||
| #if 0 | ||
| PyUnicodeWriter_WriteUTF8(writer, "|args=", 6); | ||
| PyUnicodeWriter_WriteASCII(writer, "|args=", 6); | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| PyUnicodeWriter_WriteRepr(writer, alias->args); | ||
| PyUnicodeWriter_WriteUTF8(writer, "|h=", 3); | ||
| PyUnicodeWriter_WriteASCII(writer, "|h=", 3); | ||
| PyUnicodeWriter_WriteRepr(writer, alias->hashable_args); | ||
| if (alias->unhashable_args){ | ||
| PyUnicodeWriter_WriteUTF8(writer, "|u=", 3); | ||
| PyUnicodeWriter_WriteASCII(writer, "|u=", 3); | ||
| PyUnicodeWriter_WriteRepr(writer, alias->unhashable_args); | ||
| } | ||
| #endif | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1176,7 +1176,7 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node, | ||
| } | ||
| if (key_or_null == NULL){ | ||
| if (PyUnicodeWriter_WriteUTF8(writer, "NULL:\n", -1) < 0){ | ||
| if (PyUnicodeWriter_WriteASCII(writer, "NULL:\n", 6) < 0){ | ||
| goto error; | ||
| } | ||
| @@ -1194,7 +1194,7 @@ hamt_node_bitmap_dump(PyHamtNode_Bitmap *node, | ||
| } | ||
| } | ||
| if (PyUnicodeWriter_WriteUTF8(writer, "\n", 1) < 0){ | ||
| if (PyUnicodeWriter_WriteASCII(writer, "\n", 1) < 0){ | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| goto error; | ||
| } | ||
| } | ||
| @@ -1915,7 +1915,7 @@ hamt_node_array_dump(PyHamtNode_Array *node, | ||
| goto error; | ||
| } | ||
| if (PyUnicodeWriter_WriteUTF8(writer, "\n", 1) < 0){ | ||
| if (PyUnicodeWriter_WriteASCII(writer, "\n", 1) < 0){ | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| goto error; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.