Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Creating UUIDs (GUIDs) portably

1 view
Skip to first unread message

Ondrej Krajicek

unread,
Feb 24, 2003, 2:47:27 AM2/24/03
to
Hello,

I'd bet I must be missing something obvious, but I
could not find out if (and how) one can create
UUIDs/GUIDs in Python.

I work on a project which relies heavilly on UUIDs
(as object and transaction identifiers...) which should
run in (both) Windows200x and Linux environments.
I know how to create GUID in Python on Win32
(using pythoncom.CreateGuid), but this is not portable.

Is there any Python module or (at least) Linux library,
which is able to create GUIDs (DCE RPC UUIDs
with proper flags set)?

Any hints or suggestions?

TIA,

Ondra
____________________________________________________________
Ondrej Krajicek kraj...@ics.muni.cz
The pain of life never grows dull. ::Eternal Despair

Mark McEahern

unread,
Feb 24, 2003, 8:38:14 AM2/24/03
to
[Ondrej Krajicek]

> Is there any Python module or (at least) Linux library,
> which is able to create GUIDs (DCE RPC UUIDs
> with proper flags set)?

You could write a Python Extension to wrap libuuid.so.

// m

-


Thomas Heller

unread,
Feb 24, 2003, 9:31:35 AM2/24/03
to
"Mark McEahern" <mark...@mceahern.com> writes:

Nice use-case for ctypes on linux:

thomas@susi:~ > python2.3
Python 2.3a1 (#2, Jan 25 2003, 01:52:52)
[GCC 2.95.2 19991024 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import CDLL, c_string
>>> uuid = c_string("\000" * 16)
>>> lib = CDLL("/lib/libuuid.so.1")
>>> lib.uuid_generate(uuid)
1263991427
>>> out = c_string("\000" * 36)
>>> lib.uuid_unparse(uuid, out)
36
>>> print out.value
fe59a066-5999-4cf9-a0cc-9f57564b83fa
>>>


Thomas

Klaus Alexander Seistrup

unread,
Feb 24, 2003, 10:28:25 AM2/24/03
to
Mark McEahern wrote:

> You could write a Python Extension to wrap libuuid.so.

Here a wrapper for libuuid's uuidgen() function that I wrote some
time back:

#v+

/* Distributable under GNU GPL v2+ /*

#include "Python.h"

#include <sys/types.h>
#include <uuid/uuid.h>

static char uuidgen__doc__ [] = "DCE compatible Universally Unique Identifier module";

static PyObject *
uuidgen_uuidgen (void)
{
uuid_t out;
char buf[48];

uuid_generate(out);
uuid_unparse(out, buf);

return PyString_FromString (buf);
}
static char uuidgen_uuidgen__doc__[] = "";

static PyMethodDef uuidgen_methods[] = {
{"uuidgen", uuidgen_uuidgen, 0, uuidgen_uuidgen__doc__},
{NULL, NULL, 0, NULL} /* sentinel */
};

DL_EXPORT(void)
inituuidgen()
{
Py_InitModule4("uuidgen", uuidgen_methods, uuidgen__doc__,
(PyObject *)NULL, PYTHON_API_VERSION);
}

#v-

Cheers,

// Klaus

--
><> vandag, môre, altyd saam

djw

unread,
Feb 24, 2003, 8:32:11 PM2/24/03
to
0 new messages