9 version_str = (
'Unused',
'Gregorian time based',
'DCE',
'MD5 based',
'RNG based',
'SHA',
10 'Reordered Gregorian',
'Epoch time based',
'Custom') + (
'Reserved',)*7
14 DTD_DELTA = ( datetime.datetime( *time.gmtime(0)[0:3] ) -
15 datetime.datetime( 1582, 10, 15 ) )
16 DTD_SECS_DELTA = DTD_DELTA.days * 86400
17 secs = myuuid.time / 1e7
18 secs_epoch = secs - DTD_SECS_DELTA
19 return datetime.datetime.fromtimestamp( secs_epoch )
22 fields = guid.split(
'-')
23 if len(fields) != 5:
raise ValueError( f
"Wrong number of fields in '{guid}'" )
24 if len(fields[0]) != 8:
raise ValueError( f
"Wrong length of field#0: '{fields[0]}'" )
25 if len(fields[1]) != 4:
raise ValueError( f
"Wrong length of field#1: '{fields[1]}'" )
26 if len(fields[2]) != 4:
raise ValueError( f
"Wrong length of field#2: '{fields[2]}'" )
27 if len(fields[3]) != 4:
raise ValueError( f
"Wrong length of field#3: '{fields[3]}'" )
28 if len(fields[4]) != 12:
raise ValueError( f
"Wrong length of field#4: '{fields[4]}'" )
29 return (fields[0], fields[1], fields[2], fields[3], fields[4])
33 print(
'POOL guid:', mypool)
35 myuuid =
'%s%s%s%s-%s%s-%s%s-%s-%s'\
36 %(f0[6:8],f0[4:6],f0[2:4],f0[0:2],\
37 f1[2:4],f1[0:2],f2[2:4],f2[0:2],f3,f4)
38 print(
'UUID guid:', myuuid)
44 myuuidto =
'%s%s%s'%(f2[1:4],f1,f0)
45 myUUID=uuid.UUID(myuuid)
46 print(
'UUID:', myUUID)
47 print(
'UUID time (100ns intervals since 15 Oct 1582):', myUUID.time,
"hex:", hex(myUUID.time))
48 print(
'UUID timeordered:', myuuidto)
54 print(
'POOL guid:', mypool)
56 myuuidto =
'%s%s%s%s%s%s%s%s'\
57 %(f2[2:3],f2[0:2],f1[2:4],f1[0:2],\
58 f0[6:8],f0[4:6],f0[2:4],f0[0:2],)
59 print(
'UUID timeordered:', myuuidto)
64 myUUID=uuid.UUID(myuuid)
65 print(
'UUID:', myUUID)
66 print(
'UUID variant:', myUUID.variant)
67 print(
'UUID version:', myUUID.version,
'-',version_str[myUUID.version])
68 print(
'UUID field#0 (time_low): %12.8x (%12.8x)'\
69 %( myUUID.fields[0], myUUID.time_low ))
70 print(
'UUID field#1 (time_mid): %12.4x (%12.4x)'\
71 %( myUUID.fields[1], myUUID.time_mid ))
72 print(
'UUID field#2 (time_hi_version): %12.4x (%12.4x)'\
73 %( myUUID.fields[2], myUUID.time_hi_version ))
74 print(
'UUID field#3 (clock_seq_hi_variant): %12.2x (%12.2x)'\
75 %( myUUID.fields[3], myUUID.clock_seq_hi_variant ))
76 print(
'UUID field#4 (clock_seq_low): %12.2x (%12.2x)'\
77 %( myUUID.fields[4], myUUID.clock_seq_low ))
78 print(
'UUID field#5 (node): %12.12x (%12.12x)'\
79 %( myUUID.fields[5], myUUID.node ))
80 if myUUID.version == 1:
82 print(
'================================================')
85 print(sys.argv[0],
"-h | [-u] UUID")
86 print(
" -u : assume uuidgen standard format (not POOL)")
94 guid1=
'dd3a5aac-6522-11df-82eb-001e4f3e5c33'
95 guid2=
'A2E338DD-2265-DF11-AFE1-001E4F3E5C33'
96 guid3=
'A2E338DD-2265-D011-AFE1-001E4F3E5C33'
102 if __name__ ==
"__main__":
104 if len(sys.argv) > 1:
105 if sys.argv[1] ==
'-u':
108 if sys.argv[1] ==
'-h':
110 if len(sys.argv) < 2: