cimport cython
-import uuid
+from types import ModuleType
from cpython.bytes cimport PyBytes_AsString
cdef extern from "Python.h":
const char *PyUnicode_AsUTF8(object unicode) except NULL
+uuid: ModuleType | None = None
+
+
@cython.final
cdef class UUIDDumper(CDumper):
format = PQ_TEXT
cdef class UUIDLoader(CLoader):
format = PQ_TEXT
+ def __cinit__(self, oid: int, context: AdaptContext | None = None):
+ global uuid
+ # uuid is slow to import, lazy load it
+ if uuid is None:
+ import uuid
+
cdef object cload(self, const char *data, size_t length):
cdef char[33] hex_str
cdef size_t i
cdef class UUIDBinaryLoader(CLoader):
format = PQ_BINARY
+ def __cinit__(self, oid: int, context: AdaptContext | None = None):
+ global uuid
+ # uuid is slow to import, lazy load it
+ if uuid is None:
+ import uuid
+
cdef object cload(self, const char *data, size_t length):
u = uuid.UUID.__new__(uuid.UUID)
object.__setattr__(u, 'is_safe', uuid.SafeUUID.unknown)