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

Method feed

Lib/email/header.py:447–482  ·  view source on GitHub ↗
(self, fws, string, charset)

Source from the content-addressed store, hash-verified

445 self._current_line.push(' ', '')
446
447 def feed(self, fws, string, charset):
448 # If the charset has no header encoding (i.e. it is an ASCII encoding)
449 # then we must split the header at the "highest level syntactic break"
450 # possible. Note that we don't have a lot of smarts about field
451 # syntax; we just try to break on semi-colons, then commas, then
452 # whitespace. Eventually, this should be pluggable.
453 if charset.header_encoding is None:
454 self._ascii_split(fws, string, self._splitchars)
455 return
456 # Otherwise, we're doing either a Base64 or a quoted-printable
457 # encoding which means we don't need to split the line on syntactic
458 # breaks. We can basically just find enough characters to fit on the
459 # current line, minus the RFC 2047 chrome. What makes this trickier
460 # though is that we have to split at octet boundaries, not character
461 # boundaries but it's only safe to split at character boundaries so at
462 # best we can only get close.
463 encoded_lines = charset.header_encode_lines(string, self._maxlengths())
464 # The first element extends the current line, but if it's None then
465 # nothing more fit on the current line so start a new line.
466 try:
467 first_line = encoded_lines.pop(0)
468 except IndexError:
469 # There are no encoded lines, so we're done.
470 return
471 if first_line is not None:
472 self._append_chunk(fws, first_line)
473 try:
474 last_line = encoded_lines.pop()
475 except IndexError:
476 # There was only one line.
477 return
478 self.newline()
479 self._current_line.push(self._continuation_ws, last_line)
480 # Everything else are full lines in themselves.
481 for line in encoded_lines:
482 self._lines.append(self._continuation_ws + line)
483
484 def _maxlengths(self):
485 # The first line's length.

Callers 1

encodeMethod · 0.45

Calls 8

_ascii_splitMethod · 0.95
_maxlengthsMethod · 0.95
_append_chunkMethod · 0.95
newlineMethod · 0.95
header_encode_linesMethod · 0.80
popMethod · 0.45
pushMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected