(self, copy_stmt, output, timeout)
| 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: |
no test coverage detected