Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_default_event_loop(connect, loop):
asyncio.set_event_loop(loop)
conn = await connect(no_loop=True)
cur = await conn.cursor()
assert isinstance(cur, Cursor)
await cur.execute('SELECT 1')
ret = await cur.fetchone()
assert (1,) == ret
assert conn._loop is loop
async def test_simple_select(connect):
conn = await connect()
cur = await conn.cursor()
assert isinstance(cur, Cursor)
await cur.execute('SELECT 1')
ret = await cur.fetchone()
assert (1,) == ret
def off(self):
Cursor.execute = self._tmp_execute
def __init__(self):
self._queries = []
self._total_time = 0
# save original
self._tmp_execute = Cursor.execute
if not self.closed_cursor:
warnings.warn(('You can only have one cursor per connection. '
'The cursor for connection will be closed forcibly'
' {!r}.').format(self), ResourceWarning)
self.free_cursor()
if timeout is None:
timeout = self._timeout
impl = await self._cursor_impl(name=name,
cursor_factory=cursor_factory,
scrollable=scrollable,
withhold=withhold)
self._cursor_instance = Cursor(self, impl, timeout, self._echo)
return self._cursor_instance
_connection_factory=SAConnection,
**kwargs))
@asyncio.coroutine
def create_pool(dsn=None, *, minsize=10, maxsize=10,
loop=None, **kwargs):
return (yield from base_create_pool(dsn,
minsize=minsize,
maxsize=maxsize,
loop=loop,
_connection_factory=SAConnection,
**kwargs))
class SACursor(Cursor):
def __init__(self, conn, impl, dialect):
super().__init__(conn, impl)
self._dialect = dialect
@property
def dialect(self):
"""sqlalchemy dialect, PGDialect_psycopg2() by default."""
return self._dialect
@asyncio.coroutine
def execute(self, operation, parameters=()):
if isinstance(operation, ClauseElement):
assert parameters == (), ("Don't mix sqlalchemy clause "
"and execution with parameters")
compiled = operation.compile(dialect=self._dialect)