Python generate uuid
38 Python code examples are found related to "
generate uuid".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: sdk_helpers.py From resilient-python-api with MIT License | 7 votes |
def generate_uuid_from_string(the_string): """ Returns String representation of the UUID of a hex md5 hash of the given string """ # Instansiate new md5_hash md5_hash = hashlib.md5() # Pass the_string to the md5_hash as bytes md5_hash.update(the_string.encode("utf-8")) # Generate the hex md5 hash of all the read bytes the_md5_hex_str = md5_hash.hexdigest() # Return a String repersenation of the uuid of the md5 hash return str(uuid.UUID(the_md5_hex_str))
Example 2
Source File: client.py From instagram_private_api with MIT License | 5 votes |
def generate_uuid(cls, return_hex=False, seed=None): """ Generate uuid :param return_hex: Return in hex format :param seed: Seed value to generate a consistent uuid :return: """ if seed: m = hashlib.md5() m.update(seed.encode('utf-8')) new_uuid = uuid.UUID(m.hexdigest()) else: new_uuid = uuid.uuid1() if return_hex: return new_uuid.hex return str(new_uuid)
Example 3
Source File: handlers.py From faces with GNU General Public License v2.0 | 5 votes |
def generate_idempotent_uuid(params, model, **kwargs): for name in model.idempotent_members: if name not in params: params[name] = str(uuid.uuid4()) logger.debug("injecting idempotency token (%s) into param '%s'." % (params[name], name))
Example 4
Source File: device.py From balena-sdk-python with Apache License 2.0 | 5 votes |
def generate_uuid(self): """ Generate a random device UUID. Returns: str: a generated UUID. Examples: >>> balena.models.device.generate_uuid() '19dcb86aa288c66ffbd261c7bcd46117c4c25ec655107d7302aef88b99d14c' """ # From balena-sdk # I'd be nice if the UUID matched the output of a SHA-256 function, # but although the length limit of the CN attribute in a X.509 # certificate is 64 chars, a 32 byte UUID (64 chars in hex) doesn't # pass the certificate validation in OpenVPN This either means that # the RFC counts a final NULL byte as part of the CN or that the # OpenVPN/OpenSSL implementation has a bug. return binascii.hexlify(os.urandom(31))
Example 5
Source File: Tracker.py From Tautulli with GNU General Public License v3.0 | 4 votes |
def generate_uuid(basedata=None): """ Provides a _random_ UUID with no input, or a UUID4-format MD5 checksum of any input data provided """ if basedata is None: return str(uuid.uuid4()) elif isinstance(basedata, str): checksum = hashlib.md5(str(basedata).encode('utf-8')).hexdigest() return '%8s-%4s-%4s-%4s-%12s' % ( checksum[0:8], checksum[8:12], checksum[12:16], checksum[16:20], checksum[20:32])
Example 6
Source File: api.py From todoist-python with MIT License | 4 votes |
def generate_uuid(self): """ Generates a uuid. """ return str(uuid.uuid1())
Example 7
Source File: uuid.py From incubator-ariatosca with Apache License 2.0 | 4 votes |
def generate_uuid(length=None, variant='base57'): """ A random string with varying degrees of guarantee of universal uniqueness. :param variant: * ``base57`` (the default) uses a mix of upper and lowercase alphanumerics ensuring no visually ambiguous characters; default length 22 * ``alphanumeric`` uses lowercase alphanumeric; default length 25 * ``uuid`` uses lowercase hexadecimal in the classic UUID format, including dashes; length is always 36 * ``hex`` uses lowercase hexadecimal characters but has no guarantee of uniqueness; default length of 5 """ if variant == 'base57': the_id = UUID_BASE57.uuid() if length is not None: the_id = the_id[:length] elif variant == 'alphanumeric': the_id = UUID_LOWERCASE_ALPHANUMERIC.uuid() if length is not None: the_id = the_id[:length] elif variant == 'uuid': the_id = str(uuid4()) elif variant == 'hex': length = length or 5 # See: http://stackoverflow.com/a/2782859 the_id = ('%0' + str(length) + 'x') % randrange(16 ** length) else: raise ValueError('unsupported UUID variant: {0}'.format(variant)) return the_id
Example 8
Source File: kodicast.py From script.tubecast with MIT License | 4 votes |
def generate_uuid(): friendly_name = 'device.tubecast.{}'.format(Kodicast.friendlyName) if not PY3: friendly_name = friendly_name.encode('utf8') Kodicast.uuid = str(uuid.uuid5( uuid.NAMESPACE_DNS, friendly_name))
Example 9
Source File: utils.py From instagram-statistics with GNU General Public License v3.0 | 4 votes |
def generate_uuid(force=False): generated_uuid = str(uuid.uuid4()) if force: return generated_uuid else: return generated_uuid.replace('-', '')
Example 10
Source File: local.py From cate with MIT License | 4 votes |
def generate_uuid(cls, ref_id: str, time_range: Optional[TimeRange] = None, region: Optional[shapely.geometry.Polygon] = None, var_names: Optional[VarNames] = None) -> str: if time_range: ref_id += TimeRangeLike.format(time_range) if region: ref_id += PolygonLike.format(region) if var_names: ref_id += VarNamesLike.format(var_names) return str(uuid.uuid3(_NAMESPACE, ref_id))
Example 11
Source File: newsletters.py From Tautulli with GNU General Public License v3.0 | 4 votes |
def generate_newsletter_uuid(): uuid = '' uuid_exists = 0 db = database.MonitorDatabase() while not uuid or uuid_exists: uuid = plexpy.generate_uuid()[:8] result = db.select_single( 'SELECT EXISTS(SELECT uuid FROM newsletter_log WHERE uuid = ?) as uuid_exists', [uuid]) uuid_exists = result['uuid_exists'] return uuid
Example 12
Source File: utils.py From ndscheduler with BSD 2-Clause "Simplified" License | 4 votes |
def generate_uuid(): """Generates 32-digit hex uuid. Example: d8f376e858a411e4b6ae22001ac68d05 :return: uuid hex string :rtype: str """ return uuid.uuid4().hex
Example 13
Source File: insta.py From instagram-unfollowers with GNU General Public License v3.0 | 4 votes |
def generateUUID(self, type): uuid = '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' % (random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0x0fff) | 0x4000, random.randint(0, 0x3fff) | 0x8000, random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0xffff)) if (type): return uuid else: return uuid.replace('-', '')
Example 14
Source File: uuidutils.py From oslo.utils with Apache License 2.0 | 4 votes |
def generate_uuid(dashed=True): """Creates a random uuid string. :param dashed: Generate uuid with dashes or not :type dashed: bool :returns: string """ if dashed: return str(uuid.uuid4()) return uuid.uuid4().hex
Example 15
Source File: inspircd.py From dtella with GNU General Public License v2.0 | 4 votes |
def generateUUID(self): ctr = self.uuid_counter self.uuid_counter += 1 uuid = "" for i in range(6): uuid = UUID_DIGITS[ctr % len(UUID_DIGITS)] + uuid ctr /= len(UUID_DIGITS) # There are over 2 billion UUIDs; just reconnect if we run out. if ctr > 0: self.transport.loseConnection() raise ValueError("Ran out of UUIDs") return self.sid + uuid
Example 16
Source File: Tracker.py From plugin.video.netflix with MIT License | 4 votes |
def generate_uuid(basedata = None): """ Provides a _random_ UUID with no input, or a UUID4-format MD5 checksum of any input data provided """ if basedata is None: return str(uuid.uuid4()) elif isinstance(basedata, compat_basestring): checksum = hashlib.md5(basedata).hexdigest() return '%8s-%4s-%4s-%4s-%12s' % (checksum[0:8], checksum[8:12], checksum[12:16], checksum[16:20], checksum[20:32])
Example 17
Source File: InstagramAPI.py From instegogram with MIT License | 4 votes |
def generateUUID(self, type): uuid = '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' % (random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0x0fff) | 0x4000, random.randint(0, 0x3fff) | 0x8000, random.randint(0, 0xffff), random.randint(0, 0xffff), random.randint(0, 0xffff)) if (type): return uuid else: return uuid.replace('-', '')
Example 18
Source File: auth_service.py From nanoservice with MIT License | 4 votes |
def generate_uuid(): """ Generate a random uuid """ return uuid.uuid4().hex # ***************************************************** # MAIN # *****************************************************
Example 19
Source File: pub_sub_api.py From dragonflow with Apache License 2.0 | 4 votes |
def generate_publisher_uuid(): """ Generate a non-random uuid based on the fully qualified domain name. This UUID is supposed to remain the same across service restarts. """ fqdn = socket.getfqdn() process_name = df_utils.get_process_name() return str(uuid.uuid5(uuid.NAMESPACE_DNS, "{0}.{1}".format(process_name, fqdn)))
Example 20
Source File: generation.py From open-context-py with GNU General Public License v3.0 | 4 votes |
def generate_save_context_path_from_uuid(self, uuid, do_children=True): """ Generates and saves a context path for a subject item by uuid """ cache = caches['redis'] cache.clear() output = False try: man_obj = Manifest.objects.get(uuid=uuid, item_type='subjects') except Manifest.DoesNotExist: man_obj = False if man_obj is not False: if man_obj.item_type == 'subjects': output = self.generate_save_context_path_from_manifest_obj(man_obj) if do_children: act_contain = Containment() act_contain.redis_ok = False # get the contents recusivelhy contents = act_contain.get_children_by_parent_uuid(uuid, True) if isinstance(contents, dict): for tree_node, children in contents.items(): for child_uuid in children: # do the children, but not recursively since we # already have a resurive look up of contents output = self.generate_save_context_path_from_uuid(child_uuid, False) return output
Example 21
Source File: profiles.py From macops with Apache License 2.0 | 4 votes |
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()
Example 22
Source File: crawlers.py From AIL-framework with GNU Affero General Public License v3.0 | 4 votes |
def generate_uuid(): return str(uuid.uuid4()).replace('-', '') ################################################################################ # # TODO: handle prefix cookies # # TODO: fill empty fields
Example 23
Source File: registration.py From ahenk with GNU Lesser General Public License v3.0 | 4 votes |
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
Example 24
Source File: recipe-501148.py From code with MIT License | 4 votes |
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
Example 25
Source File: other.py From chepy with GNU General Public License v3.0 | 4 votes |
def generate_uuid(self) -> str: """Generate v4 UUID Generates an RFC 4122 version 4 compliant Universally Unique Identifier (UUID), also known as a Globally Unique Identifier (GUID). A version 4 UUID relies on random numbers Returns: str: A random UUID Examples: >>> Chepy('').generate_uuid() 92644a99-632a-47c1-b169-5a141172924b """ self.state = str(uuid4()) return self # def decode_qr(self): # pragma: no cover # """Decode a qr code # This method does require zbar to be installed in the system # Returns: # Chepy: The Chepy object. # """ # data = Image.open(self._load_as_file()) # self.state = list(map(lambda x: x.data, _pyzbar_decode(data))) # return self
Example 26
Source File: common.py From openrasp-iast with Apache License 2.0 | 4 votes |
def generate_uuid(): """ 随机生成uuid Returns: str, 型如: ce361bf9-48c9-483b-8122-fc9b867869cc """ return str(uuid.uuid4())
Example 27
Source File: InstagramAPI.py From Osintgram with GNU General Public License v3.0 | 4 votes |
def generateUUID(self, type): generated_uuid = str(uuid.uuid4()) if (type): return generated_uuid else: return generated_uuid.replace('-', '')
Example 28
Source File: util.py From gobbli with Apache License 2.0 | 4 votes |
def generate_uuid() -> str: """ Generate a universally unique ID to be used for randomly naming directories, models, tasks, etc. """ return uuid.uuid4().hex
Example 29
Source File: flm_helpers.py From son-mano-framework with Apache License 2.0 | 4 votes |
def generate_image_uuid(vdu, vnfd): """ This method creates the image_uuid based on the vdu info in the vnfd """ new_string = vnfd['vendor'] + '_' + vnfd['name'] + '_' + vnfd['version'] new_string = new_string + '_' + vdu['id'] return new_string
Example 30
Source File: experiments.py From assaytools with GNU Lesser General Public License v2.1 | 4 votes |
def generate_uuid(size=6, chars=(string.ascii_uppercase + string.digits)): """ Generate convenient universally unique id (UUID) Parameters ---------- size : int, optional, default=6 Number of alphanumeric characters to generate. chars : list of chars, optional, default is all uppercase characters and digits Characters to use for generating UUIDs NOTE ---- This is not really universally unique, but it is convenient. """ return ''.join(random.choice(chars) for _ in range(size))
Example 31
Source File: SignatureUtils.py From Instagram-API with MIT License | 4 votes |
def generateUUID(type): uuid = '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' % ( mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ) return uuid if type else uuid.replace('-', '')
Example 32
Source File: skos.py From arches with GNU Affero General Public License v3.0 | 4 votes |
def generate_uuid_from_subject(self, baseuuid, subject): uuidregx = re.compile(r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}") matches = uuidregx.search(str(subject)) if matches: return matches.group(0) else: return str(uuid.uuid3(baseuuid, str(subject)))
Example 33
Source File: fwaudit.py From fwaudit with GNU General Public License v2.0 | 3 votes |
def generate_uuid(hex_style=True, urn_style=False, uuid1=False, uuid4=False, verbose=False): '''Generate a UUID and returns a string version of it. The generated UUID can be of two types, uuid1 or uuid4. The generated UUID can be of two kinds of strings, hex or URN. The user must specify the type and string kind. hex -- If True generate UUID as a 32-character hexadecimal string. urn -- If True, generate UUID as a RFC 4122-style URN-based hexadecimal string. uuid1 -- If True, generate UUID1-style, based on MAC address and current time. Use uuid1 for machine-centric data. uuid4 -- If True, generate UUID4-style, based on random data. Use uuid4 for machine-independent data. Returns specified UUID string, or None if there was an error. ''' if uuid1: if verbose: info('Generating type1 UUID, based on host ID and current time') u = uuid.uuid1() elif uuid4: if verbose: info('Generating type4 UUID, based on random data') u = uuid.uuid4() else: error('Must set either uuid1 or uuid4 to True') return None if u is None: error('Failed to generate UUID') return None if hex_style: if verbose: info('Generating hex string representation of UUID') return str(u.hex) elif urn_style: if verbose: info('Generating URN string representation of UUID') return str(u.urn) else: error('Must set either hex or urn to True') return None