本文整理匯總了Python中uuid.uuid5方法的典型用法代碼示例。如果您正苦於以下問題:Python uuid.uuid5方法的具體用法?Python uuid.uuid5怎麽用?Python uuid.uuid5使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類uuid
的用法示例。
在下文中一共展示了uuid.uuid5方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ResourceUUID
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def ResourceUUID(value, creator):
if isinstance(value, uuid.UUID):
return value
if '/' in value:
raise ValueError("'/' is not supported in resource id")
try:
return uuid.UUID(value)
except ValueError:
if len(value) <= 255:
if creator is None:
creator = "\x00"
# value/creator must be str (unicode) in Python 3 and str (bytes)
# in Python 2. It's not logical, I know.
if six.PY2:
value = value.encode('utf-8')
creator = creator.encode('utf-8')
return uuid.uuid5(RESOURCE_ID_NAMESPACE,
value + "\x00" + creator)
raise ValueError(
'transformable resource id >255 max allowed characters')
示例2: execute_write_fn
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def execute_write_fn(self, fn, block=False):
task_id = uuid.uuid5(uuid.NAMESPACE_DNS, "datasette.io")
if self._write_queue is None:
self._write_queue = queue.Queue()
if self._write_thread is None:
self._write_thread = threading.Thread(
target=self._execute_writes, daemon=True
)
self._write_thread.start()
reply_queue = janus.Queue()
self._write_queue.put(WriteTask(fn, task_id, reply_queue))
if block:
result = await reply_queue.async_q.get()
if isinstance(result, Exception):
raise result
else:
return result
else:
return task_id
示例3: make_timebucket_id
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def make_timebucket_id(
log_id: UUID, timestamp: Union[Decimal, float], bucket_size: str
) -> UUID:
d = datetime_from_timestamp(timestamp)
assert isinstance(d, datetime.datetime)
if bucket_size.startswith("year"):
boundary = "{:04}".format(d.year)
elif bucket_size.startswith("month"):
boundary = "{:04}-{:02}".format(d.year, d.month)
elif bucket_size.startswith("day"):
boundary = "{:04}-{:02}-{:02}".format(d.year, d.month, d.day)
elif bucket_size.startswith("hour"):
boundary = "{:04}-{:02}-{:02}_{:02}".format(d.year, d.month, d.day, d.hour)
elif bucket_size.startswith("minute"):
boundary = "{:04}-{:02}-{:02}_{:02}-{:02}".format(
d.year, d.month, d.day, d.hour, d.minute
)
elif bucket_size.startswith("second"):
boundary = "{:04}-{:02}-{:02}_{:02}-{:02}-{:02}".format(
d.year, d.month, d.day, d.hour, d.minute, d.second
)
else:
raise ValueError("Bucket size not supported: {}".format(bucket_size))
return uuid5(Namespace_Timebuckets, log_id.hex + "_" + boundary)
示例4: test_uuid5
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def test_uuid5(self):
equal = self.assertEqual
# Test some known version-5 UUIDs.
for u, v in [(uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org'),
'886313e1-3b8a-5372-9b90-0c9aee199e5d'),
(uuid.uuid5(uuid.NAMESPACE_URL, 'http://python.org/'),
'4c565f0d-3f5a-5890-b41b-20cf47701c5e'),
(uuid.uuid5(uuid.NAMESPACE_OID, '1.3.6.1'),
'1447fa61-5277-5fef-a9b3-fbc6e44f4af3'),
(uuid.uuid5(uuid.NAMESPACE_X500, 'c=ca'),
'cc957dd1-a972-5349-98cd-874190002798'),
]:
equal(u.variant, uuid.RFC_4122)
equal(u.version, 5)
equal(u, uuid.UUID(v))
equal(str(u), v)
示例5: dimm_device_define_by_params
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def dimm_device_define_by_params(self, params, name):
"""
Create pc-dimm device from params.
"""
params = params.object_params("dimm")
dimm_type = "nvdimm" if params.get("nv_backend") else "pc-dimm"
attrs = qdevices.Dimm.__attributes__[:]
dev = qdevices.Dimm(params=params.copy_from_keys(attrs),
dimm_type=dimm_type)
dev.set_param("id", "%s-%s" % ("dimm", name))
if dimm_type == "nvdimm" and params.get("nvdimm_uuid"):
try:
dev.set_param("uuid", uuid.UUID(params["nvdimm_uuid"]))
except ValueError:
nvdimm_uuid = params["nvdimm_uuid"]
if nvdimm_uuid == "<auto>":
nvdimm_uuid = uuid.uuid5(uuid.NAMESPACE_OID, name)
dev.set_param("uuid", nvdimm_uuid)
for ext_k, ext_v in params.get_dict("dimm_extra_params").items():
dev.set_param(ext_k, ext_v)
return dev
示例6: _get_uuid_ppc64le
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def _get_uuid_ppc64le(hw_lst):
vendor = None
serial = None
for (_, _, sys_subtype, value) in hw_lst:
if sys_subtype == 'vendor':
vendor = value
if sys_subtype == 'serial':
serial = value
system_uuid = None
system_uuid_fname = '/sys/firmware/devicetree/base/system-uuid'
if os.access(system_uuid_fname, os.R_OK):
with open(system_uuid_fname) as uuidfile:
system_uuid = uuidfile.read().rstrip(' \t\r\n\0')
elif vendor and serial:
root = uuid.UUID(bytes=b'\x00' * 16)
vendor_uuid = uuid.uuid5(root, vendor)
system_uuid = str(uuid.uuid5(vendor_uuid, serial))
return system_uuid
示例7: set_relative_to_parent
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def set_relative_to_parent(blender_object, json_data):
if blender_object.parent:
parent = blender_object.parent
parent_uuid = uuid.uuid5(uuid.NAMESPACE_DNS, parent.name)
parent_orientation = quat_swap_nzy(relative_rotation(blender_object))
parent_position = swap_nzy(relative_position(blender_object))
json_data["position"] = {
'x': parent_position.x,
'y': parent_position.y,
'z': parent_position.z
}
json_data["rotation"] = {
'x': parent_orientation.x,
'y': parent_orientation.y,
'z': parent_orientation.z,
'w': parent_orientation.w
}
json_data["parentID"] = str(parent_uuid)
return json_data
示例8: _fix
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def _fix(self):
if self.uuid_template:
return uuid.UUID(("%08x%04x%04x" + ("%02x" * 8))
% self.uuid_template)
elif self.version == 1:
return uuid.uuid1(self.node, self.clock_seq)
elif self.version == 3:
return uuid.uuid3(self.namespace, self.name)
elif self.version == 4:
return uuid.uuid4()
elif self.version == 5:
return uuid.uuid5(self.namespace, self.name)
else:
raise ValueError("Unhandled version")
# Automatic timestamp
示例9: lookup
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def lookup(self, dependency: Dependency) -> Dependency:
# Grab the package data from PyPi
with urllib.request.urlopen(
f"https://pypi.org/pypi/{dependency.name}/json"
) as resp:
package_json = json.load(resp)
return Dependency.mkoverride(
dependency,
url=package_json["info"]["project_urls"]["Homepage"],
license=package_json["info"]["license"],
extra={
self.name: PyPiDependency(
uuid=None,
euuid=uuid.uuid5(self.uuid, dependency.name),
name=dependency.name,
url=f"https://pypi.org/pypi/{dependency.name}",
license=package_json["info"]["license"],
)
},
)
示例10: create_participant
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def create_participant(self, project_id, participant_name = "DefaultUser", participant_notes = ""):
participant_id = self.get_participant_id(participant_name)
self.participant_name = participant_name
if participant_id is None:
data = {'pa_project': project_id,
'pa_info': { 'EagleId': str(uuid.uuid5(uuid.NAMESPACE_DNS, self.participant_name)),
'Name': self.participant_name,
'Notes': participant_notes},
'pa_created': self.__get_current_datetime__()}
json_data = self.__post_request__('/api/participants', data)
logging.debug("Participant " + json_data['pa_id'] + " created! Project " + project_id)
return json_data['pa_id']
else:
logging.debug("Participant %s already exists ..." % participant_id)
return participant_id
示例11: _build_lambdas
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def _build_lambdas(self, parent_path: Path, output_path):
if not parent_path.is_dir():
return
for path in parent_path.iterdir():
if (path / "Dockerfile").is_file():
tag = f"taskcat-build-{uuid5(self.NULL_UUID, str(path)).hex}"
LOG.info(
f"Packaging lambda source from {path} using docker image {tag}"
)
self._docker_build(path, tag)
self._docker_extract(tag, output_path / path.stem)
elif (path / "requirements.txt").is_file():
LOG.info(f"Packaging python lambda source from {path} using pip")
self._pip_build(path, output_path / path.stem)
else:
LOG.info(
f"Packaging lambda source from {path} without building "
f"dependencies"
)
self._zip_dir(path, output_path / path.stem)
示例12: get_artifacts_by_keys
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def get_artifacts_by_keys(
run: BaseRun, namespace: uuid.UUID, artifacts: List[V1RunArtifact]
) -> Dict:
results = {}
for m in artifacts:
state = m.state
if not state:
if m.is_input:
state = m.get_state(namespace)
else:
state = run.uuid
elif not isinstance(state, uuid.UUID):
try:
state = uuid.UUID(state)
except (ValueError, KeyError):
state = uuid.uuid5(namespace, state)
results[(m.name, state)] = m
return results
示例13: make_metric
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def make_metric(name, metadata, created_on, updated_on, read_on):
"""Create a Metric object.
Args:
name: metric name.
metadata: metric metadata.
created_on: metric creation date.
updated_on: metric last update date.
read_on: metric last read date.
Returns: a Metric object with a valid id.
"""
encoded_name = encode_metric_name(sanitize_metric_name(name))
uid = uuid.uuid5(_UUID_NAMESPACE, encoded_name)
return Metric(
encoded_name,
uid,
metadata,
created_on=created_on,
updated_on=updated_on,
read_on=read_on,
)
示例14: GenerateUUID
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def GenerateUUID(payload_id):
"""Generates a UUID for a given PayloadIdentifier.
This function will always generate the same UUID for a given identifier.
Args:
payload_id: str, a payload identifier string (reverse-dns style).
Returns:
uuid: str, a valid UUID based on the payload ID.
"""
return str(uuid.uuid5(uuid.NAMESPACE_DNS, payload_id)).upper()
示例15: generate_service_config_filename
# 需要導入模塊: import uuid [as 別名]
# 或者: from uuid import uuid5 [as 別名]
def generate_service_config_filename(version):
return str(uuid.uuid5(uuid.NAMESPACE_DNS, str(version)))
# parse xff_trusted_proxy_list