~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-30 18:28:17 UTC
  • mto: (6.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 45.
  • Revision ID: curtis.hovey@canonical.com-20120130182817-t72j09m11g8fspdq
Hush lint.

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
 
 
14
10
class UnsupportedOrder(Exception):
15
11
    """Raised when an Unsupported order is requested."""
16
12
 
17
13
 
18
 
SUPPORTED_DISPLAY_TYPES = (
19
 
    'all',
20
 
    'text-only',
21
 
    'headers-only',
22
 
    )
23
 
 
24
 
 
25
14
class GrackleClient:
26
15
    """Class for accessing Grackle web service."""
27
16
 
75
64
 
76
65
    def get_messages(self, archive_id, message_ids=None, limit=None,
77
66
                     memo=None, order=None, headers=None,
78
 
                     max_body_length=None, include_hidden=False,
79
 
                     display_type='all'):
 
67
                     max_body_length=None, include_hidden=False):
80
68
        """Retrieve specified messages.
81
69
 
82
70
        :param archive_id: The archive to retrieve messages from.
99
87
            bodies.
100
88
        :param include_hidden: If true, include messages that have been
101
89
            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.
107
90
        """
108
91
        parameters = {}
109
92
        if message_ids is not None:
118
101
            parameters['headers'] = headers
119
102
        if max_body_length is not None:
120
103
            parameters['max_body_length'] = max_body_length
121
 
        parameters['display_type'] = display_type
122
104
        parameters['include_hidden'] = include_hidden
123
105
        query = {'parameters': simplejson.dumps(parameters)}
124
106
        response = self._method_archive('GET', archive_id, query)
125
107
        if response.status == httplib.BAD_REQUEST:
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')
 
108
            raise UnsupportedOrder
132
109
        data = response.read()
133
110
        return simplejson.loads(data)