relstorage.adapters.drivers – Helpers for drivers#

Helpers for drivers

exception DriverNotImportableError(driver_name, driver_options=None, reason=None)[source]#

Bases: DriverNotAvailableError, ImportError

When the module can’t be imported.

class AbstractModuleDriver[source]#

Bases: object

Base implementation of a driver, based on a module, as used in DBAPI.

Subclasses must provide:

  • MODULE_NAME property.

  • __name__ property

  • Implementation of get_driver_module; this should import the module at runtime.

  • Implementation of exception_is_deadlock

exception DriverNotAvailableError(driver_name, driver_options=None, reason=None)#

Bases: Exception

Raised when a requested driver isn’t available.

driver_name = None#

The name of the requested driver

driver_options = None#

The IDBDriverOptions that was asked for the driver.

reason = None#

The underlying reason string, for example, from an import error if such is available. This can be an arbitrary object; if it is not None, its str() value is included in our own.


Default implementation; does nothing.

enter_critical_phase_until_transaction_end(connection, cursor)[source]#

Default implementation; does nothing.

exit_critical_phase(connection, cursor)[source]#

Default implementation; does nothing.


Import and return the driver module.

is_in_critical_phase(connection, cursor)[source]#

Default implementation; returns a false value.


Exceptions here are ignored, we don’t know what state the cursor is in.


Can this module be used on PyPy?


The name of the DB-API module to import.


Priority of this driver, when available. Lower is better. (That is, first choice should have value 1, and second choice value 2, and so on.)


Priority of this driver when running on PyPy. Lower is better.


Set this to a sequence of strings of requirements ("pg8000 >= 1.29",) Creating an instance will validate that the requirements are met (packages with correct versions are installed).

Do this only when a requirement cannot be specified in as an installation requirement.

New in version 4.0.0a1.


Set this to a false value if your subclass can do static checks at import time to determine it should not be used. Helpful for things like Python version detection.

STRICT = False#

Class attribute. If set to a true value (not the default), ask the underlying driver to work in as strict a mode as possible when it comes to detecting programming errors.

Typically set by tests. Most drivers do not have a stricter mode that can be enabled.

cursor_arraysize = 1024#

The size we request cursor’s from our cursor() method to fetch from fetchmany and (hopefully) iteration (which is a DB-API extension. We default to 1024, but the environment variable RS_CURSOR_ARRAYSIZE can be set to an int to change this default. Individual drivers might choose a different default.

casefold(self, /)#

Return a version of the string suitable for caseless comparisons.

implement_db_driver_options(name, *driver_modules)[source]#

Helper function to be called at a module scope to make it implement IDBDriverOptions.

  • name (str) – The value of __name__.

  • driver_modules – Each of these names a module that has one or more implementations of IDBDriver in it, as named in their __all__ attribute.