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

Method _ascii_split

Lib/email/header.py:490–510  ·  view source on GitHub ↗
(self, fws, string, splitchars)

Source from the content-addressed store, hash-verified

488 yield self._maxlen - self._continuation_ws_len
489
490 def _ascii_split(self, fws, string, splitchars):
491 # The RFC 2822 header folding algorithm is simple in principle but
492 # complex in practice. Lines may be folded any place where "folding
493 # white space" appears by inserting a linesep character in front of the
494 # FWS. The complication is that not all spaces or tabs qualify as FWS,
495 # and we are also supposed to prefer to break at "higher level
496 # syntactic breaks". We can't do either of these without intimate
497 # knowledge of the structure of structured headers, which we don't have
498 # here. So the best we can do here is prefer to break at the specified
499 # splitchars, and hope that we don't choose any spaces or tabs that
500 # aren't legal FWS. (This is at least better than the old algorithm,
501 # where we would sometimes *introduce* FWS after a splitchar, or the
502 # algorithm before that, where we would turn all white space runs into
503 # single spaces or tabs.)
504 parts = re.split("(["+FWS+"]+)", fws+string)
505 if parts[0]:
506 parts[:0] = ['']
507 else:
508 parts.pop(0)
509 for fws, part in zip(*[iter(parts)]*2):
510 self._append_chunk(fws, part)
511
512 def _append_chunk(self, fws, string):
513 self._current_line.push(fws, string)

Callers 1

feedMethod · 0.95

Calls 3

_append_chunkMethod · 0.95
splitMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected