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

Method _fold

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

Source from the content-addressed store, hash-verified

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

Callers 2

foldMethod · 0.95
fold_binaryMethod · 0.95

Calls 8

_has_surrogatesFunction · 0.90
hasattrFunction · 0.85
lenFunction · 0.85
anyFunction · 0.50
foldMethod · 0.45
splitMethod · 0.45
isasciiMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected