[Python-checkins] python/dist/src/Lib/email Generator.py,1.18,1.19

bwarsaw@users.sourceforge.net bwarsaw@users.sourceforge.net
Fri, 07 Mar 2003 07:43:23 -0800


Update of /cvsroot/python/python/dist/src/Lib/email
In directory sc8-pr-cvs1:/tmp/cvs-serv17098

Modified Files:
	Generator.py 
Log Message:
_write_headers(), _split_header(): All of the smarts for splitting
long header lines is now (properly) in the Header class.  So we no
longer need _split_header() and we'll just defer to Header.encode()
when we have a plain string.


Index: Generator.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/email/Generator.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** Generator.py	6 Mar 2003 05:22:02 -0000	1.18
--- Generator.py	7 Mar 2003 15:43:17 -0000	1.19
***************
*** 162,202 ****
      def _write_headers(self, msg):
          for h, v in msg.items():
!             # RFC 2822 says that lines SHOULD be no more than maxheaderlen
!             # characters wide, so we're well within our rights to split long
!             # headers.
!             text = '%s: %s' % (h, v)
!             if self.__maxheaderlen > 0 and len(text) > self.__maxheaderlen:
!                 text = self._split_header(text)
!             print >> self._fp, text
          # A blank line always separates headers from body
          print >> self._fp
- 
-     def _split_header(self, text):
-         maxheaderlen = self.__maxheaderlen
-         # Find out whether any lines in the header are really longer than
-         # maxheaderlen characters wide.  There could be continuation lines
-         # that actually shorten it.  Also, replace hard tabs with 8 spaces.
-         lines = [s.replace('\t', SPACE8) for s in text.splitlines()]
-         for line in lines:
-             if len(line) > maxheaderlen:
-                 break
-         else:
-             # No line was actually longer than maxheaderlen characters, so
-             # just return the original unchanged.
-             return text
-         # If we have raw 8bit data in a byte string, we have no idea what the
-         # encoding is.  I think there is no safe way to split this string.  If
-         # it's ascii-subset, then we could do a normal ascii split, but if
-         # it's multibyte then we could break the string.  There's no way to
-         # know so the least harm seems to be to not split the string and risk
-         # it being too long.
-         if _is8bitstring(text):
-             return text
-         # The `text' argument already has the field name prepended, so don't
-         # provide it here or the first line will get folded too short.
-         h = Header(text, maxlinelen=maxheaderlen,
-                    # For backwards compatibility, we use a hard tab here
-                    continuation_ws='\t')
-         return h.encode()
  
      #
--- 162,187 ----
      def _write_headers(self, msg):
          for h, v in msg.items():
!             print >> self._fp, '%s:' % h,
!             if self.__maxheaderlen == 0:
!                 # Explicit no-wrapping
!                 print >> self._fp, v
!             elif isinstance(v, Header):
!                 # Header instances know what to do
!                 print >> self._fp, v.encode()
!             elif _is8bitstring(v):
!                 # If we have raw 8bit data in a byte string, we have no idea
!                 # what the encoding is.  There is no safe way to split this
!                 # string.  If it's ascii-subset, then we could do a normal
!                 # ascii split, but if it's multibyte then we could break the
!                 # string.  There's no way to know so the least harm seems to
!                 # be to not split the string and risk it being too long.
!                 print >> self._fp, v
!             else:
!                 # Header's got lots of smarts, so use it.
!                 print >> self._fp, Header(
!                     v, maxlinelen=self.__maxheaderlen,
!                     header_name=h, continuation_ws='\t').encode()
          # A blank line always separates headers from body
          print >> self._fp
  
      #