유니코드 객체와 코덱
********************


유니코드 객체
=============

파이썬 3.3에서 **PEP 393**을 구현한 이후, 유니코드 객체는 내부적으로
다양한 표현을 사용하여 전체 유니코드 문자 범위를 처리하면서 메모리 효
율성을 유지합니다. 모든 코드 포인트가 128, 256 또는 65536 미만인 문자
열에 대한 특별한 경우가 있습니다; 그렇지 않으면, 코드 포인트는 1114112
(전체 유니코드 범위) 미만이어야 합니다.

Py_UNICODE* and UTF-8 representations are created on demand and cached
in the Unicode object.  The Py_UNICODE* representation is deprecated
and inefficient.

이전 API와 새 API 간의 전환으로 인해, 유니코드 객체는 만들어진 방법에
따라 내부적으로 두 가지 상태가 될 수 있습니다:

* "규범적(canonical)" 유니코드 객체는 폐지되지 않은 유니코드 API에 의
  해 만들어진 모든 객체입니다. 구현에서 허용하는 가장 효율적인 표현을
  사용합니다.

* "legacy" Unicode objects have been created through one of the
  deprecated APIs (typically "PyUnicode_FromUnicode()") and only bear
  the Py_UNICODE* representation; you will have to call
  "PyUnicode_READY()" on them before calling any other API.

참고:

  "레거시" 유니코드 객체는 폐지된 API와 함께 파이썬 3.12에서 제거됩니
  다. 그 이후로 모든 유니코드 객체는 "규범적"이 됩니다. 자세한 정보는
  **PEP 623**을 참조하십시오.


유니코드 형
-----------

다음은 파이썬에서 유니코드 구현에 사용되는 기본 유니코드 객체 형입니다
:

type Py_UCS4
type Py_UCS2
type Py_UCS1
    * Part of the Stable ABI.*

   이 형들은 각각 32비트, 16비트 및 8비트의 문자를 포함하기에 충분한
   부호 없는 정수 형을 위한 typedef 입니다. 단일 유니코드 문자를 처리
   할 때는, "Py_UCS4"를 사용하십시오.

   버전 3.3에 추가.

type Py_UNICODE

   이것은 플랫폼에 따라 16비트 형이나 32비트 형인 "wchar_t"의 typedef
   입니다.

   버전 3.3에서 변경: 이전 버전에서, 이것은 빌드 시 파이썬의 "내로우
   (narrow)"나 "와이드(wide)" 유니코드 버전 중 어느 것을 선택했는지에
   따라 16비트 형이나 32비트 형이었습니다.

type PyASCIIObject
type PyCompactUnicodeObject
type PyUnicodeObject

   이 "PyObject" 서브 형들은 파이썬 유니코드 객체를 나타냅니다. 거의
   모든 경우에, 유니코드 객체를 처리하는 모든 API 함수가 "PyObject" 포
   인터를 취하고 반환하므로 직접 사용해서는 안 됩니다.

   버전 3.3에 추가.

PyTypeObject PyUnicode_Type
    * Part of the Stable ABI.*

   이 "PyTypeObject" 인스턴스는 파이썬 유니코드 형을 나타냅니다. 파이
   썬 코드에 "str"로 노출됩니다.

The following APIs are C macros and static inlined functions for fast
checks and access to internal read-only data of Unicode objects:

int PyUnicode_Check(PyObject *obj)

   Return true if the object *obj* is a Unicode object or an instance
   of a Unicode subtype.  This function always succeeds.

int PyUnicode_CheckExact(PyObject *obj)

   Return true if the object *obj* is a Unicode object, but not an
   instance of a subtype.  This function always succeeds.

int PyUnicode_READY(PyObject *unicode)

   문자열 객체 *o*가 "규범적(canonical)" 표현인지 확인합니다. 이것은
   아래에 설명된 액세스 매크로를 사용하기 전에 필요합니다.

   성공 시 "0"을 반환하고, 실패 시 예외를 설정하면서 "-1"을 반환하는데
   , 특히 메모리 할당이 실패하면 발생합니다.

   버전 3.3에 추가.

   버전 3.10에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이 API는
   "PyUnicode_FromUnicode()"와 함께 제거됩니다.

Py_ssize_t PyUnicode_GET_LENGTH(PyObject *unicode)

   Return the length of the Unicode string, in code points.  *unicode*
   has to be a Unicode object in the "canonical" representation (not
   checked).

   버전 3.3에 추가.

Py_UCS1 *PyUnicode_1BYTE_DATA(PyObject *unicode)
Py_UCS2 *PyUnicode_2BYTE_DATA(PyObject *unicode)
Py_UCS4 *PyUnicode_4BYTE_DATA(PyObject *unicode)

   직접 문자 액세스를 위해 UCS1, UCS2 또는 UCS4 정수 형으로 캐스트 된
   규범적(canonical) 표현에 대한 포인터를 반환합니다. 규범적
   (canonical) 표현이 올바른 문자 크기인지 검사하지 않습니다;
   "PyUnicode_KIND()"를 사용하여 올바른 매크로를 선택하십시오. 이것을
   액세스하기 전에 "PyUnicode_READY()"가 호출되었어야 합니다.

   버전 3.3에 추가.

PyUnicode_WCHAR_KIND
PyUnicode_1BYTE_KIND
PyUnicode_2BYTE_KIND
PyUnicode_4BYTE_KIND

   "PyUnicode_KIND()" 매크로의 값을 반환합니다.

   버전 3.3에 추가.

   버전 3.10에서 폐지되었습니다, 버전 3.12에서 제거됩니다.:
   "PyUnicode_WCHAR_KIND"는 폐지되었습니다.

int PyUnicode_KIND(PyObject *unicode)

   Return one of the PyUnicode kind constants (see above) that
   indicate how many bytes per character this Unicode object uses to
   store its data.  *unicode* has to be a Unicode object in the
   "canonical" representation (not checked).

   버전 3.3에 추가.

void *PyUnicode_DATA(PyObject *unicode)

   Return a void pointer to the raw Unicode buffer.  *unicode* has to
   be a Unicode object in the "canonical" representation (not
   checked).

   버전 3.3에 추가.

void PyUnicode_WRITE(int kind, void *data, Py_ssize_t index, Py_UCS4 value)

   Write into a canonical representation *data* (as obtained with
   "PyUnicode_DATA()").  This function performs no sanity checks, and
   is intended for usage in loops.  The caller should cache the *kind*
   value and *data* pointer as obtained from other calls.  *index* is
   the index in the string (starts at 0) and *value* is the new code
   point value which should be written to that location.

   버전 3.3에 추가.

Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)

   규범적(canonical) 표현 *data*("PyUnicode_DATA()"로 얻은 대로)에서
   코드 포인트를 읽습니다. 검사나 준비(ready) 호출이 수행되지 않습니다
   .

   버전 3.3에 추가.

Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)

   Read a character from a Unicode object *unicode*, which must be in
   the "canonical" representation.  This is less efficient than
   "PyUnicode_READ()" if you do multiple consecutive reads.

   버전 3.3에 추가.

Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *unicode)

   Return the maximum code point that is suitable for creating another
   string based on *unicode*, which must be in the "canonical"
   representation.  This is always an approximation but more efficient
   than iterating over the string.

   버전 3.3에 추가.

Py_ssize_t PyUnicode_GET_SIZE(PyObject *unicode)

   Return the size of the deprecated "Py_UNICODE" representation, in
   code units (this includes surrogate pairs as 2 units).  *unicode*
   has to be a Unicode object (not checked).

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다, "PyUnicode_GET_LENGTH()"를 사용하여 마이
   그레이션 하십시오.

Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *unicode)

   Return the size of the deprecated "Py_UNICODE" representation in
   bytes.  *unicode* has to be a Unicode object (not checked).

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다, "PyUnicode_GET_LENGTH()"를 사용하여 마이
   그레이션 하십시오.

Py_UNICODE *PyUnicode_AS_UNICODE(PyObject *unicode)
const char *PyUnicode_AS_DATA(PyObject *unicode)

   Return a pointer to a "Py_UNICODE" representation of the object.
   The returned buffer is always terminated with an extra null code
   point.  It may also contain embedded null code points, which would
   cause the string to be truncated when used in most C functions.
   The "AS_DATA" form casts the pointer to const char*.  The *unicode*
   argument has to be a Unicode object (not checked).

   버전 3.3에서 변경: This function is now inefficient -- because in
   many cases the "Py_UNICODE" representation does not exist and needs
   to be created -- and can fail (return "NULL" with an exception
   set).  Try to port the code to use the new "PyUnicode_nBYTE_DATA()"
   macros or use "PyUnicode_WRITE()" or "PyUnicode_READ()".

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다. "PyUnicode_nBYTE_DATA()" 매크로 계열을
   사용하도록 마이그레이션 하십시오.

int PyUnicode_IsIdentifier(PyObject *unicode)
    * Part of the Stable ABI.*

   언어 정의에 따라 문자열이 유효한 식별자이면 "1"을 반환합니다, 섹션
   식별자와 키워드. 그렇지 않으면 "0"을 반환합니다.

   버전 3.9에서 변경: 문자열이 준비(ready)되지 않았을 때, 이 함수는 더
   는 "Py_FatalError()"를 호출하지 않습니다.


유니코드 문자 속성
------------------

유니코드는 다양한 문자 속성을 제공합니다. 가장 자주 필요한 것은 파이썬
구성에 따라 C 함수에 매핑되는 이러한 매크로를 통해 사용할 수 있습니다.

int Py_UNICODE_ISSPACE(Py_UCS4 ch)

   *ch*가 공백 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISLOWER(Py_UCS4 ch)

   *ch*가 소문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISUPPER(Py_UCS4 ch)

   *ch*가 대문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISTITLE(Py_UCS4 ch)

   *ch*가 제목 케이스 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISLINEBREAK(Py_UCS4 ch)

   *ch*가 줄 바꿈 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISDECIMAL(Py_UCS4 ch)

   *ch*가 10진수 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISDIGIT(Py_UCS4 ch)

   *ch*가 디짓(digit) 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISNUMERIC(Py_UCS4 ch)

   *ch*가 숫자(numeric) 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISALPHA(Py_UCS4 ch)

   *ch*가 알파벳 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISALNUM(Py_UCS4 ch)

   *ch*가 영숫자 문자인지에 따라 "1"이나 "0"을 반환합니다.

int Py_UNICODE_ISPRINTABLE(Py_UCS4 ch)

   *ch*가 인쇄 가능한 문자인지에 따라 "1"이나 "0"을 반환합니다. 인쇄할
   수 없는 문자는, 인쇄 가능한 것으로 간주하는 ASCII 스페이스(0x20)를
   제외하고, 유니코드 문자 데이터베이스에서 "Other"나 "Separator"로 정
   의된 문자입니다. (이 문맥에서 인쇄 가능한 문자는 "repr()"이 문자열
   에 대해 호출될 때 이스케이프 되지 않아야 하는 문자임에 유의하십시오
   . "sys.stdout"이나 "sys.stderr"에 기록된 문자열의 처리와 관련이 없
   습니다.)

다음 API는 빠른 직접 문자 변환에 사용할 수 있습니다:

Py_UCS4 Py_UNICODE_TOLOWER(Py_UCS4 ch)

   소문자로 변환된 문자 *ch*를 반환합니다.

   버전 3.3부터 폐지됨: 이 함수는 간단한 케이스 매핑을 사용합니다.

Py_UCS4 Py_UNICODE_TOUPPER(Py_UCS4 ch)

   대문자로 변환된 문자 *ch*를 반환합니다.

   버전 3.3부터 폐지됨: 이 함수는 간단한 케이스 매핑을 사용합니다.

Py_UCS4 Py_UNICODE_TOTITLE(Py_UCS4 ch)

   제목 케이스로 변환된 문자 *ch*를 반환합니다.

   버전 3.3부터 폐지됨: 이 함수는 간단한 케이스 매핑을 사용합니다.

int Py_UNICODE_TODECIMAL(Py_UCS4 ch)

   10진 양의 정수로 변환된 문자 *ch*를 반환합니다. 이것이 불가능하면
   "-1"을 반환합니다. 이 매크로는 예외를 발생시키지 않습니다.

int Py_UNICODE_TODIGIT(Py_UCS4 ch)

   한 자리 정수로 변환된 문자 *ch*를 반환합니다. 이것이 불가능하면
   "-1"을 반환합니다. 이 매크로는 예외를 발생시키지 않습니다.

double Py_UNICODE_TONUMERIC(Py_UCS4 ch)

   double로 변환된 문자 *ch*를 반환합니다. 이것이 불가능하면 "-1.0"을
   반환합니다. 이 매크로는 예외를 발생시키지 않습니다.

다음 API를 사용하여 서로게이트를 다룰 수 있습니다:

Py_UNICODE_IS_SURROGATE(ch)

   *ch*가 서로게이트인지 확인합니다 ("0xD800 <= ch <= 0xDFFF").

Py_UNICODE_IS_HIGH_SURROGATE(ch)

   *ch*가 상위 서로게이트인지 확인합니다 ("0xD800 <= ch <= 0xDBFF").

Py_UNICODE_IS_LOW_SURROGATE(ch)

   *ch*가 하위 서로게이트인지 확인합니다 ("0xDC00 <= ch <= 0xDFFF").

Py_UNICODE_JOIN_SURROGATES(high, low)

   두 서로게이트 문자를 결합하고 단일 Py_UCS4 값을 반환합니다. *high*
   와 *low*는 각각 서로게이트 쌍의 선행과 후행 서로게이트입니다.


유니코드 문자열 생성과 액세스
-----------------------------

유니코드 객체를 만들고 기본 시퀀스 속성에 액세스하려면 다음 API를 사용
하십시오:

PyObject *PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
    *Return value: New reference.*

   새 유니코드 객체를 만듭니다. *maxchar*은 문자열에 배치할 실제 최대
   코드 포인트여야 합니다. 근삿값으로, 127, 255, 65535, 1114111 시퀀스
   에서 가장 가까운 값으로 올림 할 수 있습니다.

   이것은 새 유니코드 객체를 할당하는 데 권장되는 방법입니다. 이 함수
   를 사용하여 만든 객체는 크기를 조정할 수 없습니다.

   버전 3.3에 추가.

PyObject *PyUnicode_FromKindAndData(int kind, const void *buffer, Py_ssize_t size)
    *Return value: New reference.*

   주어진 *kind*(가능한 값은 "PyUnicode_KIND()"에 의해 반환된
   "PyUnicode_1BYTE_KIND" 등입니다)로 새로운 유니코드 객체를 만듭니다.
   *buffer*는 kind에 따라 문자 당 1, 2 또는 4바이트의 *size* 단위의 배
   열을 가리켜야 합니다.

   If necessary, the input *buffer* is copied and transformed into the
   canonical representation.  For example, if the *buffer* is a UCS4
   string ("PyUnicode_4BYTE_KIND") and it consists only of codepoints
   in the UCS1 range, it will be transformed into UCS1
   ("PyUnicode_1BYTE_KIND").

   버전 3.3에 추가.

PyObject *PyUnicode_FromStringAndSize(const char *str, Py_ssize_t size)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object from the char buffer *str*.  The bytes will
   be interpreted as being UTF-8 encoded.  The buffer is copied into
   the new object. If the buffer is not "NULL", the return value might
   be a shared object, i.e. modification of the data is not allowed.

   If *str* is "NULL", this function behaves like
   "PyUnicode_FromUnicode()" with the buffer set to "NULL".  This
   usage is deprecated in favor of "PyUnicode_New()", and will be
   removed in Python 3.12.

PyObject *PyUnicode_FromString(const char *str)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object from a UTF-8 encoded null-terminated char
   buffer *str*.

PyObject *PyUnicode_FromFormat(const char *format, ...)
    *Return value: New reference.** Part of the Stable ABI.*

   C "printf()"-스타일 *format* 문자열과 가변 개수의 인자를 취해서, 결
   과 파이썬 유니코드 문자열의 크기를 계산하고 포맷된 값이 들어간 문자
   열을 반환합니다. 변수 인자는 C형이어야 하며 *format* ASCII 인코딩된
   문자열의 포맷 문자와 정확히 일치해야 합니다. 다음 포맷 문자가 허용
   됩니다:

   +---------------------+-----------------------+------------------------------------+
   | 포맷 문자           | 형                    | 주석                               |
   |=====================|=======================|====================================|
   | "%%"                | *n/a*                 | 리터럴 % 문자.                     |
   +---------------------+-----------------------+------------------------------------+
   | "%c"                | int                   | C int로 표현된, 단일 문자.         |
   +---------------------+-----------------------+------------------------------------+
   | "%d"                | int                   | "printf("%d")"와 동등합니다. [1]   |
   +---------------------+-----------------------+------------------------------------+
   | "%u"                | unsigned int          | "printf("%u")"와 동등합니다. [1]   |
   +---------------------+-----------------------+------------------------------------+
   | "%ld"               | long                  | "printf("%ld")"와 동등합니다. [1]  |
   +---------------------+-----------------------+------------------------------------+
   | "%li"               | long                  | "printf("%li")"와 동등합니다. [1]  |
   +---------------------+-----------------------+------------------------------------+
   | "%lu"               | unsigned long         | "printf("%lu")"와 동등합니다. [1]  |
   +---------------------+-----------------------+------------------------------------+
   | "%lld"              | long long             | "printf("%lld")"와 동등합니다. [1] |
   +---------------------+-----------------------+------------------------------------+
   | "%lli"              | long long             | "printf("%lli")"와 동등합니다. [1] |
   +---------------------+-----------------------+------------------------------------+
   | "%llu"              | unsigned long long    | "printf("%llu")"와 동등합니다. [1] |
   +---------------------+-----------------------+------------------------------------+
   | "%zd"               | "Py_ssize_t"          | "printf("%zd")"와 동등합니다. [1]  |
   +---------------------+-----------------------+------------------------------------+
   | "%zi"               | "Py_ssize_t"          | "printf("%zi")"와 동등합니다. [1]  |
   +---------------------+-----------------------+------------------------------------+
   | "%zu"               | size_t                | "printf("%zu")"와 동등합니다. [1]  |
   +---------------------+-----------------------+------------------------------------+
   | "%i"                | int                   | "printf("%i")"와 동등합니다. [1]   |
   +---------------------+-----------------------+------------------------------------+
   | "%x"                | int                   | "printf("%x")"와 동등합니다. [1]   |
   +---------------------+-----------------------+------------------------------------+
   | "%s"                | const char*           | 널-종료 C 문자 배열.               |
   +---------------------+-----------------------+------------------------------------+
   | "%p"                | const void*           | C 포인터의 16진수 표현. 플랫폼의   |
   |                     |                       | "printf"가 산출하는 내용과 관계없  |
   |                     |                       | 이 리터럴 "0x"로 시작하는 것이 보  |
   |                     |                       | 장된다는 점을 제외하면 거의        |
   |                     |                       | "printf("%p")"와 동등합니다.       |
   +---------------------+-----------------------+------------------------------------+
   | "%A"                | PyObject*             | "ascii()"를 호출한 결과.           |
   +---------------------+-----------------------+------------------------------------+
   | "%U"                | PyObject*             | 유니코드 객체.                     |
   +---------------------+-----------------------+------------------------------------+
   | "%V"                | PyObject*, const      | 유니코드 객체("NULL"일 수 있습니다 |
   |                     | char*                 | )와 두 번째 매개 변수로서 널-종료  |
   |                     |                       | C 문자 배열 (첫 번째 매개 변수가   |
   |                     |                       | "NULL"이면 사용됩니다).            |
   +---------------------+-----------------------+------------------------------------+
   | "%S"                | PyObject*             | "PyObject_Str()"을 호출한 결과.    |
   +---------------------+-----------------------+------------------------------------+
   | "%R"                | PyObject*             | "PyObject_Repr()"을 호출한 결과.   |
   +---------------------+-----------------------+------------------------------------+

   인식할 수 없는 포맷 문자는 나머지 포맷 문자열이 모두 결과 문자열에
   그대로 복사되고, 추가 인자는 버려지도록 합니다.

   참고:

     너비 포매터 단위는 바이트가 아닌 문자 수입니다. 정밀도 포매터 단
     위는 ""%s""와 ""%V""의 경우는 바이트 수이고 ("PyObject*" 인자가
     "NULL"이면), ""%A"", ""%U"", ""%S"", ""%R"" 및 ""%V""의 경우 문자
     수입니다 ("PyObject*" 인자가 "NULL"이 아니면).

   [1] 정수 지정자 (d, u, ld, li, lu, lld, lli, llu, zd, zi, zu, i, x)
       의 경우: 0-변환 플래그는 정밀도가 제공되는 경우에도 적용됩니다.

   버전 3.2에서 변경: ""%lld""와 ""%llu""에 대한 지원이 추가되었습니다
   .

   버전 3.3에서 변경: ""%li"", ""%lli"" 및 ""%zi""에 대한 지원이 추가
   되었습니다.

   버전 3.4에서 변경: ""%s"", ""%A"", ""%U"", ""%V"", ""%S"", ""%R""에
   대한 너비와 정밀도 포매터 지원이 추가되었습니다.

PyObject *PyUnicode_FromFormatV(const char *format, va_list vargs)
    *Return value: New reference.** Part of the Stable ABI.*

   정확히 두 개의 인자를 취한다는 점을 제외하면
   "PyUnicode_FromFormat()"과 동일합니다.

PyObject *PyUnicode_FromObject(PyObject *obj)
    *Return value: New reference.** Part of the Stable ABI.*

   Copy an instance of a Unicode subtype to a new true Unicode object
   if necessary. If *obj* is already a true Unicode object (not a
   subtype), return a new *strong reference* to the object.

   유니코드나 이의 서브 형 이외의 객체는 "TypeError"를 발생시킵니다.

PyObject *PyUnicode_FromEncodedObject(PyObject *obj, const char *encoding, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   인코딩된 객체 *obj*를 유니코드 객체로 디코딩합니다.

   "bytes", "bytearray" 및 기타 *바이트열류 객체*는 주어진 *encoding*
   에 따라 *errors*로 정의한 에러 처리를 사용하여 디코딩됩니다. 둘 다
   "NULL"이 될 수 있고, 이 경우 인터페이스는 기본값을 사용합니다 (자세
   한 내용은 내장 코덱를 참조하십시오).

   유니코드 객체를 포함한 다른 모든 객체는 "TypeError"가 설정되도록 합
   니다.

   API는 에러가 있으면 "NULL"을 반환합니다. 호출자는 반환된 객체의 참
   조 횟수를 감소시킬 책임이 있습니다.

Py_ssize_t PyUnicode_GetLength(PyObject *unicode)
    * Part of the Stable ABI since version 3.7.*

   유니코드 객체의 길이를 코드 포인트로 반환합니다.

   버전 3.3에 추가.

Py_ssize_t PyUnicode_CopyCharacters(PyObject *to, Py_ssize_t to_start, PyObject *from, Py_ssize_t from_start, Py_ssize_t how_many)

   Copy characters from one Unicode object into another.  This
   function performs character conversion when necessary and falls
   back to "memcpy()" if possible.  Returns "-1" and sets an exception
   on error, otherwise returns the number of copied characters.

   버전 3.3에 추가.

Py_ssize_t PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, Py_ssize_t length, Py_UCS4 fill_char)

   문자로 문자열을 채웁니다: *fill_char*을
   "unicode[start:start+length]"에 씁니다.

   *fill_char*이 문자열 최대 문자보다 크거나, 문자열에 둘 이상의 참조
   가 있으면 실패합니다.

   기록된 문자 수를 반환하거나, 에러 시 "-1"을 반환하고 예외를 발생시
   킵니다.

   버전 3.3에 추가.

int PyUnicode_WriteChar(PyObject *unicode, Py_ssize_t index, Py_UCS4 character)
    * Part of the Stable ABI since version 3.7.*

   문자열에 문자를 씁니다. 문자열은 "PyUnicode_New()"를 통해 만들었어
   야 합니다. 유니코드 문자열은 불변이므로, 문자열을 공유하거나 아직
   해시 하지 않아야 합니다.

   이 함수는 *unicode*가 유니코드 객체인지, 인덱스가 범위를 벗어났는지
   , 객체가 안전하게 수정될 수 있는지 (즉, 참조 횟수가 1인지) 확인합니
   다.

   버전 3.3에 추가.

Py_UCS4 PyUnicode_ReadChar(PyObject *unicode, Py_ssize_t index)
    * Part of the Stable ABI since version 3.7.*

   Read a character from a string.  This function checks that
   *unicode* is a Unicode object and the index is not out of bounds,
   in contrast to "PyUnicode_READ_CHAR()", which performs no error
   checking.

   버전 3.3에 추가.

PyObject *PyUnicode_Substring(PyObject *unicode, Py_ssize_t start, Py_ssize_t end)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.7.*

   Return a substring of *unicode*, from character index *start*
   (included) to character index *end* (excluded).  Negative indices
   are not supported.

   버전 3.3에 추가.

Py_UCS4 *PyUnicode_AsUCS4(PyObject *unicode, Py_UCS4 *buffer, Py_ssize_t buflen, int copy_null)
    * Part of the Stable ABI since version 3.7.*

   Copy the string *unicode* into a UCS4 buffer, including a null
   character, if *copy_null* is set.  Returns "NULL" and sets an
   exception on error (in particular, a "SystemError" if *buflen* is
   smaller than the length of *unicode*).  *buffer* is returned on
   success.

   버전 3.3에 추가.

Py_UCS4 *PyUnicode_AsUCS4Copy(PyObject *unicode)
    * Part of the Stable ABI since version 3.7.*

   Copy the string *unicode* into a new UCS4 buffer that is allocated
   using "PyMem_Malloc()".  If this fails, "NULL" is returned with a
   "MemoryError" set.  The returned buffer always has an extra null
   code point appended.

   버전 3.3에 추가.


폐지된 Py_UNICODE API
---------------------

버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다..

이 API 함수들은 **PEP 393** 구현에 의해 폐지되었습니다. 파이썬 3.x에서
제거되지 않기 때문에, 확장 모듈은 계속해서 사용할 수 있지만, 이제 그
사용으로 인해 성능과 메모리 문제가 있을 수 있음을 인식해야 합니다.

PyObject *PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
    *Return value: New reference.*

   주어진 크기(size)의 Py_UNICODE 버퍼 *u*에서 유니코드 객체를 만듭니
   다. *u*는 "NULL"일 수 있으며, 이럴 때는 내용이 정의되지 않습니다.
   필요한 데이터를 채우는 것은 사용자의 책임입니다. 버퍼가 새 객체에
   복사됩니다.

   버퍼가 "NULL"이 아니면, 반환 값은 공유 객체일 수 있습니다. 따라서,
   결과 유니코드 객체의 수정은 *u*가 "NULL"일 때만 허용됩니다.

   버퍼가 "NULL"이면, "PyUnicode_KIND()"와 같은 액세스 매크로를 사용하
   기 전에 문자열 내용이 채워지면 "PyUnicode_READY()"를 호출해야 합니
   다.

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다. "PyUnicode_FromKindAndData()",
   "PyUnicode_FromWideChar()" 또는 "PyUnicode_New()"를 사용하여 마이그
   레이션 하십시오.

Py_UNICODE *PyUnicode_AsUnicode(PyObject *unicode)

   Return a read-only pointer to the Unicode object's internal
   "Py_UNICODE" buffer, or "NULL" on error. This will create the
   Py_UNICODE* representation of the object if it is not yet
   available. The buffer is always terminated with an extra null code
   point. Note that the resulting "Py_UNICODE" string may also contain
   embedded null code points, which would cause the string to be
   truncated when used in most C functions.

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다. "PyUnicode_AsUCS4()",
   "PyUnicode_AsWideChar()", "PyUnicode_ReadChar()" 또는 유사한 새 API
   를 사용하여 마이그레이션 하십시오.

Py_UNICODE *PyUnicode_AsUnicodeAndSize(PyObject *unicode, Py_ssize_t *size)

   Like "PyUnicode_AsUnicode()", but also saves the "Py_UNICODE()"
   array length (excluding the extra null terminator) in *size*. Note
   that the resulting Py_UNICODE* string may contain embedded null
   code points, which would cause the string to be truncated when used
   in most C functions.

   버전 3.3에 추가.

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다. "PyUnicode_AsUCS4()",
   "PyUnicode_AsWideChar()", "PyUnicode_ReadChar()" 또는 유사한 새 API
   를 사용하여 마이그레이션 하십시오.

Py_ssize_t PyUnicode_GetSize(PyObject *unicode)
    * Part of the Stable ABI.*

   폐지된 "Py_UNICODE" 표현의 크기를 코드 단위로 반환합니다 (서로게이
   트 쌍을 2단위로 포함합니다).

   버전 3.3에서 폐지되었습니다, 버전 3.12에서 제거됩니다.: 이전 스타일
   유니코드 API의 일부입니다, "PyUnicode_GET_LENGTH()"를 사용하여 마이
   그레이션 하십시오.


로케일 인코딩
-------------

현재 로케일 인코딩을 사용하여 운영 체제에서 온 텍스트를 디코딩 할 수
있습니다.

PyObject *PyUnicode_DecodeLocaleAndSize(const char *str, Py_ssize_t length, const char *errors)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.7.*

   안드로이드와 VxWorks의 UTF-8이나 다른 플랫폼의 현재 로케일 인코딩의
   문자열을 디코딩합니다. 지원되는 에러 처리기는 ""strict""와
   ""surrogateescape""(**PEP 383**)입니다. 디코더는 *errors*가 "NULL"
   이면 ""strict"" 에러 처리기를 사용합니다. *str*은 널 문자로 끝나야
   하지만 널 문자를 포함할 수 없습니다.

   "Py_FileSystemDefaultEncoding"(파이썬 시작 시 읽은 로케일 인코딩)에
   서 문자열을 디코딩하려면 "PyUnicode_DecodeFSDefaultAndSize()"를 사
   용하십시오.

   This function ignores the Python UTF-8 Mode.

   더 보기: "Py_DecodeLocale()" 함수.

   버전 3.3에 추가.

   버전 3.7에서 변경: 이 함수는 이제 안드로이드를 제외하고
   "surrogateescape" 에러 처리기에 현재 로케일 인코딩도 사용합니다. 이
   전에는, "Py_DecodeLocale()"이 "surrogateescape"에 사용되었고, 현재
   로케일 인코딩은 "strict"에 사용되었습니다.

PyObject *PyUnicode_DecodeLocale(const char *str, const char *errors)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.7.*

   Similar to "PyUnicode_DecodeLocaleAndSize()", but compute the
   string length using "strlen()".

   버전 3.3에 추가.

PyObject *PyUnicode_EncodeLocale(PyObject *unicode, const char *errors)
    *Return value: New reference.** Part of the Stable ABI since
   version 3.7.*

   유니코드 객체를 안드로이드와 VxWorks에서 UTF-8로 인코딩하거나, 다른
   플랫폼에서 현재 로케일 인코딩으로 인코딩합니다. 지원되는 에러 처리
   기는 ""strict""와 ""surrogateescape""(**PEP 383**)입니다. 인코더는
   *errors*가 "NULL"이면 ""strict"" 에러 처리기를 사용합니다. "bytes"
   객체를 반환합니다. *unicode*는 내장된 널 문자를 포함할 수 없습니다.

   문자열을 "Py_FileSystemDefaultEncoding"(파이썬 시작 시 읽은 로케일
   인코딩)으로 인코딩하려면 "PyUnicode_EncodeFSDefault()"를 사용하십시
   오.

   This function ignores the Python UTF-8 Mode.

   더 보기: "Py_EncodeLocale()" 함수.

   버전 3.3에 추가.

   버전 3.7에서 변경: 이 함수는 이제 안드로이드를 제외하고
   "surrogateescape" 에러 처리기에 현재 로케일 인코딩도 사용합니다. 이
   전에는 "Py_EncodeLocale()"이 "surrogateescape"에 사용되었고, 현재
   로케일 인코딩은 "strict"에 사용되었습니다.


파일 시스템 인코딩
------------------

파일 이름과 기타 환경 문자열을 인코딩하고 디코딩하려면,
"Py_FileSystemDefaultEncoding" 을 인코딩으로 사용하고,
"Py_FileSystemDefaultEncodeErrors"를 에러 처리기로 사용해야 합니다
(**PEP 383**과 **PEP 529**). 인자 구문 분석 중에 파일 이름을 "bytes"로
인코딩하려면, ""O&"" 변환기를 사용하고 "PyUnicode_FSConverter()"를 변
환 함수로 전달해야 합니다:

int PyUnicode_FSConverter(PyObject *obj, void *result)
    * Part of the Stable ABI.*

   ParseTuple converter: encode "str" objects -- obtained directly or
   through the "os.PathLike" interface -- to "bytes" using
   "PyUnicode_EncodeFSDefault()"; "bytes" objects are output as-is.
   *result* must be a PyBytesObject* which must be released when it is
   no longer used.

   버전 3.1에 추가.

   버전 3.6에서 변경: *경로류 객체*를 받아들입니다.

인자 구문 분석 중에 파일 이름을 "str"로 디코딩하려면, ""O&"" 변환기를
사용하고 "PyUnicode_FSDecoder()"를 변환 함수로 전달해야 합니다:

int PyUnicode_FSDecoder(PyObject *obj, void *result)
    * Part of the Stable ABI.*

   ParseTuple converter: decode "bytes" objects -- obtained either
   directly or indirectly through the "os.PathLike" interface -- to
   "str" using "PyUnicode_DecodeFSDefaultAndSize()"; "str" objects are
   output as-is. *result* must be a PyUnicodeObject* which must be
   released when it is no longer used.

   버전 3.2에 추가.

   버전 3.6에서 변경: *경로류 객체*를 받아들입니다.

PyObject *PyUnicode_DecodeFSDefaultAndSize(const char *str, Py_ssize_t size)
    *Return value: New reference.** Part of the Stable ABI.*

   Decode a string from the *filesystem encoding and error handler*.

   "Py_FileSystemDefaultEncoding" 이 설정되지 않으면, 로케일 인코딩으
   로 폴백합니다.

   "Py_FileSystemDefaultEncoding" 은 시작 시 로케일 인코딩에서 초기화
   되며 나중에 수정할 수 없습니다. 현재 로케일 인코딩에서 문자열을 디
   코딩해야 하면, "PyUnicode_DecodeLocaleAndSize()"를 사용하십시오.

   더 보기: "Py_DecodeLocale()" 함수.

   버전 3.6에서 변경: "Py_FileSystemDefaultEncodeErrors" 에러 처리기를
   사용합니다.

PyObject *PyUnicode_DecodeFSDefault(const char *str)
    *Return value: New reference.** Part of the Stable ABI.*

   Decode a null-terminated string from the *filesystem encoding and
   error handler*.

   "Py_FileSystemDefaultEncoding" 이 설정되지 않으면, 로케일 인코딩으
   로 폴백합니다.

   문자열 길이를 알고 있으면 "PyUnicode_DecodeFSDefaultAndSize()"를 사
   용하십시오.

   버전 3.6에서 변경: "Py_FileSystemDefaultEncodeErrors" 에러 처리기를
   사용합니다.

PyObject *PyUnicode_EncodeFSDefault(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   "Py_FileSystemDefaultEncodeErrors" 에러 처리기를 사용하여 유니코드
   객체를 "Py_FileSystemDefaultEncoding"로 인코딩하고, "bytes"를 반환
   합니다. 결과 "bytes" 객체에는 널 바이트가 포함될 수 있음에 유의하십
   시오.

   "Py_FileSystemDefaultEncoding" 이 설정되지 않으면, 로케일 인코딩으
   로 폴백합니다.

   "Py_FileSystemDefaultEncoding" 은 시작 시 로케일 인코딩에서 초기화
   되며 나중에 수정할 수 없습니다. 현재 로케일 인코딩으로 문자열을 인
   코딩해야 하면, "PyUnicode_EncodeLocale()"을 사용하십시오.

   더 보기: "Py_EncodeLocale()" 함수.

   버전 3.2에 추가.

   버전 3.6에서 변경: "Py_FileSystemDefaultEncodeErrors" 에러 처리기를
   사용합니다.


wchar_t 지원
------------

지원하는 플랫폼에 대한 "wchar_t" 지원:

PyObject *PyUnicode_FromWideChar(const wchar_t *wstr, Py_ssize_t size)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object from the "wchar_t" buffer *wstr* of the
   given *size*. Passing "-1" as the *size* indicates that the
   function must itself compute the length, using "wcslen()". Return
   "NULL" on failure.

Py_ssize_t PyUnicode_AsWideChar(PyObject *unicode, wchar_t *wstr, Py_ssize_t size)
    * Part of the Stable ABI.*

   Copy the Unicode object contents into the "wchar_t" buffer *wstr*.
   At most *size* "wchar_t" characters are copied (excluding a
   possibly trailing null termination character).  Return the number
   of "wchar_t" characters copied or "-1" in case of an error.

   When *wstr* is "NULL", instead return the *size* that would be
   required to store all of *unicode* including a terminating null.

   Note that the resulting wchar_t* string may or may not be null-
   terminated.  It is the responsibility of the caller to make sure
   that the wchar_t* string is null-terminated in case this is
   required by the application. Also, note that the wchar_t* string
   might contain null characters, which would cause the string to be
   truncated when used with most C functions.

wchar_t *PyUnicode_AsWideCharString(PyObject *unicode, Py_ssize_t *size)
    * Part of the Stable ABI since version 3.7.*

   Convert the Unicode object to a wide character string. The output
   string always ends with a null character. If *size* is not "NULL",
   write the number of wide characters (excluding the trailing null
   termination character) into **size*. Note that the resulting
   "wchar_t" string might contain null characters, which would cause
   the string to be truncated when used with most C functions. If
   *size* is "NULL" and the wchar_t* string contains null characters a
   "ValueError" is raised.

   Returns a buffer allocated by "PyMem_New" (use "PyMem_Free()" to
   free it) on success. On error, returns "NULL" and **size* is
   undefined. Raises a "MemoryError" if memory allocation is failed.

   버전 3.2에 추가.

   버전 3.7에서 변경: Raises a "ValueError" if *size* is "NULL" and
   the wchar_t* string contains null characters.


내장 코덱
=========

파이썬은 속도를 위해 C로 작성된 내장 코덱 집합을 제공합니다. 이러한 코
덱들은 모두 다음 함수들을 통해 직접 사용할 수 있습니다.

다음 API의 대부분은 두 개의 인자 encoding과 errors를 취하며, 내장
"str()" 문자열 객체 생성자의 것들과 같은 의미입니다.

encoding을 "NULL"로 설정하면 기본 인코딩인 UTF-8이 사용됩니다. 파일 시
스템 호출은 파일 이름 인코딩에 "PyUnicode_FSConverter()"를 사용해야 합
니다. 이것은 내부적으로 변수 "Py_FileSystemDefaultEncoding" 을 사용합
니다. 이 변수는 읽기 전용으로 처리되어야 합니다: 일부 시스템에서는 정
적 문자열에 대한 포인터가 되고, 다른 시스템에서는 실행 시간에 변경됩니
다 (가령 응용 프로그램이 setlocale을 호출할 때).

에러 처리는 errors로 설정되는데, 코덱에 대해 정의된 기본 처리를 사용함
을 의미하는 "NULL"로 설정될 수도 있습니다. 모든 내장 코덱에 대한 기본
에러 처리는 "strict" 입니다 ("ValueError"가 발생합니다).

The codecs all use a similar interface.  Only deviations from the
following generic ones are documented for simplicity.


일반 코덱
---------

다음은 일반 코덱 API입니다:

PyObject *PyUnicode_Decode(const char *str, Py_ssize_t size, const char *encoding, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the encoded
   string *str*. *encoding* and *errors* have the same meaning as the
   parameters of the same name in the "str()" built-in function.  The
   codec to be used is looked up using the Python codec registry.
   Return "NULL" if an exception was raised by the codec.

PyObject *PyUnicode_AsEncodedString(PyObject *unicode, const char *encoding, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   유니코드 객체를 인코딩하고 결과를 파이썬 bytes 객체로 반환합니다.
   *encoding*과 *errors*는 유니코드 "encode()" 메서드의 같은 이름의 매
   개 변수와 같은 의미입니다. 사용할 코덱은 파이썬 코덱 레지스트리를
   사용하여 조회됩니다. 코덱에서 예외가 발생하면 "NULL"을 반환합니다.


UTF-8 코덱
----------

다음은 UTF-8 코덱 API입니다:

PyObject *PyUnicode_DecodeUTF8(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the UTF-8
   encoded string *str*. Return "NULL" if an exception was raised by
   the codec.

PyObject *PyUnicode_DecodeUTF8Stateful(const char *str, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)
    *Return value: New reference.** Part of the Stable ABI.*

   *consumed*가 "NULL"이면, "PyUnicode_DecodeUTF8()"처럼 동작합니다.
   *consumed*가 "NULL"이 아니면, 후행 불완전한 UTF-8 바이트 시퀀스는
   에러로 처리되지 않습니다. 이러한 바이트는 디코딩되지 않으며 디코딩
   된 바이트 수는 *consumed*에 저장됩니다.

PyObject *PyUnicode_AsUTF8String(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   UTF-8을 사용하여 유니코드 객체를 인코딩하고 결과를 파이썬 bytes 객
   체로 반환합니다. 에러 처리는 "strict" 입니다. 코덱에서 예외가 발생
   하면 "NULL"을 반환합니다.

const char *PyUnicode_AsUTF8AndSize(PyObject *unicode, Py_ssize_t *size)
    * Part of the Stable ABI since version 3.10.*

   유니코드 객체의 UTF-8 인코딩에 대한 포인터를 반환하고, 인코딩된 표
   현의 크기를 (바이트 단위로) *size*에 저장합니다. *size* 인자는
   "NULL"일 수 있습니다; 이 경우 크기가 저장되지 않습니다. 반환된 버퍼
   에는 다른 널 코드 포인트가 있는지에 관계없이, 항상 추가 널 바이트가
   추가됩니다 (*size*에 포함되지 않습니다).

   에러가 발생하면, "NULL"이 예외 설정과 함께 반환되고 *size*가 저장되
   지 않습니다.

   This caches the UTF-8 representation of the string in the Unicode
   object, and subsequent calls will return a pointer to the same
   buffer.  The caller is not responsible for deallocating the buffer.
   The buffer is deallocated and pointers to it become invalid when
   the Unicode object is garbage collected.

   버전 3.3에 추가.

   버전 3.7에서 변경: 반환형은 이제 "char *"가 아니라 "const char *"입
   니다.

   버전 3.10에서 변경: This function is a part of the limited API.

const char *PyUnicode_AsUTF8(PyObject *unicode)

   "PyUnicode_AsUTF8AndSize()"와 같지만, 크기를 저장하지 않습니다.

   버전 3.3에 추가.

   버전 3.7에서 변경: 반환형은 이제 "char *"가 아니라 "const char *"입
   니다.


UTF-32 코덱
-----------

다음은 UTF-32 코덱 API입니다:

PyObject *PyUnicode_DecodeUTF32(const char *str, Py_ssize_t size, const char *errors, int *byteorder)
    *Return value: New reference.** Part of the Stable ABI.*

   UTF-32로 인코딩된 버퍼 문자열에서 *size* 바이트를 디코딩하고 해당
   유니코드 객체를 반환합니다. *errors*("NULL"이 아니면)는 에러 처리를
   정의합니다. 기본값은 "strict"입니다.

   *byteorder*가 "NULL"이 아니면, 디코더는 지정된 바이트 순서를 사용하
   여 디코딩을 시작합니다:

      *byteorder == -1: little endian
      *byteorder == 0:  native order
      *byteorder == 1:  big endian

   "*byteorder"가 0이고, 입력 데이터의 처음 4바이트가 바이트 순서 표시
   (BOM)이면, 디코더가 이 바이트 순서로 전환되고 BOM은 결과 유니코드
   문자열에 복사되지 않습니다. "*byteorder"가 "-1"이나 "1"이면, 모든
   바이트 순서 표시가 출력에 복사됩니다.

   완료 후, **byteorder*는 입력 데이터의 끝에서 현재 바이트 순서로 설
   정됩니다.

   *byteorder*가 "NULL"이면, 코덱은 네이티브 순서 모드로 시작합니다.

   코덱에서 예외가 발생하면 "NULL"을 반환합니다.

PyObject *PyUnicode_DecodeUTF32Stateful(const char *str, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)
    *Return value: New reference.** Part of the Stable ABI.*

   *consumed*가 "NULL"이면, "PyUnicode_DecodeUTF32()"처럼 동작합니다.
   *consumed*가 "NULL"이 아니면, "PyUnicode_DecodeUTF32Stateful()" 은
   후행 불완전 UTF-32 바이트 시퀀스(가령 4로 나누어떨어지지 않는 바이
   트 수)를 에러로 처리하지 않습니다. 이러한 바이트는 디코딩되지 않으
   며 디코딩된 바이트 수는 *consumed*에 저장됩니다.

PyObject *PyUnicode_AsUTF32String(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   네이티브 바이트 순서로 UTF-32 인코딩을 사용하여 파이썬 바이트 문자
   열을 반환합니다. 문자열은 항상 BOM 마크로 시작합니다. 에러 처리는
   "strict"입니다. 코덱에서 예외가 발생하면 "NULL"을 반환합니다.


UTF-16 코덱
-----------

다음은 UTF-16 코덱 API입니다:

PyObject *PyUnicode_DecodeUTF16(const char *str, Py_ssize_t size, const char *errors, int *byteorder)
    *Return value: New reference.** Part of the Stable ABI.*

   UTF-16으로 인코딩된 버퍼 문자열에서 *size* 바이트를 디코딩하고 해당
   유니코드 객체를 반환합니다. *errors*("NULL"이 아니면)는 에러 처리를
   정의합니다. 기본값은 "strict"입니다.

   *byteorder*가 "NULL"이 아니면, 디코더는 지정된 바이트 순서를 사용하
   여 디코딩을 시작합니다:

      *byteorder == -1: little endian
      *byteorder == 0:  native order
      *byteorder == 1:  big endian

   "*byteorder"가 0이고, 입력 데이터의 처음 2바이트가 바이트 순서 표시
   (BOM)이면, 디코더는 이 바이트 순서로 전환되고 BOM은 결과 유니코드
   문자열에 복사되지 않습니다. "*byteorder"가 "-1"이나 "1"이면 모든 바
   이트 순서 표시가 출력에 복사됩니다 ("\ufeff"나 "\ufffe" 문자가 됩니
   다).

   After completion, "*byteorder" is set to the current byte order at
   the end of input data.

   *byteorder*가 "NULL"이면, 코덱은 네이티브 순서 모드로 시작합니다.

   코덱에서 예외가 발생하면 "NULL"을 반환합니다.

PyObject *PyUnicode_DecodeUTF16Stateful(const char *str, Py_ssize_t size, const char *errors, int *byteorder, Py_ssize_t *consumed)
    *Return value: New reference.** Part of the Stable ABI.*

   *consumed*가 "NULL"이면, "PyUnicode_DecodeUTF16()"처럼 동작합니다.
   *consumed*가 "NULL"이 아니면, "PyUnicode_DecodeUTF16Stateful()" 은
   후행 불완전 UTF-16 바이트 시퀀스(가령 홀수 바이트 수나 분할 서로게
   이트 쌍)를 에러로 처리하지 않습니다. 이러한 바이트는 디코딩되지 않
   으며 디코딩된 바이트 수는 *consumed*에 저장됩니다.

PyObject *PyUnicode_AsUTF16String(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   네이티브 바이트 순서로 UTF-16 인코딩을 사용하여 파이썬 바이트 문자
   열을 반환합니다. 문자열은 항상 BOM 마크로 시작합니다. 에러 처리는
   "strict"입니다. 코덱에서 예외가 발생하면 "NULL"을 반환합니다.


UTF-7 코덱
----------

다음은 UTF-7 코덱 API입니다:

PyObject *PyUnicode_DecodeUTF7(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the UTF-7
   encoded string *str*.  Return "NULL" if an exception was raised by
   the codec.

PyObject *PyUnicode_DecodeUTF7Stateful(const char *str, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)
    *Return value: New reference.** Part of the Stable ABI.*

   *consumed*가 "NULL"이면, "PyUnicode_DecodeUTF7()"처럼 동작합니다.
   *consumed*가 "NULL"이 아니면, 후행 불완전한 UTF-7 base-64 섹션은 에
   러로 처리되지 않습니다. 이러한 바이트는 디코딩되지 않으며 디코딩된
   바이트 수는 *consumed*에 저장됩니다.


유니코드 이스케이프 코덱
------------------------

다음은 "유니코드 이스케이프(Unicode Escape)" 코덱 API입니다:

PyObject *PyUnicode_DecodeUnicodeEscape(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the Unicode-
   Escape encoded string *str*.  Return "NULL" if an exception was
   raised by the codec.

PyObject *PyUnicode_AsUnicodeEscapeString(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   유니코드 이스케이프를 사용하여 유니코드 객체를 인코딩하고 결과를
   bytes 객체로 반환합니다. 에러 처리는 "strict"입니다. 코덱에서 예외
   가 발생하면 "NULL"을 반환합니다.


원시 유니코드 이스케이프 코덱
-----------------------------

다음은 "원시 유니코드 이스케이프(Raw Unicode Escape)" 코덱 API입니다:

PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the Raw-
   Unicode-Escape encoded string *str*.  Return "NULL" if an exception
   was raised by the codec.

PyObject *PyUnicode_AsRawUnicodeEscapeString(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   원시 유니코드 이스케이프를 사용하여 유니코드 객체를 인코딩하고 결과
   를 bytes 객체로 반환합니다. 에러 처리는 "strict"입니다. 코덱에서 예
   외가 발생하면 "NULL"을 반환합니다.


Latin-1 코덱
------------

다음은 Latin-1 코덱 API입니다: Latin-1은 처음 256개의 유니코드 서수에
해당하며 인코딩 중에 코덱에서 이들만 허용됩니다.

PyObject *PyUnicode_DecodeLatin1(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the Latin-1
   encoded string *str*.  Return "NULL" if an exception was raised by
   the codec.

PyObject *PyUnicode_AsLatin1String(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   Latin-1을 사용하여 유니코드 객체를 인코딩하고 결과를 파이썬 bytes
   객체로 반환합니다. 에러 처리는 "strict"입니다. 코덱에서 예외가 발생
   하면 "NULL"을 반환합니다.


ASCII 코덱
----------

다음은 ASCII 코덱 API입니다. 7비트 ASCII 데이터만 허용됩니다. 다른 모
든 코드는 에러를 생성합니다.

PyObject *PyUnicode_DecodeASCII(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the ASCII
   encoded string *str*.  Return "NULL" if an exception was raised by
   the codec.

PyObject *PyUnicode_AsASCIIString(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI.*

   ASCII를 사용하여 유니코드 객체를 인코딩하고 결과를 파이썬 bytes 객
   체로 반환합니다. 에러 처리는 "strict"입니다. 코덱에서 예외가 발생하
   면 "NULL"을 반환합니다.


문자 맵 코덱
------------

This codec is special in that it can be used to implement many
different codecs (and this is in fact what was done to obtain most of
the standard codecs included in the "encodings" package). The codec
uses mappings to encode and decode characters.  The mapping objects
provided must support the "__getitem__()" mapping interface;
dictionaries and sequences work well.

다음은 매핑 코덱 API입니다:

PyObject *PyUnicode_DecodeCharmap(const char *str, Py_ssize_t length, PyObject *mapping, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   Create a Unicode object by decoding *size* bytes of the encoded
   string *str* using the given *mapping* object.  Return "NULL" if an
   exception was raised by the codec.

   *mapping*이 "NULL"이면, Latin-1 디코딩이 적용됩니다. 그렇지 않으면
   *mapping*은 바이트 서수(0에서 255 사이의 정수)를 유니코드 문자열,
   정수(유니코드 서수로 해석됩니다) 또는 "None"으로 매핑해야합니다. 매
   핑되지 않은 데이터 바이트("None", "0xFFFE" 또는 "'\ufffe'"로 매핑되
   는 것뿐만 아니라, "LookupError"를 유발하는 것)은 정의되지 않은 매핑
   으로 처리되어 에러를 발생시킵니다.

PyObject *PyUnicode_AsCharmapString(PyObject *unicode, PyObject *mapping)
    *Return value: New reference.** Part of the Stable ABI.*

   주어진 *mapping* 객체를 사용하여 유니코드 객체를 인코딩하고 결과를
   bytes 객체로 반환합니다. 에러 처리는 "strict"입니다. 코덱에서 예외
   가 발생하면 "NULL"을 반환합니다.

   *mapping* 객체는 유니코드 서수 정수를 bytes 객체, 0에서 255 사이의
   정수 또는 "None"으로 매핑해야 합니다. "None"에 매핑되는 것뿐만 아니
   라 매핑되지 않은 문자 서수("LookupError"를 유발하는 것)는 "정의되지
   않은 매핑"으로 처리되어 에러가 발생합니다.

다음 코덱 API는 유니코드를 유니코드로 매핑한다는 점에서 특별합니다.

PyObject *PyUnicode_Translate(PyObject *unicode, PyObject *table, const char *errors)
    *Return value: New reference.** Part of the Stable ABI.*

   문자 매핑 테이블을 적용하여 문자열을 변환하고 결과 유니코드 객체를
   반환합니다. 코덱에서 예외가 발생하면 "NULL"을 반환합니다.

   매핑 테이블은 유니코드 서수 정수를 유니코드 서수 정수나 "None"(문자
   가 삭제되도록 합니다)에 매핑해야 합니다.

   Mapping tables need only provide the "__getitem__()" interface;
   dictionaries and sequences work well.  Unmapped character ordinals
   (ones which cause a "LookupError") are left untouched and are
   copied as-is.

   *errors*는 코덱에서의 일반적인 의미입니다. 기본 에러 처리를 사용함
   을 나타내는 "NULL"일 수 있습니다.


윈도우 용 MBCS 코덱
-------------------

다음은 MBCS 코덱 API입니다. 현재 윈도우에서만 사용할 수 있으며 Win32
MBCS 변환기를 사용하여 변환을 구현합니다. MBCS(또는 DBCS)는 단지 하나
가 아니라 인코딩 클래스임에 유의하십시오. 대상 인코딩은 코덱을 실행하
는 기계의 사용자 설정에 의해 정의됩니다.

PyObject *PyUnicode_DecodeMBCS(const char *str, Py_ssize_t size, const char *errors)
    *Return value: New reference.** Part of the Stable ABI on Windows
   since version 3.7.*

   Create a Unicode object by decoding *size* bytes of the MBCS
   encoded string *str*. Return "NULL" if an exception was raised by
   the codec.

PyObject *PyUnicode_DecodeMBCSStateful(const char *str, Py_ssize_t size, const char *errors, Py_ssize_t *consumed)
    *Return value: New reference.** Part of the Stable ABI on Windows
   since version 3.7.*

   *consumed*가 "NULL"이면, "PyUnicode_DecodeMBCS()"처럼 동작합니다.
   *consumed*가 "NULL"이 아니면, "PyUnicode_DecodeMBCSStateful()" 은
   후행 선행(lead) 바이트를 디코딩하지 않고 디코딩된 바이트 수가
   *consumed*에 저장됩니다.

PyObject *PyUnicode_AsMBCSString(PyObject *unicode)
    *Return value: New reference.** Part of the Stable ABI on Windows
   since version 3.7.*

   MBCS를 사용하여 유니코드 객체를 인코딩하고 결과를 파이썬 bytes 객체
   로 반환합니다. 에러 처리는 "strict"입니다. 코덱에서 예외가 발생하면
   "NULL"을 반환합니다.

PyObject *PyUnicode_EncodeCodePage(int code_page, PyObject *unicode, const char *errors)
    *Return value: New reference.** Part of the Stable ABI on Windows
   since version 3.7.*

   Encode the Unicode object using the specified code page and return
   a Python bytes object.  Return "NULL" if an exception was raised by
   the codec. Use "CP_ACP" code page to get the MBCS encoder.

   버전 3.3에 추가.


메서드와 슬롯
-------------


메서드와 슬롯 함수
==================

다음 API는 입력의 유니코드 객체와 문자열을 (설명에서 문자열이라고 하겠
습니다) 처리할 수 있으며 적절하게 유니코드 객체나 정수를 반환합니다.

예외가 발생하면 모두 "NULL"이나 "-1"을 반환합니다.

PyObject *PyUnicode_Concat(PyObject *left, PyObject *right)
    *Return value: New reference.** Part of the Stable ABI.*

   두 문자열을 이어붙여 하나의 새로운 유니코드 문자열을 제공합니다.

PyObject *PyUnicode_Split(PyObject *unicode, PyObject *sep, Py_ssize_t maxsplit)
    *Return value: New reference.** Part of the Stable ABI.*

   문자열을 분할하여 유니코드 문자열 리스트를 제공합니다. *sep*이
   "NULL"이면, 모든 공백 부분 문자열에서 분할이 수행됩니다. 그렇지 않
   으면, 주어진 구분자에서 분할이 일어납니다. 최대 *maxsplit* 분할이
   수행됩니다. 음수이면, 제한이 설정되지 않습니다. 구분자는 결과 리스
   트에 포함되지 않습니다.

PyObject *PyUnicode_Splitlines(PyObject *unicode, int keepends)
    *Return value: New reference.** Part of the Stable ABI.*

   Split a Unicode string at line breaks, returning a list of Unicode
   strings. CRLF is considered to be one line break.  If *keepends* is
   "0", the Line break characters are not included in the resulting
   strings.

PyObject *PyUnicode_Join(PyObject *separator, PyObject *seq)
    *Return value: New reference.** Part of the Stable ABI.*

   주어진 *separator*를 사용하여 문자열 시퀀스를 연결하고 결과 유니코
   드 문자열을 반환합니다.

Py_ssize_t PyUnicode_Tailmatch(PyObject *unicode, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)
    * Part of the Stable ABI.*

   Return "1" if *substr* matches "unicode[start:end]" at the given
   tail end (*direction* == "-1" means to do a prefix match,
   *direction* == "1" a suffix match), "0" otherwise. Return "-1" if
   an error occurred.

Py_ssize_t PyUnicode_Find(PyObject *unicode, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction)
    * Part of the Stable ABI.*

   Return the first position of *substr* in "unicode[start:end]" using
   the given *direction* (*direction* == "1" means to do a forward
   search, *direction* == "-1" a backward search).  The return value
   is the index of the first match; a value of "-1" indicates that no
   match was found, and "-2" indicates that an error occurred and an
   exception has been set.

Py_ssize_t PyUnicode_FindChar(PyObject *unicode, Py_UCS4 ch, Py_ssize_t start, Py_ssize_t end, int direction)
    * Part of the Stable ABI since version 3.7.*

   Return the first position of the character *ch* in
   "unicode[start:end]" using the given *direction* (*direction* ==
   "1" means to do a forward search, *direction* == "-1" a backward
   search).  The return value is the index of the first match; a value
   of "-1" indicates that no match was found, and "-2" indicates that
   an error occurred and an exception has been set.

   버전 3.3에 추가.

   버전 3.7에서 변경: *start* and *end* are now adjusted to behave
   like "unicode[start:end]".

Py_ssize_t PyUnicode_Count(PyObject *unicode, PyObject *substr, Py_ssize_t start, Py_ssize_t end)
    * Part of the Stable ABI.*

   Return the number of non-overlapping occurrences of *substr* in
   "unicode[start:end]".  Return "-1" if an error occurred.

PyObject *PyUnicode_Replace(PyObject *unicode, PyObject *substr, PyObject *replstr, Py_ssize_t maxcount)
    *Return value: New reference.** Part of the Stable ABI.*

   Replace at most *maxcount* occurrences of *substr* in *unicode*
   with *replstr* and return the resulting Unicode object. *maxcount*
   == "-1" means replace all occurrences.

int PyUnicode_Compare(PyObject *left, PyObject *right)
    * Part of the Stable ABI.*

   두 문자열을 비교하고 각각 작음, 같음, 큼에 대해 "-1", "0", "1"을 반
   환합니다.

   이 함수는 실패 시 "-1"을 반환하므로, 에러를 확인하기 위해
   "PyErr_Occurred()"를 호출해야 합니다.

int PyUnicode_CompareWithASCIIString(PyObject *unicode, const char *string)
    * Part of the Stable ABI.*

   Compare a Unicode object, *unicode*, with *string* and return "-1",
   "0", "1" for less than, equal, and greater than, respectively. It
   is best to pass only ASCII-encoded strings, but the function
   interprets the input string as ISO-8859-1 if it contains non-ASCII
   characters.

   이 함수는 예외를 발생시키지 않습니다.

PyObject *PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
    *Return value: New reference.** Part of the Stable ABI.*

   두 유니코드 문자열을 풍부한 비교(rich comparison) 하고 다음 중 하나
   를 반환합니다:

   * 예외가 발생하면 "NULL"

   * "Py_True" or "Py_False" for successful comparisons

   * "Py_NotImplemented" in case the type combination is unknown

   Possible values for *op* are "Py_GT", "Py_GE", "Py_EQ", "Py_NE",
   "Py_LT", and "Py_LE".

PyObject *PyUnicode_Format(PyObject *format, PyObject *args)
    *Return value: New reference.** Part of the Stable ABI.*

   *format*과 *args*에서 새 문자열 객체를 반환합니다; 이것은 "format %
   args"와 유사합니다.

int PyUnicode_Contains(PyObject *unicode, PyObject *substr)
    * Part of the Stable ABI.*

   Check whether *substr* is contained in *unicode* and return true or
   false accordingly.

   *substr* has to coerce to a one element Unicode string. "-1" is
   returned if there was an error.

void PyUnicode_InternInPlace(PyObject **p_unicode)
    * Part of the Stable ABI.*

   Intern the argument *p_unicode in place.  The argument must be the
   address of a pointer variable pointing to a Python Unicode string
   object.  If there is an existing interned string that is the same
   as *p_unicode, it sets *p_unicode to it (releasing the reference to
   the old string object and creating a new *strong reference* to the
   interned string object), otherwise it leaves *p_unicode alone and
   interns it (creating a new *strong reference*). (Clarification:
   even though there is a lot of talk about references, think of this
   function as reference-neutral; you own the object after the call if
   and only if you owned it before the call.)

PyObject *PyUnicode_InternFromString(const char *str)
    *Return value: New reference.** Part of the Stable ABI.*

   "PyUnicode_FromString()"과 "PyUnicode_InternInPlace()"의 조합, 인턴
   (intern) 된 새 유니코드 문자열 객체나, 같은 값을 가진 이전에 인턴
   된 문자열 객체에 대한 새 ("소유된") 참조를 반환합니다.
