Beispiel #1
0
 def __init__(self, message=None):
     """Initialize a Message instance."""
     feedparser = FeedParser(email.message.Message)
     feedparser._set_headersonly()
     data = message.read(4096)
     feedparser.feed(data)
     self._become_message(feedparser.close())
Beispiel #2
0
 def __init__(self, message=None):
     """Initialize a Message instance."""
     feedparser = FeedParser(email.message.Message)
     feedparser._set_headersonly()
     data = message.read(4096)
     feedparser.feed(data)
     self._become_message(feedparser.close())
Beispiel #3
0
def message_from_string_safe(text):
    'handle failure by email standard library by bypassing StringIO blowup'
    try: # use the standard library by default
        return email.message_from_string(text)
    except UnicodeEncodeError: # code copied from email.parser.Parser.parse()
        feedparser = FeedParser(Message)
        feedparser._set_headersonly()
        feedparser.feed(text)
        return feedparser.close()
Beispiel #4
0
 def parse(self, fp, headersonly=False):
     feedparser = FeedParser(self._class, policy=self.policy)
     if headersonly:
         feedparser._set_headersonly()
     while True:
         data = fp.read(8192)
         if not data:
             break
         feedparser.feed(data)
     return feedparser.close()
Beispiel #5
0
    def 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.
        """
        feedparser = FeedParser(self._class, policy=self.policy)
        if headersonly:
            feedparser._set_headersonly()
        while True:
            data = fp.read(8192)
            if not data:
                break
            feedparser.feed(data)
        return feedparser.close()
Beispiel #6
0
    def 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.
        """
        feedparser = FeedParser(self._class)
        if headersonly:
            feedparser._set_headersonly()
        while True:
            data = fp.read(8192)
            if not data:
                break
            feedparser.feed(data)
        return feedparser.close()