MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / append

Method append

tools/python-3.11.9-amd64/Lib/email/header.py:261–302  ·  view source on GitHub ↗

Append a string to the MIME header. Optional charset, if given, should be a Charset instance or the name of a character set (which will be converted to a Charset instance). A value of None (the default) means that the charset given in the constructor is used.

(self, s, charset=None, errors='strict')

Source from the content-addressed store, hash-verified

259 return other == str(self)
260
261 def append(self, s, charset=None, errors='strict'):
262 """Append a string to the MIME header.
263
264 Optional charset, if given, should be a Charset instance or the name
265 of a character set (which will be converted to a Charset instance). A
266 value of None (the default) means that the charset given in the
267 constructor is used.
268
269 s may be a byte string or a Unicode string. If it is a byte string
270 (i.e. isinstance(s, str) is false), then charset is the encoding of
271 that byte string, and a UnicodeError will be raised if the string
272 cannot be decoded with that charset. If s is a Unicode string, then
273 charset is a hint specifying the character set of the characters in
274 the string. In either case, when producing an RFC 2822 compliant
275 header using RFC 2047 rules, the string will be encoded using the
276 output codec of the charset. If the string cannot be encoded to the
277 output codec, a UnicodeError will be raised.
278
279 Optional `errors' is passed as the errors argument to the decode
280 call if s is a byte string.
281 """
282 if charset is None:
283 charset = self._charset
284 elif not isinstance(charset, Charset):
285 charset = Charset(charset)
286 if not isinstance(s, str):
287 input_charset = charset.input_codec or 'us-ascii'
288 if input_charset == _charset.UNKNOWN8BIT:
289 s = s.decode('us-ascii', 'surrogateescape')
290 else:
291 s = s.decode(input_charset, errors)
292 # Ensure that the bytes we're storing can be decoded to the output
293 # character set, otherwise an early error is raised.
294 output_charset = charset.output_codec or 'us-ascii'
295 if output_charset != _charset.UNKNOWN8BIT:
296 try:
297 s.encode(output_charset, errors)
298 except UnicodeEncodeError:
299 if output_charset!='us-ascii':
300 raise
301 charset = UTF8
302 self._chunks.append((s, charset))
303
304 def _nonctext(self, s):
305 """True if string s is not a ctext character of RFC822.

Callers 15

foldMethod · 0.95
make_headerFunction · 0.95
__init__Method · 0.95
__init__Method · 0.45
subwidgets_allMethod · 0.45
pagesMethod · 0.45
pagesMethod · 0.45
filter_commandMethod · 0.45
askopenfilesFunction · 0.45
__repr__Method · 0.45
_registerMethod · 0.45
winfo_childrenMethod · 0.45

Calls 3

CharsetClass · 0.85
decodeMethod · 0.45
encodeMethod · 0.45

Tested by 15

test_unique_variablesMethod · 0.36
callbackMethod · 0.36
test1Method · 0.36
test2Method · 0.36
test3Method · 0.36
testMethod · 0.36
read_tracerMethod · 0.36
write_tracerMethod · 0.36
test_invokeMethod · 0.36
cb_testMethod · 0.36
test_unique_variablesMethod · 0.36