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

Method __str__

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

Return the string value of the header.

(self)

Source from the content-addressed store, hash-verified

221 self._headerlen = len(header_name) + 2
222
223 def __str__(self):
224 """Return the string value of the header."""
225 self._normalize()
226 uchunks = []
227 lastcs = None
228 lastspace = None
229 for string, charset in self._chunks:
230 # We must preserve spaces between encoded and non-encoded word
231 # boundaries, which means for us we need to add a space when we go
232 # from a charset to None/us-ascii, or from None/us-ascii to a
233 # charset. Only do this for the second and subsequent chunks.
234 # Don't add a space if the None/us-ascii string already has
235 # a space (trailing or leading depending on transition)
236 nextcs = charset
237 if nextcs == _charset.UNKNOWN8BIT:
238 original_bytes = string.encode('ascii', 'surrogateescape')
239 string = original_bytes.decode('ascii', 'replace')
240 if uchunks:
241 hasspace = string and self._nonctext(string[0])
242 if lastcs not in (None, 'us-ascii'):
243 if nextcs in (None, 'us-ascii') and not hasspace:
244 uchunks.append(SPACE)
245 nextcs = None
246 elif nextcs not in (None, 'us-ascii') and not lastspace:
247 uchunks.append(SPACE)
248 lastspace = string and self._nonctext(string[-1])
249 lastcs = nextcs
250 uchunks.append(string)
251 return EMPTYSTRING.join(uchunks)
252
253 # Rich comparison operators for equality only. BAW: does it make sense to
254 # have or explicitly disable <, <=, >, >= operators?

Callers

nothing calls this directly

Calls 6

_normalizeMethod · 0.95
_nonctextMethod · 0.95
encodeMethod · 0.45
decodeMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected