美文网首页
标准库之stringprep

标准库之stringprep

作者: __XY__ | 来源:发表于2017-05-26 19:25 被阅读0次

python标准库对于这个库的介绍不是很全面,所以今天严小日就粘贴到这里并友情提供下翻译(翻译是根据理解的文意翻译的,而不是逐字翻译的,所以可能会有出入):
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. 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. Each profile must define which tables it uses, and what other optional parts of the stringprep
procedure are part of the profile. One example of a stringprep
profile is nameprep
, which is used for internationalized domain names.
The module stringprep
only exposes the tables from RFC 3454. As these tables would be very large to represent them 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.

当你在网上区别类似主机名字的时候,需要区别这些hostname是否确切相同,特别是如今比较操作都依赖应用,比如是否大小写要区分开.同时也很好必要去限制标识:全部由仅可以打印的字符组成,所以不会exactly equale
那么由此RFC 3454就定义了一个程序用来在互联网中prepara unicode字符串: 在将字符串发送到网线之前,被预先的程序提前处理,这样处理完后他们就有了规范化的样式,
RFC定义了很多表格,这些表格组成了大体的一个轮廓,每个程序都是其中的一员,一个例子就是nameprep,这个可以被用作国际通用domain name
stringprep 只显示了RFC3454中的表格,因为这些表格如果用字典或者列别表示的话会非常大,所以内部采用了Unicode编码,模块原代码本身是采用mkstringgrep.py生成的
因此,这些表的表现形式为函数,而不是数据结构,RFC表格中有两种表格,其中一种提供了'特征函数',可以判断参数是否在集合中如果是就返回TRue,
另外一种是映射,提供了映射函数:根据key提供关联的数值.

ps:这个库有点偏冷门了,很少用到,但是根据这个库顺便了解下RFC是很有必要的

相关文章

  • 标准库之stringprep

    python标准库对于这个库的介绍不是很全面,所以今天严小日就粘贴到这里并友情提供下翻译(翻译是根据理解的文意翻译...

  • Python基本图形绘制

    turtle库的使用 turtle库概述 turtle(海龟)库是turtle绘图体系的Python体现 标准库之...

  • 标准库之linecache

    一有什么做用,什么情况下使用作用是从任何文件中读取任意行,使用缓存进行了优化,我的理解是如果你需要反复的使用一个文...

  • 标准库之Argparse

    今日主要是学习了标准库中的argparse模块做什么用?命令行解析工具参考文章 :http://lingxiank...

  • Python标准库之string 库

    Python Standard Library based on Python 3.7.3 https://doc...

  • python标准库之argparse

    python 标准库之argparse 库名:argparse 作用:命令行解析, 在win下的cmd窗口中,我...

  • Swift中常用的数据结构(上)

    Swift是一门功能强大的编程语言,不过,如果没有强大的标准库与之相匹配,功能再强大也都是徒劳。Swift标准库中...

  • #抬抬小手学Python# 内置 random 模块【附源码】

    Python 内置模块之 random random 库是 Python 中生成随机数的标准库,包含的函数清单如下...

  • JS标准库之Array

    String(1) // ‘1’ ...

  • go 标准库之builtin

    废话 自从学习完go基础以后不知道何去何从了。由于是纯粹的自学并且没有任何项目需求,学好一门编程语言确实很难。为了...

网友评论

      本文标题:标准库之stringprep

      本文链接:https://www.haomeiwen.com/subject/fwtxfxtx.html