~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Curtis Hovey
  • Date: 2012-01-31 05:24:10 UTC
  • mfrom: (6.2.19 client-get-messages-0)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120131052410-4n5iva4ujik6nhp8
Added support for display_type.
Introduced make_message and make_mime_message to make test data consistent for
InMemoryStore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
)
8
8
 
9
9
 
 
10
class UnsupportedDisplayType(Exception):
 
11
    """Raised when an Unsupported display_type is requested."""
 
12
 
 
13
 
10
14
class UnsupportedOrder(Exception):
11
15
    """Raised when an Unsupported order is requested."""
12
16
 
13
17
 
 
18
SUPPORTED_DISPLAY_TYPES = (
 
19
    'all',
 
20
    'text-only',
 
21
    'headers-only',
 
22
    )
 
23
 
 
24
 
14
25
class GrackleClient:
15
26
    """Class for accessing Grackle web service."""
16
27
 
64
75
 
65
76
    def get_messages(self, archive_id, message_ids=None, limit=None,
66
77
                     memo=None, order=None, headers=None,
67
 
                     max_body_length=None, include_hidden=False):
 
78
                     max_body_length=None, include_hidden=False,
 
79
                     display_type='all'):
68
80
        """Retrieve specified messages.
69
81
 
70
82
        :param archive_id: The archive to retrieve messages from.
87
99
            bodies.
88
100
        :param include_hidden: If true, include messages that have been
89
101
            flagged "hidden" in the results.
 
102
        :param display_type: Adjust the message content to meet the needs of
 
103
            the intended display. Valid values are:
 
104
            all: (the default) include all message content.
 
105
            text-only: include only plain/text parts; exclude all other parts.
 
106
            headers-only: include only the message headers.
90
107
        """
91
108
        parameters = {}
92
109
        if message_ids is not None:
101
118
            parameters['headers'] = headers
102
119
        if max_body_length is not None:
103
120
            parameters['max_body_length'] = max_body_length
 
121
        parameters['display_type'] = display_type
104
122
        parameters['include_hidden'] = include_hidden
105
123
        query = {'parameters': simplejson.dumps(parameters)}
106
124
        response = self._method_archive('GET', archive_id, query)
107
125
        if response.status == httplib.BAD_REQUEST:
108
 
            raise UnsupportedOrder
 
126
            if response.reason == UnsupportedOrder.__doc__:
 
127
                raise UnsupportedOrder
 
128
            elif response.reason == UnsupportedDisplayType.__doc__:
 
129
                raise UnsupportedDisplayType
 
130
            else:
 
131
                raise ValueError('Bad request')
109
132
        data = response.read()
110
133
        return simplejson.loads(data)