"unicodedata" — Unicode データベース
************************************

This module provides access to the Unicode Character Database which
defines character properties for all Unicode characters. The data in
this database is based on the "UnicodeData.txt" file version 5.2.0
which is publicly available from ftp://ftp.unicode.org/.

The module uses the same names and symbols as defined by the
UnicodeData File Format 5.2.0 (see
http://www.unicode.org/reports/tr44/tr44-4.html). It defines the
following functions:

unicodedata.lookup(name)

   Look up character by name.  If a character with the given name is
   found, return the corresponding Unicode character.  If not found,
   "KeyError" is raised.

unicodedata.name(unichr[, default])

   Returns the name assigned to the Unicode character *unichr* as a
   string. If no name is defined, *default* is returned, or, if not
   given, "ValueError" is raised.

unicodedata.decimal(unichr[, default])

   Returns the decimal value assigned to the Unicode character
   *unichr* as integer. If no such value is defined, *default* is
   returned, or, if not given, "ValueError" is raised.

unicodedata.digit(unichr[, default])

   Returns the digit value assigned to the Unicode character *unichr*
   as integer. If no such value is defined, *default* is returned, or,
   if not given, "ValueError" is raised.

unicodedata.numeric(unichr[, default])

   Returns the numeric value assigned to the Unicode character
   *unichr* as float. If no such value is defined, *default* is
   returned, or, if not given, "ValueError" is raised.

unicodedata.category(unichr)

   Returns the general category assigned to the Unicode character
   *unichr* as string.

unicodedata.bidirectional(unichr)

   Returns the bidirectional class assigned to the Unicode character
   *unichr* as string. If no such value is defined, an empty string is
   returned.

unicodedata.combining(unichr)

   Returns the canonical combining class assigned to the Unicode
   character *unichr* as integer. Returns "0" if no combining class is
   defined.

unicodedata.east_asian_width(unichr)

   Returns the east asian width assigned to the Unicode character
   *unichr* as string.

   バージョン 2.4 で追加.

unicodedata.mirrored(unichr)

   Returns the mirrored property assigned to the Unicode character
   *unichr* as integer. Returns "1" if the character has been
   identified as a 「mirrored」 character in bidirectional text, "0"
   otherwise.

unicodedata.decomposition(unichr)

   Returns the character decomposition mapping assigned to the Unicode
   character *unichr* as string. An empty string is returned in case
   no such mapping is defined.

unicodedata.normalize(form, unistr)

   Unicode 文字列 *unistr* の正規形 *form* を返します。 *form* の有効
   な値は、』NFC』、』NFKC』、』NFD』、』NFKD』 です。

   Unicode 規格は標準等価性 (canonical equivalence) と互換等価性
   (compatibility equivalence) に基づいて、様々な Unicode文字列の正規
   形を定義します。Unicode では、複数の方法で表現できる文字があります
   。たとえば、文字 U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) は、
   U+0043 (LATIN CAPITAL LETTER C) U+0327 (COMBINING CEDILLA) というシ
   ーケンスとしても表現できます。

   各文字には2つの正規形があり、それぞれ正規形 C と正規形 D といいます
   。正規形 D (NFD) は標準分解 (canonical decomposition) としても知ら
   れており、各文字を分解された形に変換します。正規形 C (NFC) は標準分
   解を適用した後、結合済文字を再構成します。

   互換等価性に基づいて、2つの正規形が加えられています。Unicode では、
   一般に他の文字との統合がサポートされている文字があります。たとえば
   、U+2160 (ROMAN NUMERAL ONE) は事実上 U+0049 (LATIN CAPITAL LETTER
   I) と同じものです。しかし、Unicode では、既存の文字集合 (たとえば
   gb2312) との互換性のために、これがサポートされています。

   正規形 KD (NFKD) は、互換分解 (compatibility decomposition) を適用
   します。すなわち、すべての互換文字を、等価な文字で置換します。正規
   形 KC (NFKC) は、互換分解を適用してから、標準分解を適用します。

   2つのunicode文字列が正規化されていて人間の目に同じに見えても、片方
   が結合文字を持っていてもう片方が持っていない場合、それらは完全に同
   じではありません。

   バージョン 2.3 で追加.

更に、本モジュールは以下の定数を公開します:

unicodedata.unidata_version

   このモジュールで使われている Unicode データベースのバージョン。

   バージョン 2.3 で追加.

unicodedata.ucd_3_2_0

   これはモジュール全体と同じメソッドを具えたオブジェクトですが、
   Unicode データベースバージョン 3.2 を代わりに使っており、この特定の
   バージョンの Unicode データベースを必要とするアプリケーション(IDNA
   など)のためものです。

   バージョン 2.5 で追加.

例:

>>> import unicodedata
>>> unicodedata.lookup('LEFT CURLY BRACKET')
u'{'
>>> unicodedata.name(u'/')
'SOLIDUS'
>>> unicodedata.decimal(u'9')
9
>>> unicodedata.decimal(u'a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not a decimal
>>> unicodedata.category(u'A')  # 'L'etter, 'u'ppercase
'Lu'
>>> unicodedata.bidirectional(u'\u0660') # 'A'rabic, 'N'umber
'AN'
