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