⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uuid.py

📁 xen虚拟机源代码安装包
💻 PY
字号:
#============================================================================# This library is free software; you can redistribute it and/or# modify it under the terms of version 2.1 of the GNU Lesser General Public# License as published by the Free Software Foundation.## This library is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU# Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public# License along with this library; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#============================================================================# Copyright (C) 2005 Mike Wray <mike.wray@hp.com># Copyright (C) 2005 XenSource Ltd#============================================================================"""Universal Unique Identifiers (UUIDs).  By default, UUIDs generated here arepurely random, with no internal structure.  However, they are the same size,and are formatted by the same conventions, as the UUIDs in the Open SoftwareFoundation's Distributed Computing Environment (OSF DCE).  This allows Xend tobe used with UUIDs generated as per the DCE specification, should that berequired.  These UUIDs are also, by no coincidence, the same size as the'handle' stored by the Xen hypervisor along with the domain structure."""import commandsimport randomdef getUuidUuidgen(randomly = True):    """Generate a UUID using the command uuidgen.    If randomly is true (default) generates a random uuid.    If randomly is false generates a time-based uuid.    """    cmd = "uuidgen"    if randomly:        cmd += " -r"    else:        cmd += " -t"    return fromString(commands.getoutput(cmd))def getUuidRandom():    """Generate a random UUID."""        return [ random.randint(0, 255) for _ in range(0, 16) ]#uuidFactory = getUuidUuidgenuuidFactory = getUuidRandomdef toString(u):    return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,                     "%02x" * 6]) % tuple(u)def fromString(s):    s = s.replace('-', '')    return [ int(s[i : i + 2], 16) for i in range(0, 32, 2) ]def create():    return uuidFactory()def createString():    return toString(create())

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -