示例#1
0
    def fold(self, *, policy):
        """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-ASCII characters in the parse tree are CTE encoded using
        charset utf-8. XXX: make this a policy setting.

        The returned value is an ASCII-only string possibly containing linesep
        characters, and ending with a linesep character.  The string includes
        the header name and the ': ' separator.

        """
        # At some point we need to put fws here if it was in the source.
        header = parser.Header([
            parser.HeaderLabel([
                parser.ValueTerminal(self.name, 'header-name'),
                parser.ValueTerminal(':', 'header-sep')
            ]),
        ])
        if self._parse_tree:
            header.append(
                parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')]))
        header.append(self._parse_tree)
        return header.fold(policy=policy)
示例#2
0
 def fold(self, *, policy):
     header = parser.Header([
         parser.HeaderLabel([
             parser.ValueTerminal(self.name, 'header-name'),
             parser.ValueTerminal(':', 'header-sep')
         ]),
         parser.CFWSList([parser.WhiteSpaceTerminal(' ', 'fws')]),
         self._parse_tree
     ])
     return header.fold(policy=policy)