Construct a new Connection.
(
self,
engine: Engine,
connection: Optional[PoolProxiedConnection] = None,
_has_events: Optional[bool] = None,
_allow_revalidate: bool = True,
_allow_autobegin: bool = True,
)
| 133 | _nested_transaction: Optional[NestedTransaction] |
| 134 | |
| 135 | def __init__( |
| 136 | self, |
| 137 | engine: Engine, |
| 138 | connection: Optional[PoolProxiedConnection] = None, |
| 139 | _has_events: Optional[bool] = None, |
| 140 | _allow_revalidate: bool = True, |
| 141 | _allow_autobegin: bool = True, |
| 142 | ): |
| 143 | """Construct a new Connection.""" |
| 144 | self.engine = engine |
| 145 | self.dialect = dialect = engine.dialect |
| 146 | |
| 147 | if connection is None: |
| 148 | try: |
| 149 | self._dbapi_connection = engine.raw_connection() |
| 150 | except dialect.loaded_dbapi.Error as err: |
| 151 | Connection._handle_dbapi_exception_noconnection( |
| 152 | err, dialect, engine |
| 153 | ) |
| 154 | raise |
| 155 | else: |
| 156 | self._dbapi_connection = connection |
| 157 | |
| 158 | self._transaction = self._nested_transaction = None |
| 159 | self.__savepoint_seq = 0 |
| 160 | self.__in_begin = False |
| 161 | |
| 162 | self.__can_reconnect = _allow_revalidate |
| 163 | self._allow_autobegin = _allow_autobegin |
| 164 | self._echo = self.engine._should_log_info() |
| 165 | |
| 166 | if _has_events is None: |
| 167 | # if _has_events is sent explicitly as False, |
| 168 | # then don't join the dispatch of the engine; we don't |
| 169 | # want to handle any of the engine's events in that case. |
| 170 | self.dispatch = self.dispatch._join(engine.dispatch) |
| 171 | self._has_events = _has_events or ( |
| 172 | _has_events is None and engine._has_events |
| 173 | ) |
| 174 | |
| 175 | self._execution_options = engine._execution_options |
| 176 | |
| 177 | if self._has_events or self.engine._has_events: |
| 178 | self.dispatch.engine_connect(self) |
| 179 | |
| 180 | # this can be assigned differently via |
| 181 | # characteristics.LoggingTokenCharacteristic |
nothing calls this directly
no test coverage detected