U
f[* @ s d dl mZ d dlZd dlZd dlZejeef Z eje ej
ee f ej
ee ef f ZdddddddZdd dd
ddZ
dd dd
d
dZdd dd
ddZdd dd
ddZG dd dZdS ) )annotationsNapplication/octet-stream
str | Nonestr)filenamedefaultreturnc C s | rt | d p|S |S )z
Guess the "Content-Type" of a file.
:param filename:
The filename to guess the "Content-Type" of using :mod:`mimetypes`.
:param default:
If no "Content-Type" can be guessed, default to `default`.
r ) mimetypes
guess_type)r r r ?/opt/alt/python38/lib/python3.8/site-packages/urllib3/fields.pyguess_content_type s r
_TYPE_FIELD_VALUEnamevaluer c s ddl }|jdtdd t tr, d t fddd D s~| d
d}z|d W n tt fk
rx Y nX |S t
j d | d
S )a
Helper function to format and quote a single header parameter using the
strategy defined in RFC 2231.
Particularly useful for header parameters which might contain
non-ASCII values, like file names. This follows
`RFC 2388 Section 4.4 `_.
:param name:
The name of the parameter, a string expected to be ASCII only.
:param value:
The value of the parameter, provided as ``bytes`` or `str``.
:returns:
An RFC-2231-formatted unicode string.
.. deprecated:: 2.0.0
Will be removed in urllib3 v2.1.0. This is not valid for
``multipart/form-data`` header parameters.
r Nz'format_header_param_rfc2231' is deprecated and will be removed in urllib3 v2.1.0. This is not valid for multipart/form-data header parameters.
stacklevelutf-8c 3 s | ]}| kV qd S )Nr ).0chr r r @ s z.format_header_param_rfc2231..z"\
=""asciiz*=)
warningswarnDeprecationWarning
isinstancebytesdecodeanyencodeUnicodeEncodeErrorUnicodeDecodeErroremailutilsencode_rfc2231)r r r resultr r r format_header_param_rfc2231 s$
r+ c C s6 t |tr|d}|dddd}| d| dS )a
Format and quote a single multipart header parameter.
This follows the `WHATWG HTML Standard`_ as of 2021/06/10, matching
the behavior of current browser and curl versions. Values are
assumed to be UTF-8. The ``\n``, ``\r``, and ``"`` characters are
percent encoded.
.. _WHATWG HTML Standard:
https://html.spec.whatwg.org/multipage/
form-control-infrastructure.html#multipart-form-data
:param name:
The name of the parameter, an ASCII-only ``str``.
:param value:
The value of the parameter, a ``str`` or UTF-8 encoded
``bytes``.
:returns:
A string ``name="value"`` with the escaped value.
.. versionchanged:: 2.0.0
Matches the WHATWG HTML Standard as of 2021/06/10. Control
characters are no longer percent encoded.
.. versionchanged:: 2.0.0
Renamed from ``format_header_param_html5`` and
``format_header_param``. The old names will be removed in
urllib3 v2.1.0.
r z%0Az%0Dz%22)
" r r )r r! r" translate)r r r r r format_multipart_header_paramO s
r0 c C s" ddl }|jdtdd t| |S )
.. deprecated:: 2.0.0
Renamed to :func:`format_multipart_header_param`. Will be
removed in urllib3 v2.1.0.
r Nz'format_header_param_html5' has been renamed to 'format_multipart_header_param'. The old name will be removed in urllib3 v2.1.0.r r r r r r0 r r r r r r format_header_param_html5u s r4 c C s" ddl }|jdtdd t| |S )r1 r Nzz'format_header_param' has been renamed to 'format_multipart_header_param'. The old name will be removed in urllib3 v2.1.0.r r r2 r3 r r r format_header_param s r5 c @ s e Zd ZdZdddddddd d
Zeddddd dd
dZddddddZdddddZddddZ ddddddddZ
dS ) RequestFielda
A data container for request body parameters.
:param name:
The name of this request field. Must be unicode.
:param data:
The data/value body.
:param filename:
An optional filename of the request field. Must be unicode.
:param headers:
An optional dict-like object of headers to initially use for the field.
.. versionchanged:: 2.0.0
The ``header_formatter`` parameter is deprecated and will
be removed in urllib3 v2.1.0.
Nr r r ztyping.Mapping[str, str] | Nonez5typing.Callable[[str, _TYPE_FIELD_VALUE], str] | None)r datar headersheader_formatterc C sX || _ || _|| _i | _|r&t|| _|d k rNdd l}|jdtdd || _nt | _d S )Nr zUThe 'header_formatter' parameter is deprecated and will be removed in urllib3 v2.1.0.r r )
_name _filenamer7 r8 dictr r r r9 r0 )selfr r7 r r8 r9 r r r r __init__ s
zRequestField.__init___TYPE_FIELD_VALUE_TUPLE) fieldnamer r9 r c C s` t |tr4t|dkr"|\}}}q@|\}}t|}nd}d}|}| ||||d}|j|d |S )a
A :class:`~urllib3.fields.RequestField` factory from old-style tuple parameters.
Supports constructing :class:`~urllib3.fields.RequestField` from
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::
'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',
Field names and filenames must be unicode.
N)r r9 )content_type)r tuplelenr
make_multipart)clsr@ r r9 r r7 rB
request_paramr r r from_tuples s
zRequestField.from_tuplesr c C s | ||S )a
Override this method to change how each multipart header
parameter is formatted. By default, this calls
:func:`format_multipart_header_param`.
:param name:
The name of the parameter, an ASCII-only ``str``.
:param value:
The value of the parameter, a ``str`` or UTF-8 encoded
``bytes``.
:meta public:
)r9 )r= r r r r r _render_part s zRequestField._render_partz[dict[str, _TYPE_FIELD_VALUE | None] | typing.Sequence[tuple[str, _TYPE_FIELD_VALUE | None]])header_partsr c C sN g }t |tr| }n|}|D ]"\}}|dk r || || q d|S )aO
Helper function to format and quote a single header.
Useful for single headers that are composed of multiple items. E.g.,
'Content-Disposition' fields.
:param header_parts:
A sequence of (k, v) tuples or a :class:`dict` of (k, v) to format
as `k1="v1"; k2="v2"; ...`.
N; )r r<