stringprep --- 網際網路字串的準備¶
在網際網路上識別事物(例如主機名稱)時,通常需要比較這些識別器的「相等性 (equality)」。比較的具體執行方式可能取決於應用程式領域,例如是否應該不區分大小寫。也可能有必要限制可能的識別器,只允許由「可列印 (printable)」字元組成的識別器。
RFC 3454 定義了在網際網路通訊協定中「準備」Unicode 字串的程序。在傳送字串到網路之前,先使用準備程序處理字串,之後字串就具有特定的規範化 (normalized) 形式。RFC 定義了一系列的表,這些表可以組合成設定檔 (profile)。每個設定檔必須定義它使用哪些表以及 stringprep 程序的哪些其他可選部分是設定檔的一部分。stringprep 配置文件的一個例子是 nameprep,它被用於國際化網域名稱。
The module stringprep only exposes the tables from RFC 3454. As these
tables would be very large to represent as dictionaries or lists, the
module uses the Unicode character database internally. The module source code
itself was generated using the mkstringprep.py utility.
As a result, these tables are exposed as functions, not as data structures.
There are two kinds of tables in the RFC: sets and mappings. For a set,
stringprep provides the "characteristic function", i.e. a function that
returns True if the parameter is part of the set. For mappings, it provides the
mapping function: given the key, it returns the associated value. Below is a
list of all functions available in the module.
- stringprep.in_table_a1(code)¶
判斷 code 是否在 tableA.1(Unicode 3.2 中未指定的編碼位置 (code point))中。
- stringprep.in_table_b1(code)¶
判斷 code 是否在 tableB.1(通常沒有對映到任何東西)中。
- stringprep.map_table_b2(code)¶
根據 tableB.2(使用 NFKC 形式的大小寫折疊 (case-folding) 對映)回傳 code 的對映值。
- stringprep.map_table_b3(code)¶
根據 tableB.3(使用沒有規範化的大小寫折疊對映)回傳 code 的對映值。
- stringprep.in_table_c11(code)¶
判斷 code 是否在 tableC.1.1(ASCII 空格字元)中。
- stringprep.in_table_c12(code)¶
判斷 code 是否在 tableC.1.2(非 ASCII 空格字元)中。
- stringprep.in_table_c11_c12(code)¶
判斷 code 是否在 tableC.1(空格字元,為 C.1.1 和 C.1.2 的聯集)中。
- stringprep.in_table_c21(code)¶
判斷 code 是否在 tableC.2.1(ASCII 控制字元)中。
- stringprep.in_table_c22(code)¶
判斷 code 是否在 tableC.2.2(非 ASCII 控制字元)中。
- stringprep.in_table_c21_c22(code)¶
判斷 code 是否在 tableC.2(控制字元,為 C.2.1 和 C.2.2 的聯集)中。
- stringprep.in_table_c3(code)¶
判斷 code 是否在 tableC.3(私有使用)中。
- stringprep.in_table_c4(code)¶
判斷 code 是否在 tableC.4(非字元編碼位置)中。
- stringprep.in_table_c5(code)¶
判斷 code 是否在 tableC.5(代理碼)中。
- stringprep.in_table_c6(code)¶
判斷 code 是否在 tableC.6(不適用於純文字)中。
- stringprep.in_table_c7(code)¶
判斷 code 是否在 tableC.7(不適用於規範表示法 (canonical representation))中。
- stringprep.in_table_c8(code)¶
判斷 code 是否在 tableC.8(變更顯示屬性或已棄用)中。
- stringprep.in_table_c9(code)¶
判斷 code 是否在 tableC.9(標記字元 (tagging characters))中。
- stringprep.in_table_d1(code)¶
判斷 code 是否在 tableD.1(具有雙向屬性 "R" 或 "AL" 的字元)中。
- stringprep.in_table_d2(code)¶
判斷 code 是否在 tableD.2(具有雙向屬性 "L" 的字元)中。