"binascii" --- 바이너리와 ASCII 간의 변환
*****************************************

======================================================================

The "binascii" module contains a number of methods to convert between
binary and various ASCII-encoded binary representations. Normally, you
will not use these functions directly but use wrapper modules like
"base64" instead. The "binascii" module contains low-level functions
written in C for greater speed that are used by the higher-level
modules.

참고:

  "a2b_*" 함수는 ASCII 문자만 포함하는 유니코드 문자열을 받아들입니다.
  다른 함수는 *바이트열류 객체*(가령 "bytes", "bytearray" 및 버퍼 프로
  토콜을 지원하는 다른 객체)만 받아들입니다.

  버전 3.3에서 변경: ASCII로만 이루어진 유니코드 문자열은 이제 "a2b_*"
  함수에서 허용됩니다.

The "binascii" module defines the following functions:

binascii.a2b_uu(string)

   한 줄의 UU 인코딩된 데이터 string을 바이너리로 역변환하고 바이너리
   데이터를 반환합니다. 마지막 줄을 제외하고는, 줄은 보통 45 (바이너리
   ) 바이트를 포함합니다. 줄 데이터 뒤에는 공백 문자가 올 수 있습니다.

binascii.b2a_uu(data, *, backtick=False)

   바이너리 data를 ASCII 문자의 줄로 변환합니다, 반환 값은 개행 문자를
   포함하는 변환 된 줄입니다. *data*의 길이는 최대 45이어야 합니다.
   *backtick*가 참이면, 0은 스페이스 대신 "'`'"으로 표현됩니다.

   버전 3.7에서 변경: *backtick* 매개 변수가 추가되었습니다.

binascii.a2b_base64(string, /, *, padded=True, alphabet=BASE64_ALPHABET, strict_mode=False, canonical=False)
binascii.a2b_base64(string, /, *, ignorechars, padded=True, alphabet=BASE64_ALPHABET, strict_mode=True, canonical=False)

   base64 데이터 블록을 바이너리로 역변환하고 바이너리 데이터를 반환합
   니다. 한 번에 한 줄 이상을 전달할 수 있습니다.

   Optional *alphabet* must be a "bytes" object of length 64 which
   specifies an alternative alphabet.

   If *padded* is true, the last group of 4 base 64 alphabet
   characters must be padded with the '=' character. If *padded* is
   false, padding is neither required nor recognized: the '='
   character is not treated as padding but as a non-alphabet
   character, which means it is silently discarded when *strict_mode*
   is false, or causes an "Error" when *strict_mode* is true unless
   b'=' is included in *ignorechars*.

   If *ignorechars* is specified, it should be a *bytes-like object*
   containing characters to ignore from the input when *strict_mode*
   is true. If *ignorechars* contains the pad character "'='",  the
   pad characters presented before the end of the encoded data and the
   excess pad characters will be ignored. The default value of
   *strict_mode* is "True" if *ignorechars* is specified, "False"
   otherwise.

   If *strict_mode* is true, only valid base64 data will be converted.
   Invalid base64 data will raise "binascii.Error".

   Valid base64:

   * Conforms to **RFC 4648**.

   * Contains only characters from the base64 alphabet.

   * Contains no excess data after padding (including excess padding,
     newlines, etc.).

   * Does not start with a padding.

   If *canonical* is true, non-zero padding bits in the last group are
   rejected with "binascii.Error", enforcing canonical encoding as
   defined in **RFC 4648** section 3.5.  This check is independent of
   *strict_mode*.

   버전 3.11에서 변경: *strict_mode* 매개 변수가 추가되었습니다.

   버전 3.15에서 변경: Added the *alphabet*, *canonical*,
   *ignorechars*, and *padded* parameters.

binascii.b2a_base64(data, *, padded=True, alphabet=BASE64_ALPHABET, wrapcol=0, newline=True)

   Convert binary data to a line(s) of ASCII characters in base64
   coding, as specified in **RFC 4648**.

   If *padded* is true (default), pad the encoded data with the '='
   character to a size multiple of 4. If *padded* is false, do not add
   the pad characters.

   If *wrapcol* is non-zero, insert a newline ("b'\n'") character
   after at most every *wrapcol* characters. If *wrapcol* is zero
   (default), do not insert any newlines.

   If *newline* is true (default), a newline character will be added
   at the end of the output.

   버전 3.6에서 변경: *newline* 매개 변수가 추가되었습니다.

   버전 3.15에서 변경: Added the *alphabet*, *padded* and *wrapcol*
   parameters.

binascii.a2b_ascii85(string, /, *, foldspaces=False, adobe=False, ignorechars=b'', canonical=False)

   Convert Ascii85 data back to binary and return the binary data.

   Valid Ascii85 data contains characters from the Ascii85 alphabet in
   groups of five (except for the final group, which may have from two
   to five characters). Each group encodes 32 bits of binary data in
   the range from "0" to "2 ** 32 - 1", inclusive. The special
   character "z" is accepted as a short form of the group "!!!!!",
   which encodes four consecutive null bytes. A single-character final
   group is always rejected as an encoding violation.

   *foldspaces* is a flag that specifies whether the 'y' short
   sequence should be accepted as shorthand for 4 consecutive spaces
   (ASCII 0x20). This feature is not supported by the "standard"
   Ascii85 encoding.

   *adobe* controls whether the encoded byte sequence is framed with
   "<~" and "~>", as in a PostScript base-85 string literal.  If
   *adobe* is true, a leading "<~" is optionally accepted, while a
   trailing "~>" is *required*, and "binascii.Error" is raised if it
   is not found.

   *ignorechars* should be a *bytes-like object* containing characters
   to ignore from the input. This should only contain whitespace
   characters.

   If *canonical* is true, non-canonical encodings are rejected with
   "binascii.Error".  Here "canonical" means the encoding that
   "b2a_ascii85()" would produce: the "z" abbreviation must be used
   for all-zero groups (rather than "!!!!!"), and partial final groups
   must use the same padding digits as the encoder.

   Invalid Ascii85 data will raise "binascii.Error".

   Added in version 3.15.

binascii.b2a_ascii85(data, /, *, foldspaces=False, wrapcol=0, pad=False, adobe=False)

   Convert binary data to a formatted sequence of ASCII characters in
   Ascii85 coding. The return value is the converted data.

   *foldspaces* is an optional flag that uses the special short
   sequence 'y' instead of 4 consecutive spaces (ASCII 0x20) as
   supported by 'btoa'. This feature is not supported by the
   "standard" Ascii85 encoding.

   If *wrapcol* is non-zero, insert a newline ("b'\n'") character
   after at most every *wrapcol* characters. If *wrapcol* is zero
   (default), do not insert any newlines.

   If *pad* is true, the zero-padding applied to the end of the input
   is fully retained in the output encoding, as done by "btoa",
   producing an exact multiple of 5 bytes of output. This is not part
   of the standard encoding used in PDF, as it does not preserve the
   length of the data.

   *adobe* controls whether the encoded byte sequence is framed with
   "<~" and "~>", as in a PostScript base-85 string literal.  Note
   that while ASCII85Decode streams in PDF documents *must* be
   terminated with "~>", they *must not* use a leading "<~".

   Added in version 3.15.

binascii.a2b_base85(string, /, *, alphabet=BASE85_ALPHABET, ignorechars=b'', canonical=False)

   Convert Base85 data back to binary and return the binary data. More
   than one line may be passed at a time.

   Valid Base85 data contains characters from the Base85 alphabet in
   groups of five (except for the final group, which may have from two
   to five characters). Each group encodes 32 bits of binary data in
   the range from "0" to "2 ** 32 - 1", inclusive. A single-character
   final group is always rejected as an encoding violation.

   Optional *alphabet* must be a "bytes" object of length 85 which
   specifies an alternative alphabet.

   *ignorechars* should be a *bytes-like object* containing characters
   to ignore from the input.

   If *canonical* is true, non-canonical encodings are rejected with
   "binascii.Error".  Here "canonical" means the encoding that
   "b2a_base85()" would produce: partial final groups must use the
   same padding digits as the encoder.

   Invalid Base85 data will raise "binascii.Error".

   Added in version 3.15.

binascii.b2a_base85(data, /, *, alphabet=BASE85_ALPHABET, wrapcol=0, pad=False)

   Convert binary data to a line of ASCII characters in Base85 coding.
   The return value is the converted line.

   Optional *alphabet* must be a *bytes-like object* of length 85
   which specifies an alternative alphabet.

   If *wrapcol* is non-zero, insert a newline ("b'\n'") character
   after at most every *wrapcol* characters. If *wrapcol* is zero
   (default), do not insert any newlines.

   If *pad* is true, the zero-padding applied to the end of the input
   is retained in the output, which will always be a multiple of 5
   bytes, and thus the length of the data may not be preserved on
   decoding.

   Added in version 3.15.

binascii.a2b_base32(string, /, *, padded=True, alphabet=BASE32_ALPHABET, ignorechars=b'', canonical=False)

   Convert base32 data back to binary and return the binary data.

   Valid base32 data contains characters from the base32 alphabet
   specified in **RFC 4648** in groups of eight (if necessary, the
   final group is padded to eight characters with "="). Each group
   encodes 40 bits of binary data in the range from "0" to "2 ** 40 -
   1", inclusive.

   참고:

     This function does not map lowercase characters (which are
     invalid in standard base32) to their uppercase counterparts, nor
     does it contextually map "0" to "O" and "1" to "I"/"L" as **RFC
     4648** allows.

   Optional *alphabet* must be a "bytes" object of length 32 which
   specifies an alternative alphabet.

   If *padded* is true, the last group of 8 base 32 alphabet
   characters must be padded with the '=' character. If *padded* is
   false, the '=' character is treated as other non-alphabet
   characters (depending on the value of *ignorechars*).

   *ignorechars* should be a *bytes-like object* containing characters
   to ignore from the input. If *ignorechars* contains the pad
   character "'='",  the pad characters presented before the end of
   the encoded data and the excess pad characters will be ignored.

   If *canonical* is true, non-zero padding bits in the last group are
   rejected with "binascii.Error", enforcing canonical encoding as
   defined in **RFC 4648** section 3.5.

   Invalid base32 data will raise "binascii.Error".

   Added in version 3.15.

binascii.b2a_base32(data, /, *, padded=True, alphabet=BASE32_ALPHABET, wrapcol=0)

   Convert binary data to a line of ASCII characters in base32 coding,
   as specified in **RFC 4648**. The return value is the converted
   line.

   Optional *alphabet* must be a *bytes-like object* of length 32
   which specifies an alternative alphabet.

   If *padded* is true (default), pad the encoded data with the '='
   character to a size multiple of 8. If *padded* is false, do not add
   the pad characters.

   If *wrapcol* is non-zero, insert a newline ("b'\n'") character
   after at most every *wrapcol* characters. If *wrapcol* is zero
   (default), do not insert any newlines.

   Added in version 3.15.

binascii.a2b_qp(data, header=False)

   quoted-printable data 블록을 바이너리로 역변환하고 바이너리 데이터
   를 반환합니다. 한 번에 한 줄 이상을 전달할 수 있습니다. 선택적 인자
   *header*가 있고 참이면, 밑줄(underscore)은 스페이스로 디코딩됩니다.

binascii.b2a_qp(data, quotetabs=False, istext=True, header=False)

   바이너리 data를 quoted-printable 인코딩으로 ASCII 문자의 줄로 변환
   합니다. 반환 값은 변환된 줄입니다. 선택적 인자 *quotetabs*가 있고
   참이면, 모든 탭과 스페이스가 인코딩됩니다. 선택적 인자 *istext*가
   있고 참이면, 개행 문자는 인코딩되지 않지만, 후행 공백은 인코딩됩니
   다. 선택적 인자 *header*가 있고 참이면, 스페이스는 **RFC 1522**에
   따라 밑줄로 인코딩됩니다. 선택적 인자 *header*가 있고 거짓이면, 개
   행 문자도 함께 인코딩됩니다; 그렇지 않으면 라인 피드(linefeed) 변환
   이 바이너리 데이터 스트림을 손상할 수 있습니다.

binascii.crc_hqx(data, value)

   초기 CRC *value*로 시작하는, *data*의 16비트 CRC 값을 계산하고 결과
   를 반환합니다. 종종 0x1021로 표시되는, CRC-CCITT 다항식 *x*^16 +
   *x*^12 + *x*^5 + 1을 사용합니다. 이 CRC는 binhex4 형식에서 사용됩니
   다.

binascii.crc32(data[, value])

   초기 CRC *value*로 시작하는, *data*의 부호 없는 32비트 체크섬인
   CRC-32를 계산합니다. 기본 초기 CRC는 0입니다. 이 알고리즘은 ZIP 파
   일 체크섬과 일치합니다. 이 알고리즘은 체크섬 알고리즘으로 사용하도
   록 설계되었으므로, 일반 해시 알고리즘으로 사용하기에 적합하지 않습
   니다. 다음과 같이 사용하십시오:

      print(binascii.crc32(b"hello world"))
      # 또는, 두 조각으로:
      crc = binascii.crc32(b"hello")
      crc = binascii.crc32(b" world", crc)
      print('crc32 = {:#010x}'.format(crc))

   버전 3.0에서 변경: The result is always unsigned.

binascii.b2a_hex(data[, sep[, bytes_per_sep=1]])
binascii.hexlify(data[, sep[, bytes_per_sep=1]])

   바이너리 *data*의 16진수 표현을 반환합니다. *data*의 모든 바이트는
   해당 2자리 16진수 표현으로 변환됩니다. 따라서 반환된 바이트열 객체
   의 길이는 *data* 의 두 배입니다.

   비슷한 기능(하지만 텍스트 문자열을 반환하는)을 "bytes.hex()" 메서드
   를 사용하여 편리하게 액세스할 수도 있습니다.

   *sep*이 지정되면, 단일 문자 문자열이나 바이트열 객체여야 합니다.
   *bytes_per_sep* 입력 바이트마다 출력에 삽입됩니다. 구분자 배치는 기
   본적으로 출력의 오른쪽 끝에서부터 계산됩니다. 왼쪽부터 계산하려면,
   음수의 *bytes_per_sep* 값을 제공하십시오.

   >>> import binascii
   >>> binascii.b2a_hex(b'\xb9\x01\xef')
   b'b901ef'
   >>> binascii.hexlify(b'\xb9\x01\xef', '-')
   b'b9-01-ef'
   >>> binascii.b2a_hex(b'\xb9\x01\xef', b'_', 2)
   b'b9_01ef'
   >>> binascii.b2a_hex(b'\xb9\x01\xef', b' ', -2)
   b'b901 ef'

   버전 3.8에서 변경: *sep*과 *bytes_per_sep* 매개 변수가 추가되었습니
   다.

binascii.a2b_hex(hexstr, *, ignorechars=b'')
binascii.unhexlify(hexstr, *, ignorechars=b'')

   16진수 문자열 *hexstr*로 표현된 바이너리 데이터를 반환합니다. 이 함
   수는 "b2a_hex()"의 역함수입니다. *hexstr*는 짝수개의 16진수(대소문
   자 모두 가능합니다)를 포함해야 하며, 그렇지 않으면 "Error" 예외가
   발생합니다.

   *ignorechars* should be a *bytes-like object* containing characters
   to ignore from the input.

   비슷한 기능(텍스트 문자열 인자만 받아들이지만, 공백에 대해 더 느슨
   한)을 "bytes.fromhex()" 클래스 메서드를 사용하여 액세스할 수도 있습
   니다.

   버전 3.15에서 변경: Added the *ignorechars* parameter.

exception binascii.Error

   에러 시 발생하는 예외. 이들은 대개 프로그래밍 에러입니다.

exception binascii.Incomplete

   불완전한 데이터에서 발생하는 예외. 이들은 일반적으로 프로그래밍 에
   러가 아니지만, 조금 더 많은 데이터를 읽고 다시 시도하면 처리될 수
   있습니다.

binascii.BASE64_ALPHABET

   The Base 64 alphabet according to **RFC 4648**.

   Added in version 3.15.

binascii.URLSAFE_BASE64_ALPHABET

   The "URL and filename safe" Base 64 alphabet according to **RFC
   4648**.

   Added in version 3.15.

binascii.UU_ALPHABET

   The uuencoding alphabet.

   Added in version 3.15.

binascii.CRYPT_ALPHABET

   The Base 64 alphabet used in the *crypt(3)* routine and in the
   GEDCOM format.

   Added in version 3.15.

binascii.BINHEX_ALPHABET

   The Base 64 alphabet used in BinHex 4 (HQX) within the classic Mac
   OS.

   Added in version 3.15.

binascii.BASE85_ALPHABET

   The Base85 alphabet.

   Added in version 3.15.

binascii.ASCII85_ALPHABET

   The Ascii85 alphabet.

   Added in version 3.15.

binascii.Z85_ALPHABET

   The Z85 alphabet.

   Added in version 3.15.

binascii.BASE32_ALPHABET

   The Base 32 alphabet according to **RFC 4648**.

   Added in version 3.15.

binascii.BASE32HEX_ALPHABET

   The "Extended Hex" Base 32 alphabet according to **RFC 4648**. Data
   encoded with this alphabet maintains its sort order during bitwise
   comparisons.

   Added in version 3.15.

더 보기:

  모듈 "base64"
     RFC 호환 base64 스타일 인코딩으로, 베이스 16, 32, 64 및 85를 지원
     합니다.

  모듈 "quopri"
     MIME 전자 우편 메시지에 사용되는 quoted-printable 인코딩 지원.
