~mvo/ubuntu-sso-client/strawman-lp711413

« back to all changes in this revision

Viewing changes to ubuntu_sso/utils/webclient/qtnetwork.py

Merged trunk in up to revno 836.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import sys
19
19
 
20
 
from collections import defaultdict
21
 
 
22
20
from PyQt4.QtCore import (
 
21
    QBuffer,
23
22
    QCoreApplication,
24
23
    QUrl,
25
24
)
33
32
 
34
33
from ubuntu_sso.utils.webclient.common import (
35
34
    BaseWebClient,
 
35
    HeaderDict,
36
36
    Response,
37
37
    UnauthorizedError,
38
38
    WebClientError,
62
62
 
63
63
    @defer.inlineCallbacks
64
64
    def request(self, iri, method="GET", extra_headers=None,
65
 
                oauth_credentials=None):
 
65
                oauth_credentials=None, post_content=None):
66
66
        """Return a deferred that will be fired with a Response object."""
67
67
        uri = self.iri_to_uri(iri)
68
68
        request = QNetworkRequest(QUrl(uri))
87
87
        elif method == "HEAD":
88
88
            reply = self.nam.head(request)
89
89
        else:
90
 
            reply = self.nam.sendCustomRequest(request, method)
 
90
            post_buffer = QBuffer()
 
91
            post_buffer.setData(post_content)
 
92
            reply = self.nam.sendCustomRequest(request, method, post_buffer)
91
93
        self.replies[reply] = d
92
94
        result = yield d
93
95
        defer.returnValue(result)
104
106
        error = reply.error()
105
107
        content = reply.readAll()
106
108
        if not error:
107
 
            headers = defaultdict(list)
 
109
            headers = HeaderDict()
108
110
            for key, value in reply.rawHeaderPairs():
109
111
                headers[str(key)].append(str(value))
110
112
            response = Response(bytes(content), headers)