1
2
3
4
5
6
7
8
9
10
11 __doc__="""guid
12
13 Generate a globally unique id that is used for events.
14 This is a wrapper around the library that is used in Python 2.5
15 and higher.
16 See http://zestyping.livejournal.com/157957.html for more info and
17 the code is available from http://zesty.ca/python/
18 """
19 import urllib
20 from uuid import uuid1, uuid3, uuid4, uuid5
21 from BTrees.OOBTree import OOBTree
22 from zope.event import notify
23 from zope.interface import implements
24 from zope.component import adapts
25 from .interfaces import IGloballyIdentifiable, IGlobalIdentifier, IGUIDManager
26
27 from Products.ZenUtils.guid.event import GUIDEvent
28 from Products.ZCatalog.interfaces import ICatalogBrain
29
30
31 known_uuid_types= {
32 1:uuid1,
33 3:uuid3,
34 4:uuid4,
35 5:uuid5,
36 }
37
38 -def generate( uuid_type=4, *args, **kwargs ):
39 """
40 Generate an Universally Unique ID (UUID), according to RFC 4122.
41 If an unknown uuid_type is provided, uses the UUID4 algorithm.
42
43 >>> guids = [ generate() for x in range(100000) ]
44 >>> guid_set = set( guids )
45 >>> len(guids) == len(guid_set)
46 True
47 >>> len( str( generate() ) ) == 36
48 True
49
50 @param uuid_type: the type of UUID to generate
51 @type uuid_type: range from 0 - 5
52 @return: UUID
53 @type: string
54 """
55 uuid_func = known_uuid_types.get(uuid_type, uuid4)
56 return str(uuid_func(*args, **kwargs))
57
58
59 GUID_ATTR_NAME = '_guid'
60 GUID_TABLE_PATH = '/zport/dmd/guid_table'
61
62
87
88
122
132