~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

NEWS section template into a separate file

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Handlers for HTTP Responses.
18
18
 
24
24
 
25
25
import httplib
26
26
from cStringIO import StringIO
 
27
import rfc822
27
28
 
28
29
from bzrlib import (
29
30
    errors,
90
91
 
91
92
    def set_boundary(self, boundary):
92
93
        """Define the boundary used in a multi parts message.
93
 
        
 
94
 
94
95
        The file should be at the beginning of the body, the first range
95
96
        definition is read and taken into account.
96
97
        """
107
108
            # string entity.
108
109
            # To be on the safe side we allow it before any boundary line
109
110
            boundary_line = self._file.readline()
 
111
 
110
112
        if boundary_line != '--' + self._boundary + '\r\n':
111
 
            raise errors.InvalidHttpResponse(
112
 
                self._path,
113
 
                "Expected a boundary (%s) line, got '%s'" % (self._boundary,
114
 
                                                             boundary_line))
 
113
            # rfc822.unquote() incorrectly unquotes strings enclosed in <>
 
114
            # IIS 6 and 7 incorrectly wrap boundary strings in <>
 
115
            # together they make a beautiful bug, which we will be gracious
 
116
            # about here
 
117
            if (self._unquote_boundary(boundary_line) !=
 
118
                '--' + self._boundary + '\r\n'):
 
119
                raise errors.InvalidHttpResponse(
 
120
                    self._path,
 
121
                    "Expected a boundary (%s) line, got '%s'"
 
122
                    % (self._boundary, boundary_line))
 
123
 
 
124
    def _unquote_boundary(self, b):
 
125
        return b[:2] + rfc822.unquote(b[2:-2]) + b[-2:]
115
126
 
116
127
    def read_range_definition(self):
117
128
        """Read a new range definition in a multi parts message.
277
288
    :param msg: An HTTPMessage containing the headers for the response
278
289
    :param data: A file-like object that can be read() to get the
279
290
                 requested data
280
 
    :return: A file-like object that can seek()+read() the 
 
291
    :return: A file-like object that can seek()+read() the
281
292
             ranges indicated by the headers.
282
293
    """
283
294
    rfile = RangeFile(url, data)