/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/http_server.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import random
27
27
import re
28
28
import socket
29
 
import sys
30
29
try:
31
30
    from urlparse import urlparse
32
31
except ImportError:
102
101
    def send_error(self, code, message=None):
103
102
        """Send and log an error reply.
104
103
 
105
 
        We redefine the python-provided version to be able to set a
 
104
        We redefine the python-provided version to be able to set a 
106
105
        ``Content-Length`` header as some http/1.1 clients complain otherwise
107
106
        (see bug #568421).
108
107
 
126
125
        self.send_header('Connection', 'close')
127
126
        self.end_headers()
128
127
        if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
129
 
            self.wfile.write(content.encode('utf-8'))
 
128
            self.wfile.write(content)
130
129
 
131
130
    def _handle_one_request(self):
132
131
        http_server.SimpleHTTPRequestHandler.handle_one_request(self)
233
232
        boundary = '%d' % random.randint(0, 0x7FFFFFFF)
234
233
        self.send_header('Content-Type',
235
234
                         'multipart/byteranges; boundary=%s' % boundary)
236
 
        boundary_line = b'--%s\r\n' % boundary.encode('ascii')
 
235
        boundary_line = '--%s\r\n' % boundary
237
236
        # Calculate the Content-Length
238
237
        content_length = 0
239
238
        for (start, end) in ranges:
242
241
                'Content-type', 'application/octet-stream')
243
242
            content_length += self._header_line_length(
244
243
                'Content-Range', 'bytes %d-%d/%d' % (start, end, file_size))
245
 
            content_length += len('\r\n')  # end headers
 
244
            content_length += len('\r\n') # end headers
246
245
            content_length += end - start + 1
247
246
        content_length += len(boundary_line)
248
247
        self.send_header('Content-length', content_length)
340
339
        # abandon query parameters
341
340
        path = urlparse(path)[2]
342
341
        path = posixpath.normpath(urlutils.unquote(path))
343
 
        if sys.version_info[0] == 2:
344
 
            path = path.decode('utf-8')
 
342
        path = path.decode('utf-8')
345
343
        words = path.split('/')
346
344
        path = self._cwd
347
345
        for num, word in enumerate(w for w in words if w):
348
346
            if num == 0:
349
347
                drive, word = os.path.splitdrive(word)
350
348
            head, word = os.path.split(word)
351
 
            if word in (os.curdir, os.pardir):
352
 
                continue
 
349
            if word in (os.curdir, os.pardir): continue
353
350
            path = os.path.join(path, word)
354
351
        return path
355
352
 
382
379
    server, we need an independent connection for each of them. We achieve that
383
380
    by spawning a new thread for each connection.
384
381
    """
385
 
 
386
382
    def __init__(self, server_address, request_handler_class,
387
383
                 test_case_server):
388
384
        test_server.TestingThreadingTCPServer.__init__(self, server_address,
450
446
        path_parts = path.split(os.path.sep)
451
447
        if os.path.isabs(path):
452
448
            if path_parts[:len(self._local_path_parts)] != \
453
 
                    self._local_path_parts:
 
449
                   self._local_path_parts:
454
450
                raise BadWebserverPath(path, self.test_dir)
455
451
            remote_path = '/'.join(path_parts[len(self._local_path_parts):])
456
452
        else: