HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/requests_toolbelt/utils/__pycache__/formdata.cpython-310.pyc
o

�ˀX��@sDdZddlmZddlmZdZdd�Zdd�Zdd	�Zd
d�ZdS)
z8Implementation of nested form-data encoding function(s).�)�
basestring)�	urlencodecsztttf�t|�}tdd�|D��std��|}t�fdd�|D��r2t|�}t�fdd�|D��s#t|g|�Ri|��S)aTHandle nested form-data queries and serialize them appropriately.

    There are times when a website expects a nested form data query to be sent
    but, the standard library's urlencode function does not appropriately
    handle the nested structures. In that case, you need this function which
    will flatten the structure first and then properly encode it for you.

    When using this to send data in the body of a request, make sure you
    specify the appropriate Content-Type header for the request.

    .. code-block:: python

        import requests
        from requests_toolbelt.utils import formdata

        query = {
           'my_dict': {
               'foo': 'bar',
               'biz': 'baz",
            },
            'a': 'b',
        }

        resp = requests.get(url, params=formdata.urlencode(query))
        # or
        resp = requests.post(
            url,
            data=formdata.urlencode(query),
            headers={
                'Content-Type': 'application/x-www-form-urlencoded'
            },
        )

    Similarly, you can specify a list of nested tuples, e.g.,

    .. code-block:: python

        import requests
        from requests_toolbelt.utils import formdata

        query = [
            ('my_list', [
                ('foo', 'bar'),
                ('biz', 'baz'),
            ]),
            ('a', 'b'),
        ]

        resp = requests.get(url, params=formdata.urlencode(query))
        # or
        resp = requests.post(
            url,
            data=formdata.urlencode(query),
            headers={
                'Content-Type': 'application/x-www-form-urlencoded'
            },
        )

    For additional parameter and return information, see the official
    `urlencode`_ documentation.

    .. _urlencode:
        https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
    css�|]}t|�VqdS�N)�
_is_two_tuple)�.0�i�r�B/usr/lib/python3/dist-packages/requests_toolbelt/utils/formdata.py�	<genexpr>Ns�zurlencode.<locals>.<genexpr>zQExpected query to be able to be converted to a list comprised of length 2 tuples.c3s�|]
\}}t|��VqdSr)�
isinstance)r�_�v��expand_classesrr	r
Ss�)	�dict�list�tuple�_to_kv_list�all�
ValueError�any�_expand_query_values�
_urlencode)�query�args�kwargs�original_query_list�
query_listrrr	r
s
A�rcCst|d�rt|���S|S)N�items)�hasattrrr)�dict_or_listrrr	rYs
rcCst|ttf�ot|�dkS)Nr)rrr�len)�itemrrr	r_srcsXg}|D]%\}}t|t�r|�||f�q|d�t|�}|��fdd�|D��q|S)Nz[%s]c3s �|]\}}�||fVqdSrr)r�kr
��key_fmtrr	r
ks�z'_expand_query_values.<locals>.<genexpr>)rr�appendr�extend)rr�key�value�
value_listrr$r	rcs
rN)	�__doc__�_compatrrr�__all__rrrrrrr	�<module>sO