Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Static Private Attributes
email.generator.BytesGenerator Class Reference
Inheritance diagram for email.generator.BytesGenerator:
Inheritance graph
[legend]
Collaboration diagram for email.generator.BytesGenerator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def write
def flatten
def clone

Private Member Functions

def _new_buffer
def _encode
def _write_headers
def _handle_text
def _compile_re

Static Private Attributes

string _encoded_EMPTY = ''

Detailed Description

Generates a bytes version of a Message object tree.

Functionally identical to the base Generator except that the output is
bytes and not string.  When surrogates were used in the input to encode
bytes, these are decoded back to bytes for output.

The outfp object must accept bytes in its write method.

Definition at line 334 of file generator.py.


Member Function Documentation

def email.generator.BytesGenerator._compile_re (   cls,
  s,
  flags 
) [private]

Reimplemented from email.generator.Generator.

Definition at line 391 of file generator.py.

00391 
00392     def _compile_re(cls, s, flags):
00393         return re.compile(s.encode('ascii'), flags)
00394 
00395 


Here is the call graph for this function:

def email.generator.BytesGenerator._encode (   self,
  s 
) [private]

Reimplemented from email.generator.Generator.

Definition at line 354 of file generator.py.

00354 
00355     def _encode(self, s):
00356         return s.encode('ascii')

def email.generator.BytesGenerator._handle_text (   self,
  msg 
) [private]

Reimplemented from email.generator.Generator.

Definition at line 380 of file generator.py.

00380 
00381     def _handle_text(self, msg):
00382         # If the string has surrogates the original source was bytes, so
00383         # just write it back out.
00384         if msg._payload is None:
00385             return
00386         if _has_surrogates(msg._payload):
00387             self.write(msg._payload)
00388         else:
00389             super(BytesGenerator,self)._handle_text(msg)

Here is the call graph for this function:

Reimplemented from email.generator.Generator.

Definition at line 351 of file generator.py.

00351 
00352     def _new_buffer(self):
00353         return BytesIO()

def email.generator.BytesGenerator._write_headers (   self,
  msg 
) [private]

Reimplemented from email.generator.Generator.

Definition at line 357 of file generator.py.

00357 
00358     def _write_headers(self, msg):
00359         # This is almost the same as the string version, except for handling
00360         # strings with 8bit bytes.
00361         for h, v in msg._headers:
00362             self.write('%s: ' % h)
00363             if isinstance(v, Header):
00364                 self.write(v.encode(maxlinelen=self._maxheaderlen)+NL)
00365             elif _has_surrogates(v):
00366                 # If we have raw 8bit data in a byte string, we have no idea
00367                 # what the encoding is.  There is no safe way to split this
00368                 # string.  If it's ascii-subset, then we could do a normal
00369                 # ascii split, but if it's multibyte then we could break the
00370                 # string.  There's no way to know so the least harm seems to
00371                 # be to not split the string and risk it being too long.
00372                 self.write(v+NL)
00373             else:
00374                 # Header's got lots of smarts and this string is safe...
00375                 header = Header(v, maxlinelen=self._maxheaderlen,
00376                                 header_name=h)
00377                 self.write(header.encode(linesep=self._NL)+self._NL)
00378         # A blank line always separates headers from body
00379         self.write(self._NL)

Here is the call graph for this function:

def email.generator.Generator.clone (   self,
  fp 
) [inherited]
Clone this generator with the exact same options.

Definition at line 93 of file generator.py.

00093 
00094     def clone(self, fp):
00095         """Clone this generator with the exact same options."""
00096         return self.__class__(fp, self._mangle_from_, self._maxheaderlen)

Here is the caller graph for this function:

def email.generator.Generator.flatten (   self,
  msg,
  unixfrom = False,
  linesep = '\n' 
) [inherited]

Definition at line 61 of file generator.py.

00061 
00062     def flatten(self, msg, unixfrom=False, linesep='\n'):
00063         r"""Print the message object tree rooted at msg to the output file
00064         specified when the Generator instance was created.
00065 
00066         unixfrom is a flag that forces the printing of a Unix From_ delimiter
00067         before the first object in the message tree.  If the original message
00068         has no From_ delimiter, a `standard' one is crafted.  By default, this
00069         is False to inhibit the printing of any From_ delimiter.
00070 
00071         Note that for subobjects, no From_ line is printed.
00072 
00073         linesep specifies the characters used to indicate a new line in
00074         the output.  The default value is the most useful for typical
00075         Python applications, but it can be set to \r\n to produce RFC-compliant
00076         line separators when needed.
00077 
00078         """
00079         # We use the _XXX constants for operating on data that comes directly
00080         # from the msg, and _encoded_XXX constants for operating on data that
00081         # has already been converted (to bytes in the BytesGenerator) and
00082         # inserted into a temporary buffer.
00083         self._NL = linesep
00084         self._encoded_NL = self._encode(linesep)
00085         self._EMPTY = ''
00086         self._encoded_EMTPY = self._encode('')
00087         if unixfrom:
00088             ufrom = msg.get_unixfrom()
00089             if not ufrom:
00090                 ufrom = 'From nobody ' + time.ctime(time.time())
00091             self.write(ufrom + self._NL)
00092         self._write(msg)

def email.generator.BytesGenerator.write (   self,
  s 
)

Reimplemented from email.generator.Generator.

Definition at line 348 of file generator.py.

00348 
00349     def write(self, s):
00350         self._fp.write(s.encode('ascii', 'surrogateescape'))


Member Data Documentation

Reimplemented from email.generator.Generator.

Definition at line 346 of file generator.py.


The documentation for this class was generated from the following file: