Lines Matching refs:charset
10 # =?charset[*lang]?cte?encoded_string?=
12 # for more information about charset see the charset module. Here it is one
13 # of the preferred MIME charset names (hopefully; you never know when parsing).
26 # problems encountered during conversion. 'charset' and 'lang' are the
153 """Decode encoded word and return (string, charset, lang, defects) tuple.
157 =?charset*lang?cte?encoded_string?=
164 then from the resulting bytes into unicode using the specified charset. If
169 The specified charset and language are returned. The default for language,
173 _, charset, cte, cte_string, _ = ew.split('?')
174 charset, _, lang = charset.partition('*')
181 string = bstring.decode(charset)
184 f"contains bytes not decodable using {charset!r} charset"))
185 string = bstring.decode(charset, 'surrogateescape')
188 if charset.lower() != 'unknown-8bit':
189 defects.append(errors.CharsetError(f"Unknown charset {charset!r} "
191 return string, charset, lang, defects
204 def encode(string, charset='utf-8', encoding=None, lang=''):
209 =?charset*lang?cte?encoded_string?=
212 Optional argument charset (defaults to utf-8) specifies the charset to use
221 if charset == 'unknown-8bit':
224 bstring = string.encode(charset)
233 return "=?{}{}?{}?{}?=".format(charset, lang, encoding, encoded)