开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

source-code-analysis/python3.8.1

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python3.8.1
/
Doc
/
library
/
uuid.rst
python3.8.1
/
Doc
/
library
/
uuid.rst
uuid.rst 9.94 KB
一键复制 编辑 原始数据 按行查看 历史
zhangweibo 提交于 2021年11月16日 09:46 +08:00 . git init

:mod:`uuid` --- UUID objects according to :source:`Lib/uuid.py`


This module provides immutable :class:`UUID` objects (the :class:`UUID` class) and the functions :func:`uuid1`, :func:`uuid3`, :func:`uuid4`, :func:`uuid5` for generating version 1, 3, 4, and 5 UUIDs as specified in :func:`uuid1` or :func:`uuid4`. Note that :func:`uuid1` may compromise privacy since it creates a UUID containing the computer's network address. :func:`uuid4` creates a random UUID.

Depending on support from the underlying platform, :func:`uuid1` may or may not return a "safe" UUID. A safe UUID is one which is generated using synchronization methods that ensure no two processes can obtain the same UUID. All instances of :class:`UUID` have an :attr:`is_safe` attribute which relays any information about the UUID's safety, using this enumeration:

.. versionadded:: 3.7

.. attribute:: SafeUUID.safe

 The UUID was generated by the platform in a multiprocessing-safe way.

.. attribute:: SafeUUID.unsafe

 The UUID was not generated in a multiprocessing-safe way.

.. attribute:: SafeUUID.unknown

 The platform does not provide information on whether the UUID was
 generated safely or not.

:class:`UUID` instances have these read-only attributes:

.. attribute:: UUID.bytes

 The UUID as a 16-byte string (containing the six integer fields in big-endian
 byte order).


.. attribute:: UUID.bytes_le

 The UUID as a 16-byte string (with *time_low*, *time_mid*, and *time_hi_version*
 in little-endian byte order).


.. attribute:: UUID.fields

 A tuple of the six integer fields of the UUID, which are also available as six
 individual attributes and two derived attributes:

 +------------------------------+-------------------------------+
 | Field | Meaning |
 +==============================+===============================+
 | :attr:`time_low` | the first 32 bits of the UUID |
 +------------------------------+-------------------------------+
 | :attr:`time_mid` | the next 16 bits of the UUID |
 +------------------------------+-------------------------------+
 | :attr:`time_hi_version` | the next 16 bits of the UUID |
 +------------------------------+-------------------------------+
 | :attr:`clock_seq_hi_variant` | the next 8 bits of the UUID |
 +------------------------------+-------------------------------+
 | :attr:`clock_seq_low` | the next 8 bits of the UUID |
 +------------------------------+-------------------------------+
 | :attr:`node` | the last 48 bits of the UUID |
 +------------------------------+-------------------------------+
 | :attr:`time` | the 60-bit timestamp |
 +------------------------------+-------------------------------+
 | :attr:`clock_seq` | the 14-bit sequence number |
 +------------------------------+-------------------------------+


.. attribute:: UUID.hex

 The UUID as a 32-character hexadecimal string.


.. attribute:: UUID.int

 The UUID as a 128-bit integer.


.. attribute:: UUID.urn

 The UUID as a URN as specified in :rfc:`4122`.


.. attribute:: UUID.variant

 The UUID variant, which determines the internal layout of the UUID. This will be
 one of the constants :const:`RESERVED_NCS`, :const:`RFC_4122`,
 :const:`RESERVED_MICROSOFT`, or :const:`RESERVED_FUTURE`.


.. attribute:: UUID.version

 The UUID version number (1 through 5, meaningful only when the variant is
 :const:`RFC_4122`).

.. attribute:: UUID.is_safe

 An enumeration of :class:`SafeUUID` which indicates whether the platform
 generated the UUID in a multiprocessing-safe way.

 .. versionadded:: 3.7

The :mod:`uuid` module defines the following functions:

.. function:: getnode()

 Get the hardware address as a 48-bit positive integer. The first time this
 runs, it may launch a separate program, which could be quite slow. If all
 attempts to obtain the hardware address fail, we choose a random 48-bit
 number with the multicast bit (least significant bit of the first octet)
 set to 1 as recommended in :rfc:`4122`. "Hardware address" means the MAC
 address of a network interface. On a machine with multiple network
 interfaces, universally administered MAC addresses (i.e. where the second
 least significant bit of the first octet is *unset*) will be preferred over
 locally administered MAC addresses, but with no other ordering guarantees.

 .. versionchanged:: 3.7
 Universally administered MAC addresses are preferred over locally
 administered MAC addresses, since the former are guaranteed to be
 globally unique, while the latter are not.

.. index:: single: getnode


.. function:: uuid1(node=None, clock_seq=None)

 Generate a UUID from a host ID, sequence number, and the current time. If *node*
 is not given, :func:`getnode` is used to obtain the hardware address. If
 *clock_seq* is given, it is used as the sequence number; otherwise a random
 14-bit sequence number is chosen.

.. index:: single: uuid1


.. function:: uuid3(namespace, name)

 Generate a UUID based on the MD5 hash of a namespace identifier (which is a
 UUID) and a name (which is a string).

.. index:: single: uuid3


.. function:: uuid4()

 Generate a random UUID.

.. index:: single: uuid4


.. function:: uuid5(namespace, name)

 Generate a UUID based on the SHA-1 hash of a namespace identifier (which is a
 UUID) and a name (which is a string).

.. index:: single: uuid5

The :mod:`uuid` module defines the following namespace identifiers for use with :func:`uuid3` or :func:`uuid5`.

.. data:: NAMESPACE_DNS

 When this namespace is specified, the *name* string is a fully-qualified domain
 name.


.. data:: NAMESPACE_URL

 When this namespace is specified, the *name* string is a URL.


.. data:: NAMESPACE_OID

 When this namespace is specified, the *name* string is an ISO OID.


.. data:: NAMESPACE_X500

 When this namespace is specified, the *name* string is an X.500 DN in DER or a
 text output format.

The :mod:`uuid` module defines the following constants for the possible values of the :attr:`variant` attribute:

.. data:: RESERVED_NCS

 Reserved for NCS compatibility.


.. data:: RFC_4122

 Specifies the UUID layout given in :rfc:`4122`.


.. data:: RESERVED_MICROSOFT

 Reserved for Microsoft compatibility.


.. data:: RESERVED_FUTURE

 Reserved for future definition.


.. seealso::

 :rfc:`4122` - A Universally Unique IDentifier (UUID) URN Namespace
 This specification defines a Uniform Resource Name namespace for UUIDs, the
 internal format of UUIDs, and methods of generating UUIDs.


Example

Here are some examples of typical usage of the :mod:`uuid` module:

>>> import uuid

>>> # make a UUID based on the host ID and current time
>>> uuid.uuid1()
UUID('a8098c1a-f86e-11da-bd1a-00112444be1e')

>>> # make a UUID using an MD5 hash of a namespace UUID and a name
>>> uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
UUID('6fa459ea-ee8a-3ca4-894e-db77e160355e')

>>> # make a random UUID
>>> uuid.uuid4()
UUID('16fd2706-8baf-433b-82eb-8c7fada847da')

>>> # make a UUID using a SHA-1 hash of a namespace UUID and a name
>>> uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
UUID('886313e1-3b8a-5372-9b90-0c9aee199e5d')

>>> # make a UUID from a string of hex digits (braces and hyphens ignored)
>>> x = uuid.UUID('{00010203-0405-0607-0809-0a0b0c0d0e0f}')

>>> # convert a UUID to a string of hex digits in standard form
>>> str(x)
'00010203-0405-0607-0809-0a0b0c0d0e0f'

>>> # get the raw 16 bytes of the UUID
>>> x.bytes
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'

>>> # make a UUID from a 16-byte string
>>> uuid.UUID(bytes=x.bytes)
UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

暂无描述
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/python_sourcecode/python3.8.1.git
git@gitee.com:python_sourcecode/python3.8.1.git
python_sourcecode
python3.8.1
python3.8.1
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /