From: henadzit Date: Mon, 10 Feb 2025 22:37:50 +0000 (+0100) Subject: chore(c): remove C UUIDDumper and UUIDBinaryDumper X-Git-Tag: 3.2.5~2^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f950cb843711ef2ca4344e220e0504397432dff;p=thirdparty%2Fpsycopg.git chore(c): remove C UUIDDumper and UUIDBinaryDumper --- diff --git a/psycopg_c/psycopg_c/types/uuid.pyx b/psycopg_c/psycopg_c/types/uuid.pyx index 81f03e5ef..164be69c3 100644 --- a/psycopg_c/psycopg_c/types/uuid.pyx +++ b/psycopg_c/psycopg_c/types/uuid.pyx @@ -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 *: """ diff --git a/tests/types/test_uuid.py b/tests/types/test_uuid.py index 94dbabde2..c8dd6c0a8 100644 --- a/tests/types/test_uuid.py +++ b/tests/types/test_uuid.py @@ -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