]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
StringDumper renamed to StrDumper
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 26 Jun 2021 01:42:46 +0000 (02:42 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 26 Jun 2021 01:42:46 +0000 (02:42 +0100)
psycopg3/psycopg3/types/string.py
psycopg3_c/psycopg3_c/types/string.pyx
tests/test_adapt.py
tests/test_copy.py

index af405f206e0e7c73530a8193cf53bf0c3eb90746..b40b0ae275e123bfa2b51d0da47615f00bf08724 100644 (file)
@@ -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)
index 7284c6e8dfb83712dc6ea8be47f4041ade92a61f..0430f9a7d28b4dc4daae3247b9f6dc7cbf7e41df 100644 (file)
@@ -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)
index d835c91a2256d15c7da783fce90726b5ab46509f..decc3dc90305fdd3af8ec8e0f14889f3627a2267 100644 (file)
@@ -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"
 
 
index b61bf9d2134b7eadf6a7f69d09b97311cde4120a..70d0dd2169177c22c3b50e68bfd9846f555e41c5 100644 (file)
@@ -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)