Skip to content

Instantly share code, notes, and snippets.

@tomekr
Created June 15, 2015 22:23
Show Gist options
  • Save tomekr/c33cbf29f12477ca63b0 to your computer and use it in GitHub Desktop.
Save tomekr/c33cbf29f12477ca63b0 to your computer and use it in GitHub Desktop.
system.py
# If ctypes is available, use it to find system routines for UUID generation.
_uuid_generate_random = _uuid_generate_time = _UuidCreate = None
try:
import ctypes, ctypes.util
# The uuid_generate_* routines are provided by libuuid on at least
# Linux and FreeBSD, and provided by libc on Mac OS X.
for libname in ['uuid', 'c']:
try:
lib = ctypes.CDLL(ctypes.util.find_library(libname))
except:
continue
if hasattr(lib, 'uuid_generate_random'):
_uuid_generate_random = lib.uuid_generate_random
if hasattr(lib, 'uuid_generate_time'):
_uuid_generate_time = lib.uuid_generate_time
if _uuid_generate_random is not None:
break # found everything we were looking for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment