Python contextlib.AbstractContextManager() Examples

The following are 3 code examples of contextlib.AbstractContextManager(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module contextlib , or try the search function .
Example #1
Source File: base.py    From terracotta with MIT License 6 votes vote down vote up
def connect(self) -> contextlib.AbstractContextManager:
        """Context manager to connect to a given database and clean up on exit.

        This allows you to pool interactions with the database to prevent possibly
        expensive reconnects, or to roll back several interactions if one of them fails.

        Note:

            Make sure to call :meth:`create` on a fresh database before using this method.

        Example:

            >>> import terracotta as tc
            >>> driver = tc.get_driver('tc.sqlite')
            >>> with driver.connect():
            ...     for keys, dataset in datasets.items():
            ...         # connection will be kept open between insert operations
            ...         driver.insert(keys, dataset)

        """
        pass 
Example #2
Source File: sqlite.py    From terracotta with MIT License 5 votes vote down vote up
def connect(self) -> AbstractContextManager:
        return self._connect(check=True) 
Example #3
Source File: mysql.py    From terracotta with MIT License 5 votes vote down vote up
def connect(self) -> AbstractContextManager:
        return self._connect(check=True)