3 nf\g@s>ddlmZddlmZddlmZdgZGdddeZdS))absolute_import)encode_multipart_formdata) urlencodeRequestMethodsc@sNeZdZdZddddhZdddZdd d Zdd d ZdddZdddZ dS)ra Convenience mixin for classes who implement a :meth:`urlopen` method, such as :class:`~urllib3.connectionpool.HTTPConnectionPool` and :class:`~urllib3.poolmanager.PoolManager`. Provides behavior for making common types of HTTP request methods and decides which type of request field encoding to use. Specifically, :meth:`.request_encode_url` is for sending requests whose fields are encoded in the URL (such as GET, HEAD, DELETE). :meth:`.request_encode_body` is for sending requests whose fields are encoded in the *body* of the request using multipart or www-form-urlencoded (such as for POST, PUT, PATCH). :meth:`.request` is for making any kind of request, it will look up the appropriate encoding format and use one of the above two methods to make the request. Initializer parameters: :param headers: Headers to include with all requests, unless other headers are given explicitly. ZDELETEZGETZHEADZOPTIONSNcCs|pi|_dS)N)headers)selfrr /usr/lib/python3.6/request.py__init__)szRequestMethods.__init__TcKs tddS)NzMClasses extending RequestMethods must implement their own ``urlopen`` method.)NotImplementedError)rmethodurlbodyrencode_multipartmultipart_boundarykwr r r urlopen,szRequestMethods.urlopencKsR|j}||d<||jkr4|j||f||d|S|j||f||d|SdS)a Make a request using :meth:`urlopen` with the appropriate encoding of ``fields`` based on the ``method`` used. This is a convenience method that requires the least amount of manual effort. It can be used in most situations, while still having the option to drop down to more specific methods when necessary, such as :meth:`request_encode_url`, :meth:`request_encode_body`, or even the lowest level :meth:`urlopen`. Z request_url)fieldsrN)upper_encode_url_methodsrequest_encode_urlrequest_encode_body)rr rrr urlopen_kwr r r request2s    zRequestMethods.requestcKsD|dkr|j}d|i}|j||r4|dt|7}|j||f|S)z Make a request using :meth:`urlopen` with the ``fields`` encoded in the url. This is useful for request methods like GET, HEAD, DELETE, etc. Nr?)rupdaterr)rr rrrrextra_kwr r r rJs z!RequestMethods.request_encode_urlc Ks|dkr|j}dii}|rbd|kr*td|r@t||d\} } nt|d} } | |d<d| i|d<|dj||j||j||f|S)a Make a request using :meth:`urlopen` with the ``fields`` encoded in the body. This is useful for request methods like POST, PUT, PATCH, etc. When ``encode_multipart=True`` (default), then :meth:`urllib3.filepost.encode_multipart_formdata` is used to encode the payload with the appropriate content type. Otherwise :meth:`urllib.urlencode` is used with the 'application/x-www-form-urlencoded' content type. Multipart encoding must be used when posting files, and it's reasonably safe to use it in other times too. However, it may break request signing, such as with OAuth. Supports an optional ``fields`` parameter of key/value strings AND key/filetuple. A filetuple is a (filename, data, MIME type) tuple where the MIME type is optional. For example:: fields = { 'foo': 'bar', 'fakefile': ('foofile.txt', 'contents of foofile'), 'realfile': ('barfile.txt', open('realfile').read()), 'typedfile': ('bazfile.bin', open('bazfile').read(), 'image/jpeg'), 'nonamefile': 'contents of nonamefile field', } When uploading a file, providing a filename (the first parameter of the tuple) is optional but recommended to best mimic behavior of browsers. Note that if ``headers`` are supplied, the 'Content-Type' header will be overwritten because it depends on the dynamic random boundary string which is used to compose the body of the request. The random boundary string can be explicitly set with the ``multipart_boundary`` parameter. NrrzFrequest got values for both 'fields' and 'body', can only specify one.)boundaryz!application/x-www-form-urlencodedz Content-Type)r TypeErrorrrrr) rr rrrrrrrrZ content_typer r r r[s&  z"RequestMethods.request_encode_body)N)NNTN)NN)NN)NNTN) __name__ __module__ __qualname____doc__rr rrrrr r r r r s     N) Z __future__rZfilepostrZpackages.six.moves.urllib.parser__all__objectrr r r r s