## $Id: idgen.py 12288 2014-12-21 17:01:15Z henrik $ ## ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """ID generators. Give you unique IDs for objects. """ import grok import uuid from waeup.ikoba.interfaces import IIDSource class IDSource(grok.GlobalUtility): """This utility provides 'Universally Unique IDentifiers'. It is registered without name on startup. You can get an instance of this utility with >>> from zope.component import getUtility >>> from waeup.ikoba.interfaces import IIDSource >>> source = getUtility(IIDSource) """ grok.implements(IIDSource) @classmethod def get_uuid(self): """Get a UUID string of 36 hexadecimal chars and hyphens. """ return str(uuid.uuid4()) @classmethod def get_hex_uuid(self): """Get a UUID string of 32 hexadecimal chars. """ return uuid.uuid4().hex