MCPcopy Index your code
hub / github.com/python/cpython / _fold

Method _fold

Lib/email/_policybase.py:358–389  ·  view source on GitHub ↗
(self, name, value, sanitize)

Source from the content-addressed store, hash-verified

356 return folded.encode('ascii', 'surrogateescape')
357
358 def _fold(self, name, value, sanitize):
359 parts = []
360 parts.append('%s: ' % name)
361 if isinstance(value, str):
362 if _has_surrogates(value):
363 if sanitize:
364 h = header.Header(value,
365 charset=_charset.UNKNOWN8BIT,
366 header_name=name)
367 else:
368 # If we have raw 8bit data in a byte string, we have no idea
369 # what the encoding is. There is no safe way to split this
370 # string. If it's ascii-subset, then we could do a normal
371 # ascii split, but if it's multibyte then we could break the
372 # string. There's no way to know so the least harm seems to
373 # be to not split the string and risk it being too long.
374 parts.append(value)
375 h = None
376 else:
377 h = header.Header(value, header_name=name)
378 else:
379 # Assume it is a Header-like object.
380 h = value
381 if h is not None:
382 # The Header class interprets a value of None for maxlinelen as the
383 # default value of 78, as recommended by RFC 5322 section 2.1.1.
384 maxlinelen = 0
385 if self.max_line_length is not None:
386 maxlinelen = self.max_line_length
387 parts.append(h.encode(linesep=self.linesep, maxlinelen=maxlinelen))
388 parts.append(self.linesep)
389 return ''.join(parts)
390
391
392compat32 = 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