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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
U
I=®dS)ã@sædZddlmZddlZddlmZdZddd    d
d œZiZd d „Z    dd„Z
dd„Z Gdd„de ƒZ e
dƒZe
dƒZe
dƒZd+dd„Zdd„Zedfdd„Zd,dd „Zd!d"„Zedfd#d$„Zd%d&„ZGd'd(„d(e ƒZGd)d*„d*e ƒZdS)-a
 
    webencodings
    ~~~~~~~~~~~~
 
    This is a Python implementation of the `WHATWG Encoding standard
    <http://encoding.spec.whatwg.org/>`. See README for details.
 
    :copyright: Copyright 2012 by Simon Sapin
    :license: BSD, see LICENSE for details.
 
é)Úunicode_literalsNé)ÚLABELSz0.5.1z
iso-8859-8z mac-cyrillicz    mac-romanÚcp874)z iso-8859-8-izx-mac-cyrillicÚ    macintoshz windows-874cCs| d¡ ¡ d¡S)a9Transform (only) ASCII letters to lower case: A-Z is mapped to a-z.
 
    :param string: An Unicode string.
    :returns: A new Unicode string.
 
    This is used for `ASCII case-insensitive
    <http://encoding.spec.whatwg.org/#ascii-case-insensitive>`_
    matching of encoding labels.
    The same matching is also used, among other things,
    for `CSS keywords <http://dev.w3.org/csswg/css-values/#keywords>`_.
 
    This is different from the :meth:`~py:str.lower` method of Unicode strings
    which also affect non-ASCII characters,
    sometimes mapping them into the ASCII range:
 
        >>> keyword = u'Bac\N{KELVIN SIGN}ground'
        >>> assert keyword.lower() == u'background'
        >>> assert ascii_lower(keyword) != keyword.lower()
        >>> assert ascii_lower(keyword) == u'bac\N{KELVIN SIGN}ground'
 
    Úutf8)ÚencodeÚlowerÚdecode)Ústring©r úXD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_vendor/webencodings/__init__.pyÚ ascii_lower#srcCsxt| d¡ƒ}t |¡}|dkr$dSt |¡}|dkrt|dkrLddlm}nt ||¡}t     |¡}t
||ƒ}|t|<|S)u<
    Look for an encoding by its label.
    This is the spec’s `get an encoding
    <http://encoding.spec.whatwg.org/#concept-encoding-get>`_ algorithm.
    Supported labels are listed there.
 
    :param label: A string.
    :returns:
        An :class:`Encoding` object, or :obj:`None` for an unknown label.
 
    z    
 Nzx-user-definedr)Ú
codec_info) rÚstriprÚgetÚCACHEÚx_user_definedrÚ PYTHON_NAMESÚcodecsÚlookupÚEncoding)ÚlabelÚnameÚencodingrÚ python_namer r r r=s 
 
 
 
rcCs.t|dƒr|St|ƒ}|dkr*td|ƒ‚|S)zç
    Accept either an encoding object or label.
 
    :param encoding: An :class:`Encoding` object or a label string.
    :returns: An :class:`Encoding` object.
    :raises: :exc:`~exceptions.LookupError` for an unknown label.
 
    rNzUnknown encoding label: %r)ÚhasattrrÚ LookupError)Úencoding_or_labelrr r r Ú _get_encoding[s     
 rc@s eZdZdZdd„Zdd„ZdS)raOReresents a character encoding such as UTF-8,
    that can be used for decoding or encoding.
 
    .. attribute:: name
 
        Canonical name of the encoding
 
    .. attribute:: codec_info
 
        The actual implementation of the encoding,
        a stdlib :class:`~codecs.CodecInfo` object.
        See :func:`codecs.register`.
 
    cCs||_||_dS©N)rr)Úselfrrr r r Ú__init__|szEncoding.__init__cCs
d|jS)Nz <Encoding %s>)r)r!r r r Ú__repr__€szEncoding.__repr__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r"r#r r r r rmsrzutf-8zutf-16lezutf-16beÚreplacecCs2t|ƒ}t|ƒ\}}|p|}|j ||¡d|fS)aÖ
    Decode a single string.
 
    :param input: A byte string
    :param fallback_encoding:
        An :class:`Encoding` object or a label string.
        The encoding to use if :obj:`input` does note have a BOM.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :return:
        A ``(output, encoding)`` tuple of an Unicode string
        and an :obj:`Encoding`.
 
    r)rÚ _detect_bomrr
)ÚinputÚfallback_encodingÚerrorsÚ bom_encodingrr r r r
‹s r
cCsV| d¡rt|dd…fS| d¡r4t|dd…fS| d¡rNt|dd…fSd|fS)zBReturn (bom_encoding, input), with any BOM removed from the input.sÿþéNsþÿsé)Ú
startswithÚ_UTF16LEÚ_UTF16BEÚUTF8)r*r r r r)¡s
 
 
r)ÚstrictcCst|ƒj ||¡dS)a;
    Encode a single string.
 
    :param input: An Unicode string.
    :param encoding: An :class:`Encoding` object or a label string.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :return: A byte string.
 
    r)rrr)r*rr,r r r r¬s rcCs$t||ƒ}t||ƒ}t|ƒ}||fS)aâ
    "Pull"-based decoder.
 
    :param input:
        An iterable of byte strings.
 
        The input is first consumed just enough to determine the encoding
        based on the precense of a BOM,
        then consumed on demand when the return value is.
    :param fallback_encoding:
        An :class:`Encoding` object or a label string.
        The encoding to use if :obj:`input` does note have a BOM.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :returns:
        An ``(output, encoding)`` tuple.
        :obj:`output` is an iterable of Unicode strings,
        :obj:`encoding` is the :obj:`Encoding` that is being used.
 
    )ÚIncrementalDecoderÚ_iter_decode_generatorÚnext)r*r+r,ÚdecoderÚ    generatorrr r r Ú iter_decodeºs
 
r:ccsª|j}t|ƒ}|D]0}||ƒ}|r|jdk    s0t‚|jV|Vqtq|ddd}|jdk    s^t‚|jV|rp|VdS|D]}||ƒ}|rx|Vqx|ddd}|r¦|VdS)zqReturn a generator that first yields the :obj:`Encoding`,
    then yields output chukns as Unicode strings.
 
    NóT©Úfinal)r
ÚiterrÚAssertionError)r*r8r
ÚchunckÚoutputr r r r6Ös,  r6cCst||ƒj}t||ƒS)uY
    â€œPull”-based encoder.
 
    :param input: An iterable of Unicode strings.
    :param encoding: An :class:`Encoding` object or a label string.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
    :returns: An iterable of byte strings.
 
    )ÚIncrementalEncoderrÚ_iter_encode_generator)r*rr,rr r r Ú iter_encodeös rDccs6|D]}||ƒ}|r|Vq|ddd}|r2|VdS)NÚTr<r )r*rr@rAr r r rCs rCc@s$eZdZdZd    dd„Zd
dd„ZdS) r5uO
    â€œPush”-based decoder.
 
    :param fallback_encoding:
        An :class:`Encoding` object or a label string.
        The encoding to use if :obj:`input` does note have a BOM.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
 
    r(cCs&t|ƒ|_||_d|_d|_d|_dS)Nr;)rÚ_fallback_encodingÚ_errorsÚ_bufferÚ_decoderr)r!r+r,r r r r"s
 
zIncrementalDecoder.__init__FcCs||j}|dk    r|||ƒS|j|}t|ƒ\}}|dkrVt|ƒdkrP|sP||_dS|j}|j |j¡j}||_||_    |||ƒS)zùDecode one chunk of the input.
 
        :param input: A byte string.
        :param final:
            Indicate that no more input is available.
            Must be :obj:`True` if this is the last call.
        :returns: An Unicode string.
 
        Nr/rE)
rIrHr)ÚlenrFrÚincrementaldecoderrGr
r)r!r*r=r8rr r r r
's
 
 
 zIncrementalDecoder.decodeN)r()F)r$r%r&r'r"r
r r r r r5s
 
r5c@seZdZdZedfdd„ZdS)rBuù
    â€œPush”-based encoder.
 
    :param encoding: An :class:`Encoding` object or a label string.
    :param errors: Type of error handling. See :func:`codecs.register`.
    :raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
 
    .. method:: encode(input, final=False)
 
        :param input: An Unicode string.
        :param final:
            Indicate that no more input is available.
            Must be :obj:`True` if this is the last call.
        :returns: A byte string.
 
    r4cCst|ƒ}|j |¡j|_dSr )rrÚincrementalencoderr)r!rr,r r r r"TszIncrementalEncoder.__init__N)r$r%r&r'r3r"r r r r rBCsrB)r()r()r'Ú
__future__rrÚlabelsrÚVERSIONrrrrrÚobjectrr3r1r2r
r)rr:r6rDrCr5rBr r r r Ú<module>s4  ü
 
 
3