From: Daniele Varrazzo Date: Sat, 26 Jun 2021 01:42:46 +0000 (+0100) Subject: StringDumper renamed to StrDumper X-Git-Tag: 3.0.dev0~17^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e774da74241ce60d1c43c388f4d5db552cf8c0e7;p=thirdparty%2Fpsycopg.git StringDumper renamed to StrDumper --- diff --git a/psycopg3/psycopg3/types/string.py b/psycopg3/psycopg3/types/string.py index af405f206..b40b0ae27 100644 --- a/psycopg3/psycopg3/types/string.py +++ b/psycopg3/psycopg3/types/string.py @@ -16,7 +16,7 @@ if TYPE_CHECKING: from ..pq.proto import Escaping as EscapingProto -class _StringDumper(Dumper): +class _StrDumper(Dumper): _encoding = "utf-8" @@ -30,7 +30,7 @@ class _StringDumper(Dumper): self._encoding = enc -class StringBinaryDumper(_StringDumper): +class StrBinaryDumper(_StrDumper): format = Format.BINARY _oid = builtins["text"].oid @@ -40,7 +40,7 @@ class StringBinaryDumper(_StringDumper): return obj.encode(self._encoding) -class StringDumper(_StringDumper): +class StrDumper(_StrDumper): format = Format.TEXT @@ -139,8 +139,8 @@ def register_default_globals(ctx: "AdaptContext") -> None: # The last one registered becomes the default for each type. # Normally, binary is the default dumper, except for text (which plays # the role of unknown, so it can be cast automatically to other types). - StringBinaryDumper.register(str, ctx) - StringDumper.register(str, ctx) + StrBinaryDumper.register(str, ctx) + StrDumper.register(str, ctx) TextLoader.register(INVALID_OID, ctx) TextLoader.register("bpchar", ctx) TextLoader.register("name", ctx) diff --git a/psycopg3_c/psycopg3_c/types/string.pyx b/psycopg3_c/psycopg3_c/types/string.pyx index 7284c6e8d..0430f9a7d 100644 --- a/psycopg3_c/psycopg3_c/types/string.pyx +++ b/psycopg3_c/psycopg3_c/types/string.pyx @@ -25,7 +25,7 @@ cdef extern from "Python.h": const char *PyUnicode_AsUTF8AndSize(unicode obj, Py_ssize_t *size) except NULL -cdef class _StringDumper(CDumper): +cdef class _StrDumper(CDumper): cdef int is_utf8 cdef char *encoding cdef bytes _bytes_encoding # needed to keep `encoding` alive @@ -70,7 +70,7 @@ cdef class _StringDumper(CDumper): @cython.final -cdef class StringBinaryDumper(_StringDumper): +cdef class StrBinaryDumper(_StrDumper): format = PQ_BINARY @@ -79,12 +79,12 @@ cdef class StringBinaryDumper(_StringDumper): @cython.final -cdef class StringDumper(_StringDumper): +cdef class StrDumper(_StrDumper): format = PQ_TEXT cdef Py_ssize_t cdump(self, obj, bytearray rv, Py_ssize_t offset) except -1: - cdef Py_ssize_t size = StringBinaryDumper.cdump(self, obj, rv, offset) + cdef Py_ssize_t size = StrBinaryDumper.cdump(self, obj, rv, offset) # Like the binary dump, but check for 0, or the string will be truncated cdef const char *buf = PyByteArray_AS_STRING(rv) diff --git a/tests/test_adapt.py b/tests/test_adapt.py index d835c91a2..decc3dc90 100644 --- a/tests/test_adapt.py +++ b/tests/test_adapt.py @@ -94,13 +94,13 @@ def test_dump_subclass(conn, fmt_out): def test_subclass_dumper(conn): # This might be a C fast object: make sure that the Python code is called - from psycopg3.types.string import StringDumper + from psycopg3.types.string import StrDumper - class MyStringDumper(StringDumper): + class MyStrDumper(StrDumper): def dump(self, obj): return (obj * 2).encode("utf-8") - MyStringDumper.register(str, conn) + MyStrDumper.register(str, conn) assert conn.execute("select %t", ["hello"]).fetchone()[0] == "hellohello" diff --git a/tests/test_copy.py b/tests/test_copy.py index b61bf9d21..70d0dd216 100644 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -259,15 +259,15 @@ def test_copy_in_empty(conn, format): @pytest.mark.parametrize("format", [Format.TEXT, Format.BINARY]) def test_subclass_adapter(conn, format): if format == Format.TEXT: - from psycopg3.types.string import StringDumper as BaseDumper + from psycopg3.types.string import StrDumper as BaseDumper else: - from psycopg3.types.string import StringBinaryDumper as BaseDumper + from psycopg3.types.string import StrBinaryDumper as BaseDumper - class MyStringDumper(BaseDumper): + class MyStrDumper(BaseDumper): def dump(self, obj): return super().dump(obj) * 2 - MyStringDumper.register(str, conn) + MyStrDumper.register(str, conn) cur = conn.cursor() ensure_table(cur, sample_tabledef)