uuid 默认的 NAMESPACE_DNS 是根据什么 DNS 生成的?

2018-04-14 10:35:47 +08:00
 miniyao

用 uuid3()生成 uuid:

uuid.uuid3(uuid.NAMESPACE_DNS, 'string_a')  

官方文档就一句:

The following standard UUIDs are for use with uuid3() or uuid5().

NAMESPACE_DNS = UUID('6ba7b810-9dad-11d1-80b4-00c04fd430c8')

这个 '6ba7b810-9dad-11d1-80b4-00c04fd430c8' 是根据什么 DNS 生成的?须要改成自定义的吗?

3846 次点击
所在节点    Python
3 条回复
eastpiger
2018-04-14 11:36:57 +08:00
他不是根据 DNS 生成的,他是一个预置的 namesapce 标记,一般这个 namespace 内的值是 dns 类型的数据。

Namespace 可以是任意 uuid 字符串,你可以选择 uuid1 或者 uuid4 或者自己随便编造一个合法数据使用。


根据文档,可以找到预置的 uuid dns namespace 是怎么算的。For version 3 and version 5 UUIDs the additional command line arguments namespace and name have to be given. The namespace is either a UUID in string representation or an identifier for internally pre-defined namespace UUIDs (currently known are "ns:DNS", "ns:URL", "ns:OID", and "ns:X500"). The name is a string of arbitrary length.
miniyao
2018-04-14 11:57:45 +08:00
@eastpiger 谢谢!看了官方文档中: https 冒号 //docs 点 python 点 org/3/library/uuid.html

有这么一句说明:
uuid.NAMESPACE_DNS
When this namespace is specified, the name string is a fully-qualified domain name.

你说的 The name is a string of arbitrary length. 文档中说明的那句:如果指定了 namesapce,the name string is a fully-qualified domain name. (为什么还要 fully-qualified domain name ?不是 arbitrary length 的 string 都可以吗?)
julyclyde
2018-04-14 23:13:44 +08:00
@miniyao 你看 Java 的类名也是个域名(逆序写出来的)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/446726

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX