Back to index

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

List of all members.

Public Member Functions

def __init__
def write
def flatten
def clone

Private Member Functions

def _dispatch

Private Attributes

 _fmt

Detailed Description

Generates a text representation of a message.

Like the Generator base class, except that non-text parts are substituted
with a format string representing the part.

Definition at line 398 of file generator.py.


Constructor & Destructor Documentation

def email.generator.DecodedGenerator.__init__ (   self,
  outfp,
  mangle_from_ = True,
  maxheaderlen = 78,
  fmt = None 
)
Like Generator.__init__() except that an additional optional
argument is allowed.

Walks through all subparts of a message.  If the subpart is of main
type `text', then it prints the decoded payload of the subpart.

Otherwise, fmt is a format string that is used instead of the message
payload.  fmt is expanded with the following keywords (in
%(keyword)s format):

type       : Full MIME type of the non-text part
maintype   : Main MIME type of the non-text part
subtype    : Sub-MIME type of the non-text part
filename   : Filename of the non-text part
description: Description associated with the non-text part
encoding   : Content transfer encoding of the non-text part

The default value for fmt is None, meaning

[Non-text (%(type)s) part of message omitted, filename %(filename)s]

Definition at line 404 of file generator.py.

00404 
00405     def __init__(self, outfp, mangle_from_=True, maxheaderlen=78, fmt=None):
00406         """Like Generator.__init__() except that an additional optional
00407         argument is allowed.
00408 
00409         Walks through all subparts of a message.  If the subpart is of main
00410         type `text', then it prints the decoded payload of the subpart.
00411 
00412         Otherwise, fmt is a format string that is used instead of the message
00413         payload.  fmt is expanded with the following keywords (in
00414         %(keyword)s format):
00415 
00416         type       : Full MIME type of the non-text part
00417         maintype   : Main MIME type of the non-text part
00418         subtype    : Sub-MIME type of the non-text part
00419         filename   : Filename of the non-text part
00420         description: Description associated with the non-text part
00421         encoding   : Content transfer encoding of the non-text part
00422 
00423         The default value for fmt is None, meaning
00424 
00425         [Non-text (%(type)s) part of message omitted, filename %(filename)s]
00426         """
00427         Generator.__init__(self, outfp, mangle_from_, maxheaderlen)
00428         if fmt is None:
00429             self._fmt = _FMT
00430         else:
00431             self._fmt = fmt

Here is the caller graph for this function:


Member Function Documentation

def email.generator.DecodedGenerator._dispatch (   self,
  msg 
) [private]

Reimplemented from email.generator.Generator.

Definition at line 432 of file generator.py.

00432 
00433     def _dispatch(self, msg):
00434         for part in msg.walk():
00435             maintype = part.get_content_maintype()
00436             if maintype == 'text':
00437                 print(part.get_payload(decode=False), file=self)
00438             elif maintype == 'multipart':
00439                 # Just skip this
00440                 pass
00441             else:
00442                 print(self._fmt % {
00443                     'type'       : part.get_content_type(),
00444                     'maintype'   : part.get_content_maintype(),
00445                     'subtype'    : part.get_content_subtype(),
00446                     'filename'   : part.get_filename('[no filename]'),
00447                     'description': part.get('Content-Description',
00448                                             '[no description]'),
00449                     'encoding'   : part.get('Content-Transfer-Encoding',
00450                                             '[no encoding]'),
00451                     }, file=self)
00452 
00453 
00454 
# Helper used by Generator._make_boundary

Here is the caller 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.Generator.write (   self,
  s 
) [inherited]

Reimplemented in email.generator.BytesGenerator.

Definition at line 57 of file generator.py.

00057 
00058     def write(self, s):
00059         # Just delegate to the file object
00060         self._fp.write(s)


Member Data Documentation

Definition at line 428 of file generator.py.


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