~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/response.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006 Michael Ellerman
 
2
#           modified by John Arbash Meinel (Canonical Ltd)
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
59
60
                                 self._ent_start, self._ent_end,
60
61
                                 self._data_start)
61
62
 
62
 
    __repr__ = __str__
63
 
 
64
63
 
65
64
class RangeFile(object):
66
65
    """File-like object that allow access to partial available data.
97
96
        i = bisect(self._ranges, self._pos) - 1
98
97
 
99
98
        if i < 0 or self._pos > self._ranges[i]._ent_end:
100
 
            mutter('Bisect for pos: %s failed. Found offset: %d, ranges:%s',
101
 
                   self._pos, i, self._ranges)
102
99
            raise errors.InvalidRange(self._path, self._pos)
103
100
 
104
101
        r = self._ranges[i]
137
134
 
138
135
    # TODO: jam 20060706 Consider compiling these regexes on demand
139
136
    _CONTENT_RANGE_RE = re.compile(
140
 
        r'\s*([^\s]+)\s+([0-9]+)-([0-9]+)/([0-9]+)\s*$')
 
137
        '\s*([^\s]+)\s+([0-9]+)-([0-9]+)/([0-9]+)\s*$')
141
138
 
142
139
    def __init__(self, path, content_range, input_file):
143
140
        # mutter("parsing 206 non-multipart response for %s", path)
178
175
    """A multi-range HTTP response."""
179
176
    
180
177
    _CONTENT_TYPE_RE = re.compile(
181
 
        r'^\s*multipart/byteranges\s*;\s*boundary\s*=\s*("?)([^"]*?)\1\s*$')
 
178
        '^\s*multipart/byteranges\s*;\s*boundary\s*=\s*(.*?)\s*$')
182
179
    
183
180
    # Start with --<boundary>\r\n
184
181
    # and ignore all headers ending in \r\n
198
195
        RangeFile.__init__(self, path, input_file)
199
196
 
200
197
        self.boundary_regex = self._parse_boundary(content_type, path)
201
 
        # mutter('response:\n%r', self._data)
202
198
 
203
199
        for match in self.boundary_regex.finditer(self._data):
204
200
            ent_start, ent_end = HttpRangeResponse._parse_range(match.group(1),
220
216
            raise errors.InvalidHttpContentType(path, ctype,
221
217
                    "Expected multipart/byteranges with boundary")
222
218
 
223
 
        boundary = match.group(2)
 
219
        boundary = match.group(1)
224
220
        # mutter('multipart boundary is %s', boundary)
225
221
        pattern = HttpMultipartRangeResponse._BOUNDARY_PATT
226
222
        return re.compile(pattern % re.escape(boundary),
250
246
        try:
251
247
            content_type = headers['Content-Type']
252
248
        except KeyError:
253
 
            # When there is no content-type header we treat
254
 
            # the response as being of type 'application/octet-stream' as per
255
 
            # RFC2616 section 7.2.1.
256
 
            # Therefore it is obviously not multipart
257
 
            content_type = 'application/octet-stream'
258
 
            is_multipart = False
259
 
        else:
260
 
            is_multipart = _is_multipart(content_type)
 
249
            raise errors.InvalidHttpContentType(url, '',
 
250
                msg='Missing Content-Type')
261
251
 
262
 
        if is_multipart:
 
252
        if _is_multipart(content_type):
263
253
            # Full fledged multipart response
264
254
            return HttpMultipartRangeResponse(url, content_type, data)
265
255
        else:
279
269
        return data
280
270
    elif code == 404:
281
271
        raise errors.NoSuchFile(url)
282
 
    # Some servers will retun "400: Bad Request" when too much ranges are
283
 
    # specified
284
 
    elif code in (400, 416):
285
 
        # We don't know which, but one of the ranges we specified
286
 
        # was wrong. So we raise with 0 for a lack of a better
287
 
        # magic value.
288
 
        raise errors.InvalidRange(url,0)
289
272
 
290
273
    # TODO: jam 20060713 Properly handle redirects (302 Found, etc)
291
274
    #       The '_get' code says to follow redirects, we probably