def is_psycopg_green(): """Test whether gevent compatibility layer is installed in psycopg.""" if not hasattr(extensions, 'set_wait_callback'): raise ImportError( "support for coroutines not available in this Psycopg version (%s)" % psycopg2.__version__) return extensions.get_wait_callback() == gevent_wait_callback
def _check_wait_callback(self): # Subclasses may override this method if they have no concept of # this. extensions = self._get_extension_module() callback = extensions.get_wait_callback() # Truth table: # callback is not None | Need callback | pass? # True | True | Pass # False | False | Pass # True | False | Fail # False | True | Fail # # This is XNOR, exclusive nor, or iff. Note how it passes # only when both conditions are the same. callback_not_none = bool(callback is not None) need_callback = bool(self._WANT_WAIT_CALLBACK) if callback_not_none is not need_callback: raise WaitCallbackStateError(self.__name__, callback_not_none, need_callback)
def is_psycopg_patched(): """Return True if psycopg is patched, False otherwise""" if not hasattr(extensions, 'get_wait_callback'): return False return extensions.get_wait_callback() == gevent_wait_callback
def _check_wait_callback(self): from psycopg2 import extensions # pylint:disable=no-name-in-module if extensions.get_wait_callback() is not None: # pragma: no cover raise ImportError("Wait callback installed")