]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
chore(c): remove C UUIDDumper and UUIDBinaryDumper
authorhenadzit <henadzi.tsaryk@gmail.com>
Mon, 10 Feb 2025 22:37:50 +0000 (23:37 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 20 Feb 2025 10:15:41 +0000 (11:15 +0100)
psycopg_c/psycopg_c/types/uuid.pyx
tests/types/test_uuid.py

index 81f03e5efd756b913d010f3455e2b3a1854c0bf5..164be69c3973886c2444e9a27debb22c0e2387cc 100644 (file)
@@ -1,38 +1,6 @@
 cimport cython
-
-from types import ModuleType
-from cpython.bytes cimport PyBytes_AsString
 from cpython.long cimport PyLong_FromUnsignedLongLong
 
-cdef extern from "Python.h":
-    # PyUnicode_AsUTF8 was added to cpython.unicode in 3.1.x but we still
-    # support 3.0.x
-    const char *PyUnicode_AsUTF8(object unicode) except NULL
-
-
-@cython.final
-cdef class UUIDDumper(CDumper):
-    format = PQ_TEXT
-    oid = oids.UUID_OID
-
-    cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1:
-        cdef const char *src = PyUnicode_AsUTF8(obj.hex)
-        cdef char *buf = CDumper.ensure_size(rv, offset, 32)
-        memcpy(buf, src, 32)
-        return 32
-
-
-@cython.final
-cdef class UUIDBinaryDumper(CDumper):
-    format = PQ_BINARY
-    oid = oids.UUID_OID
-
-    cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1:
-        cdef const char *src = PyBytes_AsString(obj.bytes)
-        cdef char *buf = CDumper.ensure_size(rv, offset, 16)
-        memcpy(buf, src, 16)
-        return 16
-
 
 cdef extern from *:
     """
index 94dbabde23fcc723a1befaf73dd38a5f68a0b7fb..c8dd6c0a84c113485fef91937faed666662cdab2 100644 (file)
@@ -9,8 +9,17 @@ from psycopg.adapt import PyFormat
 
 
 @pytest.mark.parametrize("fmt_in", PyFormat)
-def test_uuid_dump(conn, fmt_in):
-    val = "12345678123456781234567812345679"
+@pytest.mark.parametrize(
+    "val",
+    [
+        "12345678123456781234567812345679",
+        "12345678-1234-5678-1234-567812345679",
+        "0123456789abcdef0123456789abcdef",
+        "01234567-89ab-cdef-0123-456789abcdef",
+        "{a0eebc99-9c0b4ef8-bb6d6bb9-bd380a11}",
+    ],
+)
+def test_uuid_dump(conn, fmt_in, val):
     cur = conn.cursor()
     cur.execute(f"select %{fmt_in.value} = %s::uuid", (UUID(val), val))
     assert cur.fetchone()[0] is True