| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ea970fb commit 11e8348
50 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -992,19 +992,11 @@ These are the UTF-8 codec APIs: | |||
| 992 | 992 | ||
| 993 | 993 | As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size. | |
| 994 | 994 | ||
| 995 | - Raise an exception if the *unicode* string contains embedded null | ||
| 996 | - characters. To accept embedded null characters and truncate on purpose | ||
| 997 | - at the first null byte, ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be | ||
| 998 | - used instead. | ||
| 999 | - | ||
| 1000 | 995 | .. versionadded:: 3.3 | |
| 1001 | 996 | ||
| 1002 | 997 | .. versionchanged:: 3.7 | |
| 1003 | 998 | The return type is now ``const char *`` rather of ``char *``. | |
| 1004 | 999 | ||
| 1005 | - .. versionchanged:: 3.13 | ||
| 1006 | - Raise an exception if the string contains embedded null characters. | ||
| 1007 | - | ||
| 1008 | 1000 | ||
| 1009 | 1001 | UTF-32 Codecs | |
| 1010 | 1002 | """"""""""""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1149,9 +1149,6 @@ New Features | |||
| 1149 | 1149 | :c:func:`PyErr_WriteUnraisable`, but allow to customize the warning mesage. | |
| 1150 | 1150 | (Contributed by Serhiy Storchaka in :gh:`108082`.) | |
| 1151 | 1151 | ||
| 1152 | - * Add :c:func:`PyUnicode_AsUTF8` function to the limited C API. | ||
| 1153 | - (Contributed by Victor Stinner in :gh:`111089`.) | ||
| 1154 | - | ||
| 1155 | 1152 | ||
| 1156 | 1153 | Porting to Python 3.13 | |
| 1157 | 1154 | ---------------------- | |
@@ -1222,12 +1219,6 @@ Porting to Python 3.13 | |||
| 1222 | 1219 | Note that ``Py_TRASHCAN_BEGIN`` has a second argument which | |
| 1223 | 1220 | should be the deallocation function it is in. | |
| 1224 | 1221 | ||
| 1225 | - * The :c:func:`PyUnicode_AsUTF8` function now raises an exception if the string | ||
| 1226 | - contains embedded null characters. To accept embedded null characters and | ||
| 1227 | - truncate on purpose at the first null byte, | ||
| 1228 | - ``PyUnicode_AsUTF8AndSize(unicode, NULL)`` can be used instead. | ||
| 1229 | - (Contributed by Victor Stinner in :gh:`111089`.) | ||
| 1230 | - | ||
| 1231 | 1222 | * On Windows, ``Python.h`` no longer includes the ``<stddef.h>`` standard | |
| 1232 | 1223 | header file. If needed, it should now be included explicitly. For example, it | |
| 1233 | 1224 | provides ``offsetof()`` function, and ``size_t`` and ``ptrdiff_t`` types. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -440,6 +440,22 @@ PyAPI_FUNC(PyObject*) PyUnicode_FromKindAndData( | |||
| 440 | 440 | const void *buffer, | |
| 441 | 441 | Py_ssize_t size); | |
| 442 | 442 | ||
| 443 | + /* --- Manage the default encoding ---------------------------------------- */ | ||
| 444 | + | ||
| 445 | + /* Returns a pointer to the default encoding (UTF-8) of the | ||
| 446 | + Unicode object unicode. | ||
| 447 | + | ||
| 448 | + Like PyUnicode_AsUTF8AndSize(), this also caches the UTF-8 representation | ||
| 449 | + in the unicodeobject. | ||
| 450 | + | ||
| 451 | + _PyUnicode_AsString is a #define for PyUnicode_AsUTF8 to | ||
| 452 | + support the previous internal function with the same behaviour. | ||
| 453 | + | ||
| 454 | + Use of this API is DEPRECATED since no size information can be | ||
| 455 | + extracted from the returned data. | ||
| 456 | + */ | ||
| 457 | + | ||
| 458 | + PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode); | ||
| 443 | 459 | ||
| 444 | 460 | /* === Characters Type APIs =============================================== */ | |
| 445 | 461 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -443,25 +443,17 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsUTF8String( | |||
| 443 | 443 | PyObject *unicode /* Unicode object */ | |
| 444 | 444 | ); | |
| 445 | 445 | ||
| 446 | - // Returns a pointer to the UTF-8 encoding of the Unicode object unicode. | ||
| 447 | - // | ||
| 448 | - // Raise an exception if the string contains embedded null characters. | ||
| 449 | - // Use PyUnicode_AsUTF8AndSize() to accept embedded null characters. | ||
| 450 | - // | ||
| 451 | - // This function caches the UTF-8 encoded string in the Unicode object | ||
| 452 | - // and subsequent calls will return the same string. The memory is released | ||
| 453 | - // when the Unicode object is deallocated. | ||
| 454 | - PyAPI_FUNC(const char *) PyUnicode_AsUTF8(PyObject *unicode); | ||
| 455 | - | ||
| 456 | - // Returns a pointer to the UTF-8 encoding of the | ||
| 457 | - // Unicode object unicode and the size of the encoded representation | ||
| 458 | - // in bytes stored in `*size` (if size is not NULL). | ||
| 459 | - // | ||
| 460 | - // On error, `*size` is set to 0 (if size is not NULL). | ||
| 461 | - // | ||
| 462 | - // This function caches the UTF-8 encoded string in the Unicode object | ||
| 463 | - // and subsequent calls will return the same string. The memory is released | ||
| 464 | - // when the Unicode object is deallocated. | ||
| 446 | + /* Returns a pointer to the default encoding (UTF-8) of the | ||
| 447 | + Unicode object unicode and the size of the encoded representation | ||
| 448 | + in bytes stored in *size. | ||
| 449 | + | ||
| 450 | + In case of an error, no *size is set. | ||
| 451 | + | ||
| 452 | + This function caches the UTF-8 encoded string in the unicodeobject | ||
| 453 | + and subsequent calls will return the same string. The memory is released | ||
| 454 | + when the unicodeobject is deallocated. | ||
| 455 | + */ | ||
| 456 | + | ||
| 465 | 457 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 | |
| 466 | 458 | PyAPI_FUNC(const char *) PyUnicode_AsUTF8AndSize( | |
| 467 | 459 | PyObject *unicode, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -914,10 +914,7 @@ def test_asutf8(self): | |||
| 914 | 914 | self.assertEqual(unicode_asutf8('abc', 4), b'abc\0') | |
| 915 | 915 | self.assertEqual(unicode_asutf8('абв', 7), b'\xd0\xb0\xd0\xb1\xd0\xb2\0') | |
| 916 | 916 | self.assertEqual(unicode_asutf8('\U0001f600', 5), b'\xf0\x9f\x98\x80\0') | |
| 917 | - | ||
| 918 | - # disallow embedded null characters | ||
| 919 | - self.assertRaises(ValueError, unicode_asutf8, 'abc\0', 0) | ||
| 920 | - self.assertRaises(ValueError, unicode_asutf8, 'abc\0def', 0) | ||
| 917 | + self.assertEqual(unicode_asutf8('abc\0def', 8), b'abc\0def\0') | ||
| 921 | 918 | ||
| 922 | 919 | self.assertRaises(UnicodeEncodeError, unicode_asutf8, '\ud8ff', 0) | |
| 923 | 920 | self.assertRaises(TypeError, unicode_asutf8, b'abc', 0) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2478,8 +2478,6 @@ | |||
| 2478 | 2478 | added = '3.13' | |
| 2479 | 2479 | [function.PySys_AuditTuple] | |
| 2480 | 2480 | added = '3.13' | |
| 2481 | - [function.PyUnicode_AsUTF8] | ||
| 2482 | - added = '3.13' | ||
| 2483 | 2481 | [function._Py_SetRefcnt] | |
| 2484 | 2482 | added = '3.13' | |
| 2485 | 2483 | abi_only = true | |
| Back | FazBrowse Home | New Git URL |
0 commit comments