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.

configure_from_options(options)[source]#

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.

get_driver_module()[source]#

Import and return the driver module.

is_in_critical_phase(connection, cursor)[source]#

Default implementation; returns a false value.

synchronize_cursor_for_rollback(cursor)[source]#

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

AVAILABLE_ON_PYPY = True#

Can this module be used on PyPy?

MODULE_NAME = None#

The name of the DB-API module to import.

PRIORITY = 100#

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_PYPY = 100#

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

REQUIREMENTS = ()#

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 setup.py as an installation requirement.

New in version 4.0.0a1.

STATIC_AVAILABLE = True#

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.

Parameters:
  • 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.