![]() Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : fdshops ( 1003) PHP Version : 8.2.21 Disable Function : NONE Directory : /lib/python2.7/site-packages/requests_toolbelt/utils/ |
� ӵ Yc @ sT d Z d d l m Z d d l m Z d Z d � Z d � Z d � Z d � Z d S( s8 Implementation of nested form-data encoding function(s).i ( t basestring( t urlencodeR c s� t t t f � t | � } t d � | D� � s@ t d � � n | } x, t � f d � | D� � rt t | � } qI Wt | | | � S( sT 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 s s | ] } t | � Vq d S( N( t _is_two_tuple( t .0t i( ( sD /usr/lib/python2.7/site-packages/requests_toolbelt/utils/formdata.pys <genexpr>N s sQ Expected query to be able to be converted to a list comprised of length 2 tuples.c 3 s$ | ] \ } } t | � � Vq d S( N( t isinstance( R t _t v( t expand_classes( sD /usr/lib/python2.7/site-packages/requests_toolbelt/utils/formdata.pys <genexpr>S s ( t dictt listt tuplet _to_kv_listt allt ValueErrort anyt _expand_query_valuest _urlencode( t queryt argst kwargst original_query_listt query_list( ( R sD /usr/lib/python2.7/site-packages/requests_toolbelt/utils/formdata.pyR s Ac C s# t | d � r t | j � � S| S( Nt items( t hasattrR R ( t dict_or_list( ( sD /usr/lib/python2.7/site-packages/requests_toolbelt/utils/formdata.pyR Y s c C s% t | t t f � o$ t | � d k S( Ni ( R R R t len( t item( ( sD /usr/lib/python2.7/site-packages/requests_toolbelt/utils/formdata.pyR _ s c sy g } xl | D]d \ } } t | t � r>