~james-w/ubuntu/lucid/lazr.restfulclient/remove-test-recommends

« back to all changes in this revision

Viewing changes to src/lazr/restfulclient/_browser.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2009-11-03 21:30:42 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103213042-pjl4grxyiwbjtufh
Tags: 0.9.10-1
* New upstream release.
  - Do not download missing build-dependencies (Closes: #552949).
* debian/patches/no_deps.patch:
  - Removed, it is no longer useful.
* debian/copyright:
  - Update with new copyright informations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    react when its cache is a MultipleRepresentationCache.
78
78
    """
79
79
 
80
 
    def __init__(self, credentials, cache=None, timeout=None,
 
80
    def __init__(self, authorizer=None, cache=None, timeout=None,
81
81
                 proxy_info=None):
82
82
        super(RestfulHttp, self).__init__(cache, timeout, proxy_info)
83
 
        # The credentials are not used in this class, but you can
84
 
        # use them in a subclass.
85
 
        self.restful_credentials = credentials
86
 
 
 
83
        self.authorizer = authorizer
 
84
        if self.authorizer is not None:
 
85
            self.authorizer.authorizeSession(self)
87
86
 
88
87
    def _request(self, conn, host, absolute_uri, request_uri, method, body,
89
88
                 headers, redirections, cachekey):
103
102
        if 'accept-encoding' in headers:
104
103
            headers['te'] = 'deflate, gzip'
105
104
            del headers['accept-encoding']
 
105
        if headers.has_key('authorization'):
 
106
            # There's an authorization header left over from a
 
107
            # previous request that resulted in a redirect. Remove it
 
108
            # and start again.
 
109
            del headers['authorization']
 
110
        if self.authorizer is not None:
 
111
            self.authorizer.authorizeRequest(
 
112
                absolute_uri, method, body, headers)
106
113
        return super(RestfulHttp, self)._request(
107
114
            conn, host, absolute_uri, request_uri, method, body, headers,
108
115
            redirections, cachekey)
190
197
    def _request(self, url, data=None, method='GET',
191
198
                 media_type='application/json', extra_headers=None):
192
199
        """Create an authenticated request object."""
 
200
        # If the user is trying to get data that has been redacted,
 
201
        # give a helpful message.
 
202
        if url == "tag:launchpad.net:2008:redacted":
 
203
            raise ValueError("You tried to access a resource that you "
 
204
                             "don't have the server-side permission to see.")
 
205
 
193
206
        # Add extra headers for the request.
194
207
        headers = {'Accept' : media_type}
195
208
        if isinstance(self._connection.cache, MultipleRepresentationCache):
218
231
 
219
232
    def get_wadl_application(self, url):
220
233
        """GET a WADL representation of the resource at the requested url."""
 
234
        # We're probably talking to an old version of lazr.restful
 
235
        # that misspells the WADL media type. Accept either the correctly
 
236
        # spelled media type or the misspelling.
 
237
        wadl_type = 'application/vnd.sun.wadl+xml'
 
238
        misspelled_wadl_type = 'application/vd.sun.wadl+xml'
 
239
        accept = "%s, %s" % (wadl_type, misspelled_wadl_type)
221
240
        response, content = self._request(
222
 
            url, media_type='application/vd.sun.wadl+xml')
 
241
            url, media_type=wadl_type, extra_headers={'Accept': accept})
223
242
        return Application(str(url), content)
224
243
 
225
244
    def post(self, url, method_name, **kws):