|
6 | 6 | from RequestsLibrary import log
|
7 | 7 | from RequestsLibrary.compat import urljoin
|
8 | 8 | from RequestsLibrary.utils import (
|
| 9 | + is_list_or_tuple, |
9 | 10 | is_file_descriptor,
|
10 | 11 | warn_if_equal_symbol_in_url_session_less,
|
11 | 12 | )
|
@@ -48,9 +49,16 @@ def _common_request(self, method, session, uri, **kwargs):
|
48 | 49 |
|
49 | 50 | files = kwargs.get("files", {}) or {}
|
50 | 51 | data = kwargs.get("data", []) or []
|
51 |
| - files_descriptor_to_close = filter( |
52 |
| - is_file_descriptor, list(files.values()) + [data] |
53 |
| - ) |
| 52 | + |
| 53 | + if is_list_or_tuple(files): |
| 54 | + files_descriptor_to_close = filter( |
| 55 | + is_file_descriptor, [file[1][1] for file in files] + [data] |
| 56 | + ) |
| 57 | + else: |
| 58 | + files_descriptor_to_close = filter( |
| 59 | + is_file_descriptor, list(files.values()) + [data] |
| 60 | + ) |
| 61 | + |
54 | 62 | for file_descriptor in files_descriptor_to_close:
|
55 | 63 | file_descriptor.close()
|
56 | 64 |
|
@@ -176,7 +184,7 @@ def session_less_get(
|
176 | 184 | | ``json`` | A JSON serializable Python object to send in the body of the request. |
|
177 | 185 | | ``headers`` | Dictionary of HTTP Headers to send with the request. |
|
178 | 186 | | ``cookies`` | Dict or CookieJar object to send with the request. |
|
179 |
| - | ``files`` | Dictionary of file-like-objects (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. | |
| 187 | + | ``files`` | Dictionary of file-like-objects (or ``{'name': file-tuple}``) for multipart encoding upload. ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers to add for the file. List or tuple of ``('key': file-tuple)`` allows uploading multiple files with the same key, resulting in a list of files on the receiving end. | |
180 | 188 | | ``auth`` | Auth tuple to enable Basic/Digest/Custom HTTP Auth. |
|
181 | 189 | | ``timeout`` | How many seconds to wait for the server to send data before giving up, as a float, or a ``(connect timeout, read timeout)`` tuple. |
|
182 | 190 | | ``allow_redirects`` | Boolean. Enable/disable (values ``${True}`` or ``${False}``). Only for HEAD method keywords allow_redirection defaults to ``${False}``, all others ``${True}``. |
|
|
0 commit comments