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

Method fold

Lib/email/headerregistry.py:225–251  ·  view source on GitHub ↗

Fold header according to policy. The parsed representation of the header is folded according to RFC5322 rules, as modified by the policy. If the parse tree contains surrogateescaped bytes, the bytes are CTE encoded using the charset 'unknown-8bit". Any non-

(self, *, policy)

Source from the content-addressed store, hash-verified

223 return str.__new__(cls, value)
224
225 def fold(self, *, policy):
226 """Fold header according to policy.
227
228 The parsed representation of the header is folded according to
229 RFC5322 rules, as modified by the policy. If the parse tree
230 contains surrogateescaped bytes, the bytes are CTE encoded using
231 the charset 'unknown-8bit".
232
233 Any non-ASCII characters in the parse tree are CTE encoded using
234 charset utf-8. XXX: make this a policy setting.
235
236 The returned value is an ASCII-only string possibly containing linesep
237 characters, and ending with a linesep character. The string includes
238 the header name and the ': ' separator.
239
240 """
241 # At some point we need to put fws here if it was in the source.
242 header = parser.Header([
243 parser.HeaderLabel([
244 parser.ValueTerminal(self.name, 'header-name'),
245 parser.ValueTerminal(':', 'header-sep')]),
246 ])
247 if self._parse_tree:
248 header.append(
249 parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')]))
250 header.append(self._parse_tree)
251 return header.fold(policy=policy)
252
253
254def _reconstruct_header(cls_name, bases, value):

Callers

nothing calls this directly

Calls 1

appendMethod · 0.95

Tested by

no test coverage detected