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

Method _fold

Lib/email/policy.py:211–230  ·  view source on GitHub ↗
(self, name, value, refold_binary=False)

Source from the content-addressed store, hash-verified

209 return folded.encode(charset, 'surrogateescape')
210
211 def _fold(self, name, value, refold_binary=False):
212 if hasattr(value, 'name'):
213 return value.fold(policy=self)
214 maxlen = self.max_line_length if self.max_line_length else sys.maxsize
215 # We can't use splitlines here because it splits on more than \r and \n.
216 lines = linesep_splitter.split(value)
217 refold = (self.refold_source == 'all' or
218 self.refold_source == 'long' and
219 (lines and len(lines[0])+len(name)+2 > maxlen or
220 any(len(x) > maxlen for x in lines[1:])))
221
222 if not refold:
223 if not self.utf8:
224 refold = not value.isascii()
225 elif refold_binary:
226 refold = _has_surrogates(value)
227 if refold:
228 return self.header_factory(name, ''.join(lines)).fold(policy=self)
229
230 return name + ': ' + self.linesep.join(lines) + self.linesep
231
232
233default = EmailPolicy()

Callers 2

foldMethod · 0.95
fold_binaryMethod · 0.95

Calls 6

_has_surrogatesFunction · 0.90
isasciiMethod · 0.80
anyFunction · 0.50
foldMethod · 0.45
splitMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected