Back to index

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

List of all members.

Public Member Functions

def __init__
def parse
def parsestr

Private Attributes

 _class

Detailed Description

Definition at line 17 of file parser.py.


Constructor & Destructor Documentation

def email.parser.Parser.__init__ (   self,
  args,
  kws 
)
Parser of RFC 2822 and MIME email messages.

Creates an in-memory object tree representing the email message, which
can then be manipulated and turned over to a Generator to return the
textual representation of the message.

The string must be formatted as a block of RFC 2822 headers and header
continuation lines, optionally preceeded by a `Unix-from' header.  The
header block is terminated either by the end of the string or by a
blank line.

_class is the class to instantiate for new message objects when they
must be created.  This class must have a constructor that can take
zero arguments.  Default is Message.Message.

Definition at line 18 of file parser.py.

00018 
00019     def __init__(self, *args, **kws):
00020         """Parser of RFC 2822 and MIME email messages.
00021 
00022         Creates an in-memory object tree representing the email message, which
00023         can then be manipulated and turned over to a Generator to return the
00024         textual representation of the message.
00025 
00026         The string must be formatted as a block of RFC 2822 headers and header
00027         continuation lines, optionally preceeded by a `Unix-from' header.  The
00028         header block is terminated either by the end of the string or by a
00029         blank line.
00030 
00031         _class is the class to instantiate for new message objects when they
00032         must be created.  This class must have a constructor that can take
00033         zero arguments.  Default is Message.Message.
00034         """
00035         if len(args) >= 1:
00036             if '_class' in kws:
00037                 raise TypeError("Multiple values for keyword arg '_class'")
00038             kws['_class'] = args[0]
00039         if len(args) == 2:
00040             if 'strict' in kws:
00041                 raise TypeError("Multiple values for keyword arg 'strict'")
00042             kws['strict'] = args[1]
00043         if len(args) > 2:
00044             raise TypeError('Too many arguments')
00045         if '_class' in kws:
00046             self._class = kws['_class']
00047             del kws['_class']
00048         else:
00049             self._class = Message
00050         if 'strict' in kws:
00051             warnings.warn("'strict' argument is deprecated (and ignored)",
00052                           DeprecationWarning, 2)
00053             del kws['strict']
00054         if kws:
00055             raise TypeError('Unexpected keyword arguments')

Here is the caller graph for this function:


Member Function Documentation

def email.parser.Parser.parse (   self,
  fp,
  headersonly = False 
)
Create a message structure from the data in a file.

Reads all the data from the file and returns the root of the message
structure.  Optional headersonly is a flag specifying whether to stop
parsing after reading the headers or not.  The default is False,
meaning it parses the entire contents of the file.

Reimplemented in email.parser.HeaderParser.

Definition at line 56 of file parser.py.

00056 
00057     def parse(self, fp, headersonly=False):
00058         """Create a message structure from the data in a file.
00059 
00060         Reads all the data from the file and returns the root of the message
00061         structure.  Optional headersonly is a flag specifying whether to stop
00062         parsing after reading the headers or not.  The default is False,
00063         meaning it parses the entire contents of the file.
00064         """
00065         feedparser = FeedParser(self._class)
00066         if headersonly:
00067             feedparser._set_headersonly()
00068         while True:
00069             data = fp.read(8192)
00070             if not data:
00071                 break
00072             feedparser.feed(data)
00073         return feedparser.close()

Here is the caller graph for this function:

def email.parser.Parser.parsestr (   self,
  text,
  headersonly = False 
)
Create a message structure from a string.

Returns the root of the message structure.  Optional headersonly is a
flag specifying whether to stop parsing after reading the headers or
not.  The default is False, meaning it parses the entire contents of
the file.

Reimplemented in email.parser.HeaderParser.

Definition at line 74 of file parser.py.

00074 
00075     def parsestr(self, text, headersonly=False):
00076         """Create a message structure from a string.
00077 
00078         Returns the root of the message structure.  Optional headersonly is a
00079         flag specifying whether to stop parsing after reading the headers or
00080         not.  The default is False, meaning it parses the entire contents of
00081         the file.
00082         """
00083         return self.parse(StringIO(text), headersonly=headersonly)
00084 
00085 


Here is the call graph for this function:


Member Data Documentation

Definition at line 45 of file parser.py.


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