uuid.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # License: BSD
4 # https://raw.github.com/robotics-in-concert/rocon_multimaster/license/LICENSE
5 #
6 
7 ##############################################################################
8 # Imports
9 ##############################################################################
10 
11 import re
12 
13 ##############################################################################
14 # Methods
15 ##############################################################################
16 
17 valid_uuid_pattern = re.compile("^[0-9a-f]{32}$")
18 
19 
21  '''
22  A not very reliable way to check if the last 32 characters of a string
23  are a uuid postfix. Not reliable because if the prefix characters are
24  [0-9a-f] then it will accept shorter combinations of strings. Practical
25  because who will give a gateway a uuid style name?
26  '''
27  if len(name) <= 32:
28  return False
29  uuid_potential_part = name[-32:]
30  match = valid_uuid_pattern.match(uuid_potential_part)
31  return False if match is None else True
32 
33 
34 def gateway_basename(gateway_name):
35  '''
36  Strips the 16 byte hash (in hex format) from a gateway name, leaving the base name.
37  Note, 16 hex values represents 32 characters
38 
39  @param gateway_name : base_name + 16 byte hex formatted hash
40  @type str
41  @return base name without the hash
42  @rtype str
43  '''
44  # Need to check if it actually has a uuid postfix since gateways can disable uuid's.
45  if is_uuid_postfixed(gateway_name):
46  return gateway_name[:-32]
47  else:
48  return gateway_name
49 
50 if __name__ == '__main__':
51  print gateway_basename("dude")
52  print gateway_basename("dude8bd699042519416d88722e8b0611d43")
53  print gateway_basename("dude8bd699042519416d88722e8b0611d43b")
def gateway_basename(gateway_name)
Definition: uuid.py:34
def is_uuid_postfixed(name)
Definition: uuid.py:20


rocon_gateway_utils
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 14:40:06