if obj is None:
return None, TEXT_OID
- cls = type(obj)
- func = self.get_adapt_function(cls, fmt)
+ src = type(obj)
+ func = self.get_adapt_function(src, fmt)
return func(obj)
- def get_adapt_function(self, cls: type, fmt: Format) -> AdapterFunc:
+ def get_adapt_function(self, src: type, fmt: Format) -> AdapterFunc:
try:
- return self._adapt_funcs[cls, fmt]
+ return self._adapt_funcs[src, fmt]
except KeyError:
pass
- adapter = self.lookup_adapter(cls, fmt)
+ adapter = self.lookup_adapter(src, fmt)
if isinstance(adapter, type):
- return adapter(cls, self.connection).adapt
+ return adapter(src, self.connection).adapt
else:
return adapter
- def lookup_adapter(self, cls: type, fmt: Format) -> AdapterType:
- key = (cls, fmt)
+ def lookup_adapter(self, src: type, fmt: Format) -> AdapterType:
+ key = (src, fmt)
cur = self.cursor
if cur is not None and key in cur.adapters:
return Adapter.globals[key]
raise e.ProgrammingError(
- f"cannot adapt type {cls} to format {Format(fmt).name}"
+ f"cannot adapt type {src} to format {Format(fmt).name}"
)
def cast_row(self, result: PGresult, n: int) -> Generator[Any, None, None]:
@Adapter.text(list)
class ListAdapter(Adapter):
- def __init__(self, cls: type, context: AdaptContext = None):
- super().__init__(cls, context)
+ def __init__(self, src: type, context: AdaptContext = None):
+ super().__init__(src, context)
self.tx = Transformer(context)
def adapt(self, obj: List[Any]) -> bytes:
@Adapter.text(str)
@Adapter.binary(str)
class StringAdapter(Adapter):
- def __init__(self, cls: type, context: AdaptContext):
- super().__init__(cls, context)
+ def __init__(self, src: type, context: AdaptContext):
+ super().__init__(src, context)
self._encode: EncodeFunc
if self.connection is not None:
@Adapter.text(bytes)
class BytesAdapter(Adapter):
- def __init__(self, cls: type, context: AdaptContext = None):
- super().__init__(cls, context)
+ def __init__(self, src: type, context: AdaptContext = None):
+ super().__init__(src, context)
self.esc = Escaping(
self.connection.pgconn if self.connection is not None else None
)