ó
    úÞ j¡  ã                   ó<   • S r SSKJr  SSKJr  SrS rS rS rS rg)	z8Implementation of nested form-data encoding function(s).é   )Ú
basestring)Ú	urlencodec                 ó$  ^• [         [        [        4m[        U 5      n[	        S U 5       5      (       d  [        S5      eUn[        U4S jU 5       5      (       a'  [        U5      n[        U4S jU 5       5      (       a  M'  [        U/UQ70 UD6$ )aŒ  Handle 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
c              3   ó6   #   • U H  n[        U5      v •  M     g 7f©N)Ú_is_two_tuple)Ú.0Úis     ÚZ/var/www/html/gaurav/venv/lib/python3.13/site-packages/requests_toolbelt/utils/formdata.pyÚ	<genexpr>Úurlencode.<locals>.<genexpr>N   s   é € Ð=Ñ)< AŒ}˜Q×ÐÒ)<ùs   ‚zQExpected query to be able to be converted to a list comprised of length 2 tuples.c              3   ó>   >#   • U H  u  p[        UT5      v •  M     g 7fr   )Ú
isinstance)r	   Ú_ÚvÚexpand_classess      €r   r   r   S   s   øé € ÐC¹
±°Œj˜˜N×+Ð+º
ùs   ƒ)	ÚdictÚlistÚtupleÚ_to_kv_listÚallÚ
ValueErrorÚanyÚ_expand_query_valuesÚ
_urlencode)ÚqueryÚargsÚkwargsÚoriginal_query_listÚ
query_listr   s        @r   r   r   
   s�   ø€ ôB œD¤%Ð(€NÜ% eÓ,ÐäÑ=Ñ)<Ó=×=Ñ=Üð >ó ?ð 	?ð %€JÜ
ÔC¹
ÓC×
CÑ
CÜ)¨*Ó5ˆ
ô ÔC¹
ÓC×
CÓ
Cô �jÐ2 4Ò2¨6Ñ2Ð2ó    c                 óZ   • [        U S5      (       a  [        U R                  5       5      $ U $ )NÚitems)Úhasattrr   r#   )Údict_or_lists    r   r   r   Y   s)   € Üˆ|˜W×%Ñ%Ü�L×&Ñ&Ó(Ó)Ð)ØÐr!   c                 óX   • [        U [        [        45      =(       a    [        U 5      S:H  $ )Nr   )r   r   r   Úlen)Úitems    r   r   r   _   s    € Ü�dœT¤5˜MÓ*×=¬s°4«y¸A©~Ð=r!   c                 óÊ   ^• / nU  HY  u  p#[        U[        5      (       a  UR                  X#45        M.  US-   m[        U5      nUR	                  U4S jU 5       5        M[     U$ )Nz[%s]c              3   ó4   >#   • U H  u  pTU-  U4v •  M     g 7fr   © )r	   Úkr   Úkey_fmts      €r   r   Ú'_expand_query_values.<locals>.<genexpr>k   s   øé € ÐF¹:±4°1˜w¨™{¨AÕ.º:ùs   ƒ)r   r   Úappendr   Úextend)r   r    ÚkeyÚvalueÚ
value_listr-   s        @r   r   r   c   s`   ø€ Ø€JÛ)‰
ˆÜ�eœZ×(Ñ(Ø×Ñ˜s˜lÖ+à˜F‘lˆGÜ$ UÓ+ˆJØ×ÑÔF¹:ÓFÖFñ *ð Ðr!   N)	Ú__doc__Ú_compatr   r   r   Ú__all__r   r   r   r+   r!   r   Ú<module>r7      s+   ðá >Ý  Ý -ð €òL3ò^ò>ó	r!   