def get_swift_hash():
if os.path.isfile(SWIFT_HASH_FILE):
with open(SWIFT_HASH_FILE, 'r') as hashfile:
swift_hash = hashfile.read().strip()
elif config('swift-hash'):
swift_hash = config('swift-hash')
with open(SWIFT_HASH_FILE, 'w') as hashfile:
hashfile.write(swift_hash)
else:
model_uuid = os.environ.get("JUJU_ENV_UUID",
os.environ.get("JUJU_MODEL_UUID"))
swift_hash = str(uuid.uuid3(uuid.UUID(model_uuid),
service_name()))
with open(SWIFT_HASH_FILE, 'w') as hashfile:
hashfile.write(swift_hash)
return swift_hash
python类uuid3()的实例源码
def cluster_config(self):
"""
Provide the default configuration for a cluster
"""
if self.cluster:
cluster_dir = "{}/config/stack/default/{}".format(self.root_dir, self.cluster)
if not os.path.isdir(cluster_dir):
_create_dirs(cluster_dir, self.root_dir)
filename = "{}/cluster.yml".format(cluster_dir)
contents = {}
contents['fsid'] = str(uuid.uuid3(uuid.NAMESPACE_DNS, os.urandom(32)))
public_networks_str = ", ".join([str(n) for n in self.public_networks])
cluster_networks_str = ", ".join([str(n) for n in self.cluster_networks])
contents['public_network'] = public_networks_str
contents['cluster_network'] = cluster_networks_str
contents['available_roles'] = self.available_roles
self.writer.write(filename, contents)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def test_uuid3(self):
equal = self.assertEqual
# Test some known version-3 UUIDs.
for u, v in [(uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org'),
'6fa459ea-ee8a-3ca4-894e-db77e160355e'),
(uuid.uuid3(uuid.NAMESPACE_URL, 'http://python.org/'),
'9fe8e8c4-aaa8-32a9-a55c-4535a88b748d'),
(uuid.uuid3(uuid.NAMESPACE_OID, '1.3.6.1'),
'dd1a1cef-13d5-368a-ad82-eca71acd4cd1'),
(uuid.uuid3(uuid.NAMESPACE_X500, 'c=ca'),
'658d3002-db6b-3040-a1d1-8ddd7d189a4d'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 3)
equal(u, uuid.UUID(v))
equal(str(u), v)
def __set_identity(self):
node = None
if sys.platform == 'win32':
for getter in [uuid._netbios_getnode, uuid._ipconfig_getnode]:
node = getter()
if node:
break
else:
# Linux only, find mac address using ifconfig command. taken from uuid._ifconfig_getnode
for args in ('eth0', 'wlan0', 'en0'): # TODO: other possible network interface name
node = uuid._find_mac('ifconfig', args, ['hwaddr', 'ether'], lambda i: i + 1)
if node:
break
if node is None:
raise RuntimeError("No network interface found.")
self.__mac_address = ':'.join([str('%012x' % node)[x:x + 2] for x in range(0, 12, 2)])
url = 'xiboside://%s/%s/%s' % (sys.platform, os.name, self.__mac_address)
self.__keys['hardware'] = uuid.uuid3(uuid.NAMESPACE_URL, url)
def upload_avatar():
u = g.user
if 'photo' in request.files:
form = request.form
filename = str(uuid3(NAMESPACE_DNS, str(u.id) + u.username + str(time.time()))).replace('-','')
try:
x = int(form['x'])
y = int(form['y'])
w = int(form['nw'])
h = int(form['nh'])
img = Image.open(request.files['photo'])
format = img.format
croped_img = crop_img(img, x, y, w, h)
filename = save_avatar(croped_img, filename, format)
url_path = current_app.config['UPLOADED_PHOTOS_URL']
old_name = u.avatar.split(url_path)[1]
remove_avatar(old_name)
u.avatar = url_path + filename
u.save()
except Exception as e:
print(e)
flash('????????2Mb?????', 'error')
return redirect(url_for('user.setting_view'))
def generateUuid(self, email_id, machine_name):
""" return a uuid which uniquely identifies machinename and email id """
uuidstr = None
if machine_name not in self.d:
myNamespace = uuid.uuid3(uuid.NAMESPACE_URL, machine_name)
uuidstr = str(uuid.uuid3(myNamespace, email_id))
self.d[machine_name] = (machine_name, uuidstr, email_id)
self.d[uuidstr] = (machine_name, uuidstr ,email_id)
else:
(machine_name, uuidstr, email_id) = self.d[machine_name]
return uuidstr
def _fabric_server_uuid(host, port):
"""Create a UUID using host and port"""
return uuid.uuid3(uuid.NAMESPACE_URL, _fabric_xmlrpc_uri(host, port))
def randomUUIDField(self):
"""
Return the unique uuid from uuid1, uuid3, uuid4, or uuid5.
"""
uuid1 = uuid.uuid1().hex
uuid3 = uuid.uuid3(
uuid.NAMESPACE_URL,
self.randomize(['python', 'django', 'awesome'])
).hex
uuid4 = uuid.uuid4().hex
uuid5 = uuid.uuid5(
uuid.NAMESPACE_DNS,
self.randomize(['python', 'django', 'awesome'])
).hex
return self.randomize([uuid1, uuid3, uuid4, uuid5])
def generate_uuid(uuid_str):
return str(uuid.uuid3(uuid.NAMESPACE_OID, (uuid_str.encode('utf8'))))
def generate_uuid(self, metadata):
""" Generate a unique identifier given a dictionary of matrix metadata.
:param metadata: metadata for the matrix
:type metadata: dict
:return: unique name for the file
:rtype: str
"""
identifier = ''
for key in sorted(metadata.keys()):
identifier = '{0}_{1}'.format(identifier, str(metadata[key]))
name_uuid = str(uuid.uuid3(uuid.NAMESPACE_DNS, identifier))
return name_uuid
def _fabric_server_uuid(host, port):
"""Create a UUID using host and port"""
return uuid.uuid3(uuid.NAMESPACE_URL, _fabric_xmlrpc_uri(host, port))
def test_parse_uuid_invalid(self):
# Invalid uuid4 taken from https://gist.github.com/ShawnMilo/7777304
uuid_str = '89eb3586-8a82-47a4-c911-758a62601cf7'
self.assertFalse(_ZipArchive._is_uuid4(uuid_str))
# Not a UUID.
uuid_str = 'abc123'
self.assertFalse(_ZipArchive._is_uuid4(uuid_str))
# Other UUID versions.
for uuid_ in (uuid.uuid1(), uuid.uuid3(uuid.NAMESPACE_DNS, 'foo'),
uuid.uuid5(uuid.NAMESPACE_DNS, 'bar')):
uuid_str = str(uuid_)
self.assertFalse(_ZipArchive._is_uuid4(uuid_str))
def generate_uuid_by_element_id(element_id):
return str(uuid.uuid3(uuid.NAMESPACE_DNS, element_id))
def generate_uuid(self, depend_mac=True):
if depend_mac is False:
self.logger.debug('uuid creating randomly')
return uuid.uuid4() # make a random UUID
else:
self.logger.debug('uuid creating according to mac address')
return uuid.uuid3(uuid.NAMESPACE_DNS,
str(get_mac())) # make a UUID using an MD5 hash of a namespace UUID and a mac address
def hashed_id():
try:
salt = getstatusoutput("git config --get user.name")[1]
except:
import uuid
salt = uuid.uuid3(uuid.NAMESPACE_DNS, "")
return sha(salt).hexdigest()
def save(self):
buffers = self._buffers
self._buffers = []
try:
filename = str(uuid.uuid3(uuid.NAMESPACE_DNS, "%s_%s" % (time.time(), randint(0, 100000))))
filename = os.path.join(self._cache, filename)
fp = open(filename, 'w')
for event in buffers:
fp.write(str(event))
return filename
except Exception, e:
return 'Save Failed, cause: %s' % e
def __init__(self, level):
self.level = level
self.trace_id = str(uuid.uuid3(uuid.NAMESPACE_DNS, "%s_%s" % (time.time(), randint(0, 100000))))
def _translate_target(self, c, a, v):
# Set some things up
target = self.targets[a]
def relative_path(p):
p = str(p)
if p[0:1] != '/':
return os.path.relpath(p, c['_output_wrt'])
else:
return p
# recurse for list like things
if isinstance(v, list) or isinstance(v, SCons.Node.NodeList):
return [self._translate_target(c, a, v_) for v_ in v]
elif isinstance(v, dict):
v = copy.deepcopy(v)
elif isinstance(v, SCons.Node.FS.Entry) or isinstance(v, SCons.Node.FS.File):
# Can add more metadata here as needed
ident = uuid.uuid3(c[self.nest_levels[self.current_nest]['ident_attr']], str(v))
self.file_idents[str(v)] = ident
v = {'db:ident': ident,
'tripl.file:path': relative_path(v),
# This will be super cool...
'tripl.file:sources': [{'tripl.file:path': relative_path(p)} for p in v.sources]}
# This is where the metadata function gets called if it is callable
metadata = target['metadata'](c, v) if callable(target['metadata']) else (target['metadata'] or {})
if isinstance(v, dict):
# Here we merge in the metadata
v.update(metadata)
elif metadata:
metadata['tripl.nestly.target:value'] = v
v = metadata
# TODO namespace all keywords
return v
def from_offline_player(cls, display_name):
class FakeNamespace():
bytes = b'OfflinePlayer:'
base_uuid = uuid.uuid3(FakeNamespace(), display_name)
return UUID(bytes=base_uuid.bytes)
def gennerate_uuid(rootname, lineno):
name = rootname + str(lineno)
return uuid.uuid3(uuid.NAMESPACE_DNS, name).hex
def __init__(self, email, password):
self.email = email
self.password = password
self.session = requests.Session()
self.sessionToken = None
self.id = str(uuid.uuid3(uuid.NAMESPACE_DNS, 'rienafairefr.pynYNAB'))
self.lastrequest_elapsed=None
self.logger = logging.getLogger('pynYnab')
self._init_session()
def get_uuid( cur_dict ):
od = collections.OrderedDict(sorted(cur_dict.items()))
json_data_obj = json.dumps(od)
digest = uuid.uuid3(uuid.NAMESPACE_DNS, json_data_obj)
return str(digest)
def get_uuid( cur_dict ):
od = collections.OrderedDict(sorted(cur_dict.items()))
json_data_obj = json.dumps(od)
digest = uuid.uuid3(uuid.NAMESPACE_DNS, json_data_obj)
return str(digest)