stringprepInternet String PreparationInternet字符串准备

Source code: Lib/stringprep.py


When identifying things (such as host names) in the internet, it is often necessary to compare such identifications for “equality”. 在识别互联网上的事物(如主机名)时,通常需要比较这些标识是否“平等”。Exactly how this comparison is executed may depend on the application domain, e.g. whether it should be case-insensitive or not. 这种比较的具体执行方式可能取决于应用程序域,例如,它是否应该不区分大小写。It may be also necessary to restrict the possible identifications, to allow only identifications consisting of “printable” characters.可能还需要限制可能的标识,只允许包含“可打印”字符的标识。

RFC 3454 defines a procedure for “preparing” Unicode strings in internet protocols. 定义在internet协议中“准备”Unicode字符串的过程。Before passing strings onto the wire, they are processed with the preparation procedure, after which they have a certain normalized form. 在将字符串传递到导线上之前,将使用准备过程对其进行处理,然后使其具有某种规范化形式。The RFC defines a set of tables, which can be combined into profiles. RFC定义了一组表,这些表可以组合到配置文件中。Each profile must define which tables it uses, and what other optional parts of the stringprep procedure are part of the profile. 每个概要文件必须定义它使用的表,以及stringprep过程的其他可选部分是概要文件的一部分。One example of a stringprep profile is nameprep, which is used for internationalized domain names.stringprep配置文件的一个示例是nameprep,用于国际化域名。

The module stringprep only exposes the tables from RFC 3454. stringprep模块仅公开RFC 3454中的表。As these tables would be very large to represent them as dictionaries or lists, the module uses the Unicode character database internally. 由于这些表将非常大,以字典或列表的形式表示,因此该模块在内部使用Unicode字符数据库。The module source code itself was generated using the mkstringprep.py utility.模块源代码本身是使用mkstringprep.py实用程序生成的。

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. RFC中有两种表:集合和映射。For a set, stringprep provides the “characteristic function”, i.e. a function that returns True if the parameter is part of the set. 对于集合,stringprep提供“特征函数”,即如果参数是集合的一部分,则返回True的函数。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)

Determine whether code is in tableA.1 (Unassigned code points in Unicode 3.2).确定code是否在表A中。1(Unicode 3.2中的未分配代码点)。

stringprep.in_table_b1(code)

Determine whether code is in tableB.1 (Commonly mapped to nothing).确定code是否在表B中。1(通常映射为nothing)。

stringprep.map_table_b2(code)

Return the mapped value for code according to tableB.2 (Mapping for case-folding used with NFKC).根据表B.2(与NFKC一起使用的案例折叠映射)返回code的映射值。

stringprep.map_table_b3(code)

Return the mapped value for code according to tableB.3 (Mapping for case-folding used with no normalization).根据表B.3(在没有归一化的情况下使用大小写折叠映射)返回code的映射值。

stringprep.in_table_c11(code)

Determine whether code is in tableC.1.1 (ASCII space characters).确定code是否在表C.1.1(ASCII空格字符)中。

stringprep.in_table_c12(code)

Determine whether code is in tableC.1.2 (Non-ASCII space characters).确定code是否在表C.1.2(非ASCII空格字符)中。

stringprep.in_table_c11_c12(code)

Determine whether code is in tableC.1 (Space characters, union of C.1.1 and C.1.2).确定code是否在表C.1(空格字符,C.1.1和C.1.2的并集)中。

stringprep.in_table_c21(code)

Determine whether code is in tableC.2.1 (ASCII control characters).确定code是否在表C.2.1(ASCII控制字符)中。

stringprep.in_table_c22(code)

Determine whether code is in tableC.2.2 (Non-ASCII control characters).确定code是否在表C.2.2(非ASCII控制字符)中。

stringprep.in_table_c21_c22(code)

Determine whether code is in tableC.2 (Control characters, union of C.2.1 and C.2.2).确定code是否在表C.2(控制字符,C.2.1和C.2.2的并集)中。

stringprep.in_table_c3(code)

Determine whether code is in tableC.3 (Private use).确定code是否在表C.3(私人使用)中。

stringprep.in_table_c4(code)

Determine whether code is in tableC.4 (Non-character code points).确定code是否在表C.4(非字符代码点)中。

stringprep.in_table_c5(code)

Determine whether code is in tableC.5 (Surrogate codes).确定code是否在表C.5(代理代码)中。

stringprep.in_table_c6(code)

Determine whether code is in tableC.6 (Inappropriate for plain text).确定code是否在表C.6(不适用于纯文本)中。

stringprep.in_table_c7(code)

Determine whether code is in tableC.7 (Inappropriate for canonical representation).确定code是否在表C.7(不适用于规范表示)中。

stringprep.in_table_c8(code)

Determine whether code is in tableC.8 (Change display properties or are deprecated).确定code是否在表C.8(更改显示属性或已弃用)中。

stringprep.in_table_c9(code)

Determine whether code is in tableC.9 (Tagging characters).确定code是否在表C.9(标记字符)中。

stringprep.in_table_d1(code)

Determine whether code is in tableD.1 (Characters with bidirectional property “R” or “AL”).确定代码是否在表D.1(具有双向属性“R”或“AL”的字符)中。

stringprep.in_table_d2(code)

Determine whether code is in tableD.2 (Characters with bidirectional property “L”).确定代码是否在表D.2(具有双向属性“L”的字符)中。