A partial implementation of this protocol (implementing everyting except
`dump()`) is available as `psycopg.adapt.Dumper`.
- .. attribute:: format
- :type: pq.Format
-
- The format this class dumps, `~Format.TEXT` or `~Format.BINARY`.
- This is a class attribute.
+ .. autoattribute:: format
.. automethod:: dump
A partial implementation of this protocol (implementing everyting except
`load()`) is available as `psycopg.adapt.Loader`.
- .. attribute:: format
- :type: Format
-
- The format this class can load, `~Format.TEXT` or `~Format.BINARY`.
- This is a class attribute.
+ .. autoattribute:: format
.. automethod:: load
See :ref:`adaptation` for an overview of the Psycopg adaptation system.
+.. _abstract base class: https://docs.python.org/glossary.html#term-abstract-base-class
+
Dumpers and loaders
-------------------
.. autoclass:: Dumper(cls, context=None)
- This is an abstract base class: subclasses *must* at least implement the
- `dump()` method and specify the `format`.
-
- The class implements the `~psycopg.abc.Dumper` protocol.
+ This is an `abstract base class`_, partially implementing the
+ `~psycopg.abc.Dumper` protocol. Subclasses *must* at least implement the
+ `.dump()` method and optionally override other members.
.. automethod:: dump
+ .. attribute:: format
+ :type: psycopg.pq.Format
+ :value: TEXT
+
+ Class attribute. Set it to `~psycopg.pq.Format.BINARY` if the class
+ `dump()` methods converts the object to binary format.
+
.. automethod:: quote
.. automethod:: get_key
.. autoclass:: Loader(oid, context=None)
- This is an abstract base class: subclasses *must* at least implement the
- `!load()` method and specify a `format`.
-
- The class implements the `~psycopg.abc.Loader` protocol.
+ This is an `abstract base class`_, partially implementing the
+ `~psycopg.abc.Loader` protocol. Subclasses *must* at least implement the
+ `.load()` method and optionally override other members.
.. automethod:: load
+ .. attribute:: format
+ :type: psycopg.pq.Format
+ :value: TEXT
+
+ Class attribute. Set it to `~psycopg.pq.Format.BINARY` if the class
+ `load()` methods converts the object from binary format.
+
Other objects used in adaptations
---------------------------------
"""
format: pq.Format
- """The format this dumper produces (class attirbute)."""
+ """
+ The format that this class `dump()` method produces,
+ `~psycopg.pq.Format.TEXT` or `~psycopg.pq.Format.BINARY`.
+
+ This is a class attribute.
+ """
oid: int
"""The oid to pass to the server, if known; 0 otherwise (class attribute)."""
class Loader(Protocol):
"""
- Convert PostgreSQL objects with OID *oid* to Python objects.
+ Convert PostgreSQL values with type OID *oid* to Python objects.
"""
format: pq.Format
+ """
+ The format that this class `load()` method can convert,
+ `~psycopg.pq.Format.TEXT` or `~psycopg.pq.Format.BINARY`.
+
+ This is a class attribute.
+ """
def __init__(self, oid: int, context: Optional[AdaptContext] = None):
...
return self
-class Loader(ABC):
+class Loader(abc.Loader, ABC):
"""
- Convert PostgreSQL objects with OID *oid* to Python objects.
+ Convert PostgreSQL values with type OID *oid* to Python objects.
"""
format: pq.Format = pq.Format.TEXT