zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
U
 ý°d+ã@sÆddlmZddlZddlZddlZejeefZ    eje    ej
ee    fej
ee    effZ dddddœdd„Z dd    dd
œd d „Z dd    dd
œd d„Zdd    dd
œdd„Zdd    dd
œdd„ZGdd„dƒZdS)é)Ú annotationsNúapplication/octet-streamú
str | NoneÚstr)ÚfilenameÚdefaultÚreturncCs|rt |¡dp|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)rr©r úEd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\urllib3/fields.pyÚguess_content_types r Ú_TYPE_FIELD_VALUE©ÚnameÚvaluerc    sžddl}|jdtddtˆtƒr,ˆ d¡‰t‡fdd„d    Dƒƒs~|›d
ˆ›d }z| d ¡Wntt    fk
rxYnX|St
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 <https://tools.ietf.org/html/rfc2388#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.
    rNz'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.é©Ú
stacklevelúutf-8c3s|]}|ˆkVqdS)Nr )Ú.0Úch©rr r Ú    <genexpr>@sz.format_header_param_rfc2231.<locals>.<genexpr>z"\
ú="ú"Úasciiz*=) ÚwarningsÚwarnÚDeprecationWarningÚ
isinstanceÚbytesÚdecodeÚanyÚencodeÚUnicodeEncodeErrorÚUnicodeDecodeErrorÚemailÚutilsÚencode_rfc2231)rrrÚresultr rr Úformat_header_param_rfc2231s$û
 
r+cCs6t|tƒr| d¡}| ddddœ¡}|›d|›dS)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.
    rz%0Az%0Dz%22)é
é é"rr)r r!r"Ú    translate)rrr r r Úformat_multipart_header_paramOs
 
r0cCs"ddl}|jdtddt||ƒS)ú„
    .. deprecated:: 2.0.0
        Renamed to :func:`format_multipart_header_param`. Will be
        removed in urllib3 v2.1.0.
    rNz€'format_header_param_html5' has been renamed to 'format_multipart_header_param'. The old name will be removed in urllib3 v2.1.0.rr©rrrr0©rrrr r r Úformat_header_param_html5usûr4cCs"ddl}|jdtddt||ƒS)r1rNzz'format_header_param' has been renamed to 'format_multipart_header_param'. The old name will be removed in urllib3 v2.1.0.rrr2r3r r r Úformat_header_param‡sûr5c@sˆeZdZdZdddddddœd    d
„Zeddd ddd œd d„ƒZddddœdd„Zdddœdd„Zddœdd„Z    ddddddœdd„Z
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.
    Nrrrztyping.Mapping[str, str] | Nonez5typing.Callable[[str, _TYPE_FIELD_VALUE], str] | None)rÚdatarÚheadersÚheader_formattercCsX||_||_||_i|_|r&t|ƒ|_|dk    rNddl}|jdtdd||_nt    |_dS)NrzUThe 'header_formatter' parameter is deprecated and will be removed in urllib3 v2.1.0.rr)
Ú_nameÚ    _filenamer7r8Údictrrrr9r0)Úselfrr7rr8r9rr r r Ú__init__«s
üzRequestField.__init__Ú_TYPE_FIELD_VALUE_TUPLE)Ú    fieldnamerr9rcCs†t|tƒrZt|ƒdkr6t tjtttf|¡\}}}qft tjttf|¡\}}t|ƒ}n d}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)rr9)Ú content_type)
r ÚtupleÚlenÚtypingÚcastÚTuplerrr Úmake_multipart)Úclsr@rr9rr7rBÚ request_paramr r r Ú from_tuplesÇs,
 ÿ  ÿ
ÿ zRequestField.from_tuplesrcCs | ||¡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=rrr r r Ú _render_partøszRequestField._render_partz[dict[str, _TYPE_FIELD_VALUE | None] | typing.Sequence[tuple[str, _TYPE_FIELD_VALUE | None]])Ú header_partsrcCsNg}t|tƒr| ¡}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<ÚitemsÚappendrLÚjoin)r=rMÚpartsÚiterablerrr r r Ú _render_partss
 
 zRequestField._render_parts)rcCsˆg}dddg}|D],}|j |d¡r| |›d|j|›¡q|j ¡D](\}}||krJ|rJ| |›d|›¡qJ| d¡d |¡S)z=
        Renders the headers for this request field.
        úContent-Dispositionú Content-TypeúContent-LocationFz: z
)r8ÚgetrPrOrQ)r=ÚlinesÚ    sort_keysÚsort_keyÚ header_nameÚ header_valuer r r Úrender_headers's
 
zRequestField.render_headersÚNone)Úcontent_dispositionrBÚcontent_locationrc    CsN|pdd d| d|jfd|jff¡g¡}||jd<||jd<||jd<d    S)
aó
        Makes this request field into a multipart request field.
 
        This method overrides "Content-Disposition", "Content-Type" and
        "Content-Location" headers to the request parameter.
 
        :param content_disposition:
            The 'Content-Disposition' of the request body. Defaults to 'form-data'
        :param content_type:
            The 'Content-Type' of the request body.
        :param content_location:
            The 'Content-Location' of the request body.
 
        z    form-datarNÚrrrUrVrWN)rQrTr:r;r8)r=r`rBrar r r rH:s
ÿþÿ    
 
zRequestField.make_multipart)NNN)N)NNN) Ú__name__Ú
__module__Ú __qualname__Ú__doc__r>Ú classmethodrKrLrTr^rHr r r r r6™súü0ür6)r)Ú
__future__rÚ email.utilsr'r    rEÚUnionrr!rrGr?r r+r0r4r5r6r r r r Ú<module>s"  þÿÿ0&