]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Moved BodyData to response_types module
authorMenno Smits <menno@freshfoo.com>
Mon, 12 Jan 2015 11:05:00 +0000 (00:05 +1300)
committerMenno Smits <menno@freshfoo.com>
Mon, 12 Jan 2015 11:05:00 +0000 (00:05 +1300)
imapclient/response_parser.py
imapclient/response_types.py

index 87d7593b7502f433f4deedacd612ed7c59cc32ee..acbe893cf761a5d2ad9748afaec544855b800fc1 100644 (file)
@@ -23,7 +23,7 @@ xrange = six.moves.xrange
 from .datetime_util import parse_to_datetime
 from .fixed_offset import FixedOffset
 from .response_lexer import TokenSource
-from .response_types import Envelope, Address
+from .response_types import BodyData, Envelope, Address
 
 try:
     import imaplib2 as imaplib
@@ -124,28 +124,6 @@ def _int_or_error(value, error_text):
         raise ParseError('%s: %s' % (error_text, repr(value)))
 
 
-class BodyData(tuple):
-
-    @classmethod
-    def create(cls, response):
-        # In case of multipart messages we will see at least 2 tuples
-        # at the start. Nest these in to a list so that the returned
-        # response tuple always has a consistent number of elements
-        # regardless of whether the message is multipart or not.
-        if isinstance(response[0], tuple):
-            # Multipart, find where the message part tuples stop
-            for i, part in enumerate(response):
-                if isinstance(part, six.binary_type):
-                    break
-            return cls(([cls.create(part) for part in response[:i]],) + response[i:])
-        else:
-            return cls(response)
-
-    @property
-    def is_multipart(self):
-        return isinstance(self[0], list)
-
-
 def _convert_INTERNALDATE(date_string, normalise_times=True):
     date_msg = b'INTERNALDATE "' + date_string + b'"'
     mo = imaplib.InternalDate.match(date_msg)
index 78365da96148e35311b4f71e8e2e44e275f4f464..5625b585723bf373a50e7b68835e557f4fd0c280 100644 (file)
@@ -5,6 +5,8 @@
 from collections import namedtuple
 from email.utils import formataddr
 
+from . import six
+
 
 class Envelope(namedtuple("Envelope", "date subject from_ sender reply_to to " +
                           "cc bcc in_reply_to message_id")):
@@ -50,6 +52,7 @@ class Address(namedtuple("Address", "name route mailbox host")):
     def __str__(self):
         return formataddr((self.name, self.mailbox + '@' + self.host))
 
+
 class SearchIds(list):
     """
     Contains a list of message ids as returned by IMAPClient.search().
@@ -62,3 +65,28 @@ class SearchIds(list):
     def __init__(self, *args):
         list.__init__(self, *args)
         self.modseq = None
+
+
+class BodyData(tuple):
+    """
+    Returned when parsing BODY and BODYSTRUCTURE responses.
+    """
+
+    @classmethod
+    def create(cls, response):
+        # In case of multipart messages we will see at least 2 tuples
+        # at the start. Nest these in to a list so that the returned
+        # response tuple always has a consistent number of elements
+        # regardless of whether the message is multipart or not.
+        if isinstance(response[0], tuple):
+            # Multipart, find where the message part tuples stop
+            for i, part in enumerate(response):
+                if isinstance(part, six.binary_type):
+                    break
+            return cls(([cls.create(part) for part in response[:i]],) + response[i:])
+        else:
+            return cls(response)
+
+    @property
+    def is_multipart(self):
+        return isinstance(self[0], list)