~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Curtis Hovey
  • Date: 2012-01-30 20:31:29 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: curtis.hovey@canonical.com-20120130203129-mr4jjkjm401g3vdq
Added SUPPORTED_DISPLAY_TYPES.

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
 
63
74
            raise Exception('!!')
64
75
 
65
76
    def get_messages(self, archive_id, message_ids=None, limit=None,
66
 
                     memo=None, order=None, headers=None,
 
77
                     memo=None, order=None, headers=None, display_type='all',
67
78
                     max_body_length=None, include_hidden=False):
68
79
        """Retrieve specified messages.
69
80
 
81
92
        :param headers: The headers to include in the message.  Only headers
82
93
            actually present in the message will be provided.  If unspecified,
83
94
            most headers will be included.
 
95
        :param display_type: Adjust the message content to meet the needs of
 
96
            the intended display. Valid values are:
 
97
            all: (the default) include all message content.
 
98
            text-only: include only plain/text parts; exclude all other parts.
 
99
            headers-only: include only the message headers.
84
100
        :param max_body_length: The maximum length for a message's body.  When
85
101
            multiple messages are nested (as with a thread), this applies to
86
102
            each message's body, not the aggregate length of all messages'
99
115
            parameters['order'] = order
100
116
        if headers is not None:
101
117
            parameters['headers'] = headers
 
118
        if display_type not in SUPPORTED_DISPLAY_TYPES:
 
119
            raise UnsupportedDisplayType
102
120
        if max_body_length is not None:
103
121
            parameters['max_body_length'] = max_body_length
104
122
        parameters['include_hidden'] = include_hidden