10
class UnparsableDateRange(Exception):
11
"""The date_range was not in the format of 2012-01-01..2012-01-31."""
14
class UnsupportedDisplayType(Exception):
15
"""Raised when an Unsupported display_type is requested."""
18
10
class UnsupportedOrder(Exception):
19
11
"""Raised when an Unsupported order is requested."""
22
SUPPORTED_DISPLAY_TYPES = (
29
14
class GrackleClient:
30
15
"""Class for accessing Grackle web service."""
78
63
raise Exception('!!')
80
def get_messages(self, archive_id, message_ids=None, date_range=None,
81
limit=None, memo=None, order=None, headers=None,
82
include_hidden=False, max_body_length=None,
65
def get_messages(self, archive_id, message_ids=None, limit=None,
66
memo=None, order=None, headers=None,
67
max_body_length=None, include_hidden=False):
84
68
"""Retrieve specified messages.
86
70
:param archive_id: The archive to retrieve messages from.
87
71
:param message_ids: (optional) Retrieve only messages with these ids.
88
:param date_range: Retrieve the messages from or between a range of
89
dates. Example: 2012-01-01..2012-01-31 retrieve all the messages
90
between the 01 and 31 of January, including message from 01
92
72
:param limit: The maximum number of messages to return. The server
93
73
may, at its discretion, return fewer.
94
74
:param memo: (optional) Opaque identifier describing the position in
108
88
:param include_hidden: If true, include messages that have been
109
89
flagged "hidden" in the results.
110
:param display_type: Adjust the message content to meet the needs of
111
the intended display. Valid values are:
112
all: (the default) include all message content.
113
text-only: include only plain/text parts; exclude all other parts.
114
headers-only: include only the message headers.
117
92
if message_ids is not None:
118
93
parameters['message_ids'] = message_ids
119
if date_range is not None:
120
parameters['date_range'] = date_range
121
94
if limit is not None:
122
95
parameters['limit'] = limit
123
96
if memo is not None:
128
101
parameters['headers'] = headers
129
102
if max_body_length is not None:
130
103
parameters['max_body_length'] = max_body_length
131
parameters['display_type'] = display_type
132
104
parameters['include_hidden'] = include_hidden
133
105
query = {'parameters': simplejson.dumps(parameters)}
134
106
response = self._method_archive('GET', archive_id, query)
135
107
if response.status == httplib.BAD_REQUEST:
136
if response.reason == UnsupportedOrder.__doc__:
137
raise UnsupportedOrder
138
elif response.reason == UnsupportedDisplayType.__doc__:
139
raise UnsupportedDisplayType
141
raise ValueError('Bad request')
108
raise UnsupportedOrder
142
109
data = response.read()
143
110
return simplejson.loads(data)