MCPcopy Index your code
hub / github.com/RustPython/RustPython / _fold

Method _fold

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

Source from the content-addressed store, hash-verified

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

Callers 2

foldMethod · 0.95
fold_binaryMethod · 0.95

Calls 5

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

Tested by

no test coverage detected