src/pylib/Python/fileutils

Source   Edit  

Consts

Utf8 = "utf-8"
Source   Edit  

Procs

proc Py_DecodeLocaleEx(arg: cstring; wstr: var ptr wchar_t; wlen: ptr csize_t;
                       reason: var cstring; current_locale: bool;
                       errors: Py_error_handler): int {....raises: [], tags: [],
    forbids: [].}

Decode a byte string from the locale encoding.

Use the strict error handler if 'surrogateescape' is zero. Use the surrogateescape error handler if 'surrogateescape' is non-zero: undecodable bytes are decoded as characters in range U+DC80..U+DCFF. If a byte sequence can be decoded as a surrogate character, escape the bytes using the surrogateescape error handler instead of decoding them.

On success, return 0 and write the newly allocated wide character string into wstr (use PyMem_RawFree() to free the memory). If wlen is not NULL, write the number of wide characters excluding the null character into wlen.

On memory allocation failure, return -1.

On decoding error, return -2. Write the start of invalid byte sequence in the input string into wlen. If reason is not NULL, write the decoding error message into reason.

Return -3 if the error handler 'errors' is not supported.

Use the Py_EncodeLocaleEx() function to encode the character string back to a byte string.

Source   Edit  
proc Py_GetLocaleEncoding(): string {....raises: [], tags: [], forbids: [].}
Get the current locale encoding name:
  • Return "utf-8" if Py_FORCE_UTF8_LOCALE is defined (ex: on Android)
  • Return "utf-8" if the UTF-8 Mode is enabled
  • On Windows, return the ANSI code page (ex: "cp1250")
  • Return "utf-8" if nl_langinfo(CODESET) returns an empty string.
  • Otherwise, return nl_langinfo(CODESET).

See also config_get_locale_encoding()

Source   Edit