Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 import re
00012
00013
00014
00015
00016
00017 valid_uuid_pattern = re.compile("^[0-9a-f]{32}$")
00018
00019
00020 def is_uuid_postfixed(name):
00021 '''
00022 A not very reliable way to check if the last 32 characters of a string
00023 are a uuid postfix. Not reliable because if the prefix characters are
00024 [0-9a-f] then it will accept shorter combinations of strings. Practical
00025 because who will give a gateway a uuid style name?
00026 '''
00027 if len(name) <= 32:
00028 return False
00029 uuid_potential_part = name[-32:]
00030 match = valid_uuid_pattern.match(uuid_potential_part)
00031 return False if match is None else True
00032
00033
00034 def gateway_basename(gateway_name):
00035 '''
00036 Strips the 16 byte hash (in hex format) from a gateway name, leaving the base name.
00037 Note, 16 hex values represents 32 characters
00038
00039 @param gateway_name : base_name + 16 byte hex formatted hash
00040 @type str
00041 @return base name without the hash
00042 @rtype str
00043 '''
00044
00045 if is_uuid_postfixed(gateway_name):
00046 return gateway_name[:-32]
00047 else:
00048 return gateway_name
00049
00050 if __name__ == '__main__':
00051 print gateway_basename("dude")
00052 print gateway_basename("dude8bd699042519416d88722e8b0611d43")
00053 print gateway_basename("dude8bd699042519416d88722e8b0611d43b")