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

Method _fold

tools/python-3.11.9-amd64/Lib/email/_policybase.py:340–371  ·  view source on GitHub ↗
(self, name, value, sanitize)

Source from the content-addressed store, hash-verified

338 return folded.encode('ascii', 'surrogateescape')
339
340 def _fold(self, name, value, sanitize):
341 parts = []
342 parts.append('%s: ' % name)
343 if isinstance(value, str):
344 if _has_surrogates(value):
345 if sanitize:
346 h = header.Header(value,
347 charset=_charset.UNKNOWN8BIT,
348 header_name=name)
349 else:
350 # If we have raw 8bit data in a byte string, we have no idea
351 # what the encoding is. There is no safe way to split this
352 # string. If it's ascii-subset, then we could do a normal
353 # ascii split, but if it's multibyte then we could break the
354 # string. There's no way to know so the least harm seems to
355 # be to not split the string and risk it being too long.
356 parts.append(value)
357 h = None
358 else:
359 h = header.Header(value, header_name=name)
360 else:
361 # Assume it is a Header-like object.
362 h = value
363 if h is not None:
364 # The Header class interprets a value of None for maxlinelen as the
365 # default value of 78, as recommended by RFC 2822.
366 maxlinelen = 0
367 if self.max_line_length is not None:
368 maxlinelen = self.max_line_length
369 parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
370 parts.append(self.linesep)
371 return ''.join(parts)
372
373
374compat32 = Compat32()

Callers 2

foldMethod · 0.95
fold_binaryMethod · 0.95

Calls 4

encodeMethod · 0.95
_has_surrogatesFunction · 0.90
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected