◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
22 changes: 22 additions & 0 deletions Doc/c-api/sys.rst
Original file line number Diff line number Diff line change
@@ -106,6 +106,16 @@ Operating System Utilities
surrogate character, escape the bytes using the surrogateescape error
handler instead of decoding them.

Return a pointer to a newly allocated wide character string, use
:c:func:`PyMem_RawFree` to free the memory. If size is not ``NULL``, write
the number of wide characters excluding the null character into ``*size``
Expand Down Expand Up @@ -137,6 +147,18 @@ Operating System Utilities
:ref:`surrogateescape error handler <surrogateescape>`: surrogate characters
in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF.

Return a pointer to a newly allocated byte string, use :c:func:`PyMem_Free`
to free the memory. Return ``NULL`` on encoding error or memory allocation
error
Expand Down
16 changes: 16 additions & 0 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,20 @@ system.
:c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at
Python startup).

.. seealso::

The :c:func:`Py_DecodeLocale` function.

.. versionadded:: 3.3


.. c:function:: PyObject* PyUnicode_DecodeLocale(const char *str, const char *errors)

Expand All @@ -797,12 +805,20 @@ system.
:c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at
Python startup).

.. seealso::

The :c:func:`Py_EncodeLocale` function.

.. versionadded:: 3.3


File System Encoding
""""""""""""""""""""
Expand Down
37 changes: 30 additions & 7 deletions Include/fileutils.h
Original file line number Diff line number Diff line change
@@ -20,18 +20,41 @@ PyAPI_FUNC(char*) _Py_EncodeLocaleRaw(
#endif

#ifdef Py_BUILD_CORE
PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape(
const char *s,
Py_ssize_t size,
size_t *p_wlen);

PyAPI_FUNC(wchar_t *) _Py_DecodeCurrentLocale(
const char *arg,
size_t *size);

PyAPI_FUNC(char*) _Py_EncodeCurrentLocale(
const wchar_t *text,
size_t *error_pos);
#endif

#ifndef Py_LIMITED_API
Expand Down
2 changes: 1 addition & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ static int parse_isoformat_date(const char *dtstr,
if (NULL == p) {
return -1;
}
if (*(p++) != '-') {
return -2;
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/_localemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,9 @@ PyIntl_bind_textdomain_codeset(PyObject* self,PyObject*args)
if (!PyArg_ParseTuple(args, "sz", &domain, &codeset))
return NULL;
codeset = bind_textdomain_codeset(domain, codeset);
if (codeset)
return PyUnicode_DecodeLocale(codeset, NULL);
Py_RETURN_NONE;
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions Modules/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,13 @@ static PyModuleDef readlinemodule;
static PyObject *
encode(PyObject *b)
{
return _PyUnicode_EncodeCurrentLocale(b, "surrogateescape");
}

static PyObject *
decode(const char *s)
{
return _PyUnicode_DecodeCurrentLocale(s, "surrogateescape");
}


Expand Down
Loading
Toggle all file notes Toggle all file annotations