:members:
-.. autoclass:: Dumper(src, context=None)
+.. autoclass:: Dumper(cls, context=None)
This is an abstract base class: subclasses *must* implement the `dump()`
method and specify the `format`.
from the context, but this may fail in some contexts and may require a
cast.
- :param src: The type that will be managed by this dumper.
- :type src: type
+ :param cls: The type that will be managed by this dumper.
+ :type cls: type
:param context: The context where the transformation is performed. If not
specified the conversion might be inaccurate, for instance it will not
be possible to know the connection encoding or the server date format.
Document how to find type OIDs in a database.
- .. automethod:: register(src, context=None)
+ .. automethod:: register(cls, context=None)
You should call this method on the `Dumper` subclass you create,
- passing the Python type you want to dump as *src*.
+ passing the Python type you want to dump as *cls*.
- :param src: The type to manage.
- :type src: `!type` or `!str`
+ :param cls: The type to manage.
+ :type cls: `!type` or `!str`
:param context: Where the dumper should be used. If `!None` the dumper
will be used globally.
:type context: `~psycopg3.Connection`, `~psycopg3.Cursor`, or `Transformer`
- If *src* is specified as string it will be lazy-loaded, so that it
+ If *cls* is specified as string it will be lazy-loaded, so that it
will be possible to register it without importing it before. In this
case it should be the fully qualified name of the object (e.g.
``"uuid.UUID"``).
format = Format.TEXT
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ super().__init__(cls, context)
self._tx = Transformer(context)
def _dump_sequence(
format = Format.TEXT
_oid = builtins["interval"].oid
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ super().__init__(cls, context)
if self.connection:
if (
self.connection.pgconn.parameter_status(b"IntervalStyle")
_encoding = "utf-8"
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ super().__init__(cls, context)
conn = self.connection
if conn:
format = Format.TEXT
_oid = builtins["bytea"].oid
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ super().__init__(cls, context)
self._esc = Escaping(
self.connection.pgconn if self.connection else None
)
cdef class CDumper:
- cdef object src
+ cdef object cls
cdef public libpq.Oid oid
cdef readonly object connection
cdef pq.PGconn _pgconn
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- self.src = src
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ self.cls = cls
self.connection = context.connection if context is not None else None
self._pgconn = (
self.connection.pgconn if self.connection is not None else None
@classmethod
def register(
cls,
- src: Union[type, str],
+ cls: Union[type, str],
context: Optional[AdaptContext] = None,
int format = Format.TEXT,
) -> None:
else:
from psycopg3.adapt import global_adapters as adapters
- adapters.register_dumper(src, cls)
+ adapters.register_dumper(cls, cls)
cdef class CLoader:
def __cinit__(self):
self.oid = oids.INT8_OID
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ super().__init__(cls, context)
def dump(self, obj) -> bytes:
cdef char buf[22]
cdef char *encoding
cdef bytes _bytes_encoding # needed to keep `encoding` alive
- def __init__(self, src: type, context: Optional[AdaptContext]):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext]):
+ super().__init__(cls, context)
self.is_utf8 = 0
self.encoding = "utf-8"
def __cinit__(self):
self.oid = oids.BYTEA_OID
- def __init__(self, src: type, context: Optional[AdaptContext] = None):
- super().__init__(src, context)
+ def __init__(self, cls: type, context: Optional[AdaptContext] = None):
+ super().__init__(cls, context)
self.esc = Escaping(self._pgconn)
def dump(self, obj) -> memoryview: