~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-09-01 17:37:35 UTC
  • mfrom: (1979.1.2 boundary-quotes-57723)
  • Revision ID: pqm@pqm.ubuntu.com-20060901173735-543e9acad03760d1
(jam) fix bug #57723: failure when using SQUID proxy

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
                                 self._ent_start, self._ent_end,
61
61
                                 self._data_start)
62
62
 
 
63
    __repr__ = __str__
 
64
 
63
65
 
64
66
class RangeFile(object):
65
67
    """File-like object that allow access to partial available data.
96
98
        i = bisect(self._ranges, self._pos) - 1
97
99
 
98
100
        if i < 0 or self._pos > self._ranges[i]._ent_end:
 
101
            mutter('Bisect for pos: %s failed. Found offset: %d, ranges:%s',
 
102
                   self._pos, i, self._ranges)
99
103
            raise errors.InvalidRange(self._path, self._pos)
100
104
 
101
105
        r = self._ranges[i]
134
138
 
135
139
    # TODO: jam 20060706 Consider compiling these regexes on demand
136
140
    _CONTENT_RANGE_RE = re.compile(
137
 
        '\s*([^\s]+)\s+([0-9]+)-([0-9]+)/([0-9]+)\s*$')
 
141
        r'\s*([^\s]+)\s+([0-9]+)-([0-9]+)/([0-9]+)\s*$')
138
142
 
139
143
    def __init__(self, path, content_range, input_file):
140
144
        # mutter("parsing 206 non-multipart response for %s", path)
175
179
    """A multi-range HTTP response."""
176
180
    
177
181
    _CONTENT_TYPE_RE = re.compile(
178
 
        '^\s*multipart/byteranges\s*;\s*boundary\s*=\s*(.*?)\s*$')
 
182
        r'^\s*multipart/byteranges\s*;\s*boundary\s*=\s*("?)([^"]*?)\1\s*$')
179
183
    
180
184
    # Start with --<boundary>\r\n
181
185
    # and ignore all headers ending in \r\n
195
199
        RangeFile.__init__(self, path, input_file)
196
200
 
197
201
        self.boundary_regex = self._parse_boundary(content_type, path)
 
202
        # mutter('response:\n%r', self._data)
198
203
 
199
204
        for match in self.boundary_regex.finditer(self._data):
200
205
            ent_start, ent_end = HttpRangeResponse._parse_range(match.group(1),
216
221
            raise errors.InvalidHttpContentType(path, ctype,
217
222
                    "Expected multipart/byteranges with boundary")
218
223
 
219
 
        boundary = match.group(1)
 
224
        boundary = match.group(2)
220
225
        # mutter('multipart boundary is %s', boundary)
221
226
        pattern = HttpMultipartRangeResponse._BOUNDARY_PATT
222
227
        return re.compile(pattern % re.escape(boundary),