K i&ddlmZddlZddlZddlmZddlmZddl m Z ddl m Z m Z ddlmZd gZej"ej$eeej"eeffej,eej"eefffZGd d Zy) ) annotationsN) urlencode) _TYPE_BODY)HTTPHeaderDict) _TYPE_FIELDSencode_multipart_formdata)BaseHTTPResponseRequestMethodsceZdZdZhdZd d dZ d d dZ d ddZ d ddZ d ddZ y)r a Convenience mixin for classes who implement a :meth:`urlopen` method, such as :class:`urllib3.HTTPConnectionPool` and :class:`urllib3.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. >GETHEADDELETEOPTIONSNc|xsi|_yN)headers)selfrs ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/urllib3/_request_methods.py__init__zRequestMethods.__init__3s }" c td)NzMClasses extending RequestMethods must implement their own ``urlopen`` method.)NotImplementedError)rmethodurlbodyrencode_multipartmultipart_boundarykws rurlopenzRequestMethods.urlopen6s" ,  rc |j}| | td|o| |j}dttj |j vrt|}d|d<tj|ddjd}|||d <||jvr|j||f||d |S|j||f||d |S) ay 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`. :param method: HTTP request method (such as GET, POST, PUT, etc.) :param url: The URL to perform the request on. :param body: Data to send in the request body, either :class:`str`, :class:`bytes`, an iterable of :class:`str`/:class:`bytes`, or a file-like object. :param fields: Data to encode and send in the URL or request body, depending on ``method``. :param headers: Dictionary of custom headers to send, such as User-Agent, If-None-Match, etc. If None, pool headers are used. If provided, these headers completely replace any pool-specific headers. :param json: Data to encode and send as JSON with UTF-encoded in the request body. The ``"Content-Type"`` header will be set to ``"application/json"`` unless specified otherwise. zUrequest got values for both 'body' and 'json' parameters which are mutually exclusivez content-typezapplication/json Content-Type),:F) separators ensure_asciizutf-8r)fieldsr)upper TypeErrorrmapstrlowerkeysr_jsondumpsencode_encode_url_methodsrequest_encode_urlrequest_encode_body)rrrrr'rjson urlopen_kws rrequestzRequestMethods.requestEsV   0g   ,,"c#))W\\^&DD(1*<';;t OVVD  !%Jv  T-- -*4**    ,4++$*G?I rc | |j}d|i}|j||r|dt|zz }|j||fi|S)a} Make a request using :meth:`urlopen` with the ``fields`` encoded in the url. This is useful for request methods like GET, HEAD, DELETE, etc. :param method: HTTP request method (such as GET, POST, PUT, etc.) :param url: The URL to perform the request on. :param fields: Data to encode and send in the URL. :param headers: Dictionary of custom headers to send, such as User-Agent, If-None-Match, etc. If None, pool headers are used. If provided, these headers completely replace any pool-specific headers. r?)rupdaterr )rrrr'rr5extra_kws rr2z!RequestMethods.request_encode_urlsW4 ?llG+4g*> #  36** *Ct||FC4844rc | |j}dt|i}|rId|vr td|rt||\} } n t |d} } | |d<|dj d| |j ||j||fi|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 :func:`urllib3.encode_multipart_formdata` is used to encode the payload with the appropriate content type. Otherwise :func:`urllib.parse.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. :param method: HTTP request method (such as GET, POST, PUT, etc.) :param url: The URL to perform the request on. :param fields: Data to encode and send in the request body. :param headers: Dictionary of custom headers to send, such as User-Agent, If-None-Match, etc. If None, pool headers are used. If provided, these headers completely replace any pool-specific headers. :param encode_multipart: If True, encode the ``fields`` using the multipart/form-data MIME format. :param multipart_boundary: If not specified, then a random boundary will be generated using :func:`urllib3.filepost.choose_boundary`. rrzFrequest got values for both 'fields' and 'body', can only specify one.)boundaryz!application/x-www-form-urlencodedr")rrr)r r setdefaultr9r ) rrrr'rrrr5r:r content_types rr3z"RequestMethods.request_encode_bodysF ?llG+4nW6M*N #\ %>%7&"l f%7# $HV  Y  * *>< H #t||FC4844rr)rtyping.Mapping[str, str] | NonereturnNone)NNTN)rr+rr+r_TYPE_BODY | Nonerr?rboolr str | Noner typing.Anyr@r )NNNN)rr+rr+rrBr'_TYPE_FIELDS | Nonerr?r4ztyping.Any | Noner5rEr@r )NN) rr+rr+r'z_TYPE_ENCODE_URL_FIELDS | Nonerr?r5r+r@r )rr+rr+r'rFrr?rrCrrDr5r+r@r ) __name__ __module__ __qualname____doc__r1rr r6r2r3rrr r s8?%#'37!%)-        1    '       &#'&*37"&LLL L $ L 1 L L!L Ld2637 #5#5#5/ #5 1 #5  #5 #5R'+37!%)-^5^5^5$ ^5 1 ^5  ^5'^5^5 ^5r) __future__rr4r.typing urllib.parser_base_connectionr _collectionsrfilepostrr responser __all__UnionSequencetupler+bytesMapping_TYPE_ENCODE_URL_FIELDSr rKrrrZs" "((=&   ,, OOE#v||CJ7789 NN3 S%Z0013 B5B5r