(self, copy_stmt, output, timeout)
| 1169 | return '' |
| 1170 | |
| 1171 | async def _copy_out(self, copy_stmt, output, timeout): |
| 1172 | try: |
| 1173 | path = os.fspath(output) |
| 1174 | except TypeError: |
| 1175 | # output is not a path-like object |
| 1176 | path = None |
| 1177 | |
| 1178 | writer = None |
| 1179 | opened_by_us = False |
| 1180 | run_in_executor = self._loop.run_in_executor |
| 1181 | |
| 1182 | if path is not None: |
| 1183 | # a path |
| 1184 | f = await run_in_executor(None, open, path, 'wb') |
| 1185 | opened_by_us = True |
| 1186 | elif hasattr(output, 'write'): |
| 1187 | # file-like |
| 1188 | f = output |
| 1189 | elif callable(output): |
| 1190 | # assuming calling output returns an awaitable. |
| 1191 | writer = output |
| 1192 | else: |
| 1193 | raise TypeError( |
| 1194 | 'output is expected to be a file-like object, ' |
| 1195 | 'a path-like object or a coroutine function, ' |
| 1196 | 'not {}'.format(type(output).__name__) |
| 1197 | ) |
| 1198 | |
| 1199 | if writer is None: |
| 1200 | async def _writer(data): |
| 1201 | await run_in_executor(None, f.write, data) |
| 1202 | writer = _writer |
| 1203 | |
| 1204 | try: |
| 1205 | return await self._protocol.copy_out(copy_stmt, writer, timeout) |
| 1206 | finally: |
| 1207 | if opened_by_us: |
| 1208 | f.close() |
| 1209 | |
| 1210 | async def _copy_in(self, copy_stmt, source, timeout): |
| 1211 | try: |
no test coverage detected