Creating UUIDs (GUIDs) portably

Klaus Alexander Seistrup spam at magnetic-ink.dk
Mon Feb 24 10:28:25 EST 2003


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




More information about the Python-list mailing list