|
19 | 19 | MutableMapping,
|
20 | 20 | Optional,
|
21 | 21 | Pattern,
|
22 |
| - Set, |
23 | 22 | Tuple,
|
24 | 23 | Union,
|
25 | 24 | cast,
|
|
50 | 49 | reify,
|
51 | 50 | sentinel,
|
52 | 51 | set_exception,
|
53 |
| - set_result, |
54 | 52 | )
|
55 | 53 | from .http_parser import RawRequestMessage
|
56 | 54 | from .http_writer import HttpVersion
|
@@ -146,7 +144,6 @@ class BaseRequest(MutableMapping[str, Any], HeadersMixin):
|
146 | 144 | "_loop",
|
147 | 145 | "_transport_sslcontext",
|
148 | 146 | "_transport_peername",
|
149 |
| - "_disconnection_waiters", |
150 | 147 | ]
|
151 | 148 | )
|
152 | 149 |
|
@@ -194,7 +191,6 @@ def __init__(
|
194 | 191 | self._task = task
|
195 | 192 | self._client_max_size = client_max_size
|
196 | 193 | self._loop = loop
|
197 |
| - self._disconnection_waiters: Set[asyncio.Future[None]] = set() |
198 | 194 |
|
199 | 195 | transport = self._protocol.transport
|
200 | 196 | assert transport is not None
|
@@ -823,21 +819,18 @@ async def _prepare_hook(self, response: StreamResponse) -> None:
|
823 | 819 |
|
824 | 820 | def _cancel(self, exc: BaseException) -> None:
|
825 | 821 | set_exception(self._payload, exc)
|
826 |
| - for fut in self._disconnection_waiters: |
827 |
| - set_result(fut, None) |
828 | 822 |
|
829 | 823 | def _finish(self) -> None:
|
830 |
| - for fut in self._disconnection_waiters: |
831 |
| - fut.cancel() |
832 |
| - |
833 |
| - async def wait_for_disconnection(self) -> None: |
834 |
| - loop = asyncio.get_event_loop() |
835 |
| - fut = loop.create_future() # type: asyncio.Future[None] |
836 |
| - self._disconnection_waiters.add(fut) |
837 |
| - try: |
838 |
| - await fut |
839 |
| - finally: |
840 |
| - self._disconnection_waiters.remove(fut) |
| 824 | + if self._post is None or self.content_type != "multipart/form-data": |
| 825 | + return |
| 826 | + |
| 827 | + # NOTE: Release file descriptors for the |
| 828 | + # NOTE: `tempfile.Temporaryfile`-created `_io.BufferedRandom` |
| 829 | + # NOTE: instances of files sent within multipart request body |
| 830 | + # NOTE: via HTTP POST request. |
| 831 | + for file_name, file_field_object in self._post.items(): |
| 832 | + if isinstance(file_field_object, FileField): |
| 833 | + file_field_object.file.close() |
841 | 834 |
|
842 | 835 |
|
843 | 836 | class Request(BaseRequest):
|
|
0 commit comments