~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Curtis Hovey
  • Date: 2012-02-14 21:55:15 UTC
  • Revision ID: curtis.hovey@canonical.com-20120214215515-vu1zn9n58ov659es
Added basic handling of date_range.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    urlencode,
7
7
)
8
8
 
9
 
from grackle.error import (
10
 
    UnparsableDateRange,
11
 
    UnsupportedDisplayType,
12
 
    UnsupportedOrder,
 
9
 
 
10
class UnparsableDateRange(Exception):
 
11
    """The date_range was not in the format of 2012-01-01..2012-01-31."""
 
12
 
 
13
 
 
14
class UnsupportedDisplayType(Exception):
 
15
    """Raised when an Unsupported display_type is requested."""
 
16
 
 
17
 
 
18
class UnsupportedOrder(Exception):
 
19
    """Raised when an Unsupported order is requested."""
 
20
 
 
21
 
 
22
SUPPORTED_DISPLAY_TYPES = (
 
23
    'all',
 
24
    'text-only',
 
25
    'headers-only',
13
26
    )
14
27
 
15
28
 
46
59
        connection.request(method, url, body)
47
60
        return connection.getresponse()
48
61
 
49
 
    def put_archive(self, archive_id, mbox=None):
50
 
        """Create an archive.
51
 
 
52
 
        :param archive_id: The archive id.
53
 
        :param mbox: An optional mbox with messages to add to the new archive.
54
 
        """
55
 
        response = self._method_archive(
56
 
            'POST', '', {'archive_id': archive_id}, None)
57
 
        response.read()
58
 
        if response.status == httplib.BAD_REQUEST:
59
 
            raise Exception('wtf')
60
 
        elif response.status == httplib.CREATED:
61
 
            return
62
 
        else:
63
 
            raise Exception('!!')
64
 
 
65
62
    def put_message(self, archive_id, key, file_obj):
66
63
        """Put a message into an archive.
67
64
 
70
67
            the message.
71
68
        :param file_obj: The raw text of the message, as a file.
72
69
        """
73
 
        path = '%s/%s' % (archive_id, key)
74
70
        response = self._method_archive(
75
 
            'POST', path, {}, file_obj.read())
 
71
            'POST', archive_id, {'key': key}, file_obj.read())
76
72
        response.read()
77
73
        if response.status == httplib.BAD_REQUEST:
78
74
            raise Exception('wtf')
141
137
                raise UnsupportedOrder
142
138
            elif response.reason == UnsupportedDisplayType.__doc__:
143
139
                raise UnsupportedDisplayType
144
 
            elif response.reason == UnparsableDateRange.__doc__:
145
 
                raise UnparsableDateRange
146
140
            else:
147
141
                raise ValueError('Bad request')
148
142
        data = response.read()