MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / _copy_out

Method _copy_out

asyncpg/connection.py:1194–1231  ·  view source on GitHub ↗
(self, copy_stmt, output, timeout)

Source from the content-addressed store, hash-verified

1192 return ''
1193
1194 async def _copy_out(self, copy_stmt, output, timeout):
1195 try:
1196 path = os.fspath(output)
1197 except TypeError:
1198 # output is not a path-like object
1199 path = None
1200
1201 writer = None
1202 opened_by_us = False
1203 run_in_executor = self._loop.run_in_executor
1204
1205 if path is not None:
1206 # a path
1207 f = await run_in_executor(None, open, path, 'wb')
1208 opened_by_us = True
1209 elif hasattr(output, 'write'):
1210 # file-like
1211 f = output
1212 elif callable(output):
1213 # assuming calling output returns an awaitable.
1214 writer = output
1215 else:
1216 raise TypeError(
1217 'output is expected to be a file-like object, '
1218 'a path-like object or a coroutine function, '
1219 'not {}'.format(type(output).__name__)
1220 )
1221
1222 if writer is None:
1223 async def _writer(data):
1224 await run_in_executor(None, f.write, data)
1225 writer = _writer
1226
1227 try:
1228 return await self._protocol.copy_out(copy_stmt, writer, timeout)
1229 finally:
1230 if opened_by_us:
1231 f.close()
1232
1233 async def _copy_in(self, copy_stmt, source, timeout):
1234 try:

Callers 2

copy_from_tableMethod · 0.95
copy_from_queryMethod · 0.95

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected