~didrocks/unity/altf10

« back to all changes in this revision

Viewing changes to grackle/client.py

  • Committer: Curtis Hovey
  • Date: 2012-03-16 16:10:54 UTC
  • Revision ID: curtis.hovey@canonical.com-20120316161054-jk68i83kh81qm2vi
Store the body text only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
    urlencode,
7
7
)
8
8
 
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',
 
9
from grackle.error import (
 
10
    UnparsableDateRange,
 
11
    UnsupportedDisplayType,
 
12
    UnsupportedOrder,
26
13
    )
27
14
 
28
15
 
59
46
        connection.request(method, url, body)
60
47
        return connection.getresponse()
61
48
 
 
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
 
62
65
    def put_message(self, archive_id, key, file_obj):
63
66
        """Put a message into an archive.
64
67
 
67
70
            the message.
68
71
        :param file_obj: The raw text of the message, as a file.
69
72
        """
 
73
        path = '%s/%s' % (archive_id, key)
70
74
        response = self._method_archive(
71
 
            'POST', archive_id, {'key': key}, file_obj.read())
 
75
            'POST', path, {}, file_obj.read())
72
76
        response.read()
73
77
        if response.status == httplib.BAD_REQUEST:
74
78
            raise Exception('wtf')