/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: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-28 02:47:10 UTC
  • mfrom: (7519.1.1 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200728024710-a2ylds219f1lsl62
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/388173

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import errno
18
 
try:
19
 
    import http.client as http_client
20
 
    import http.server as http_server
21
 
except ImportError:
22
 
    import httplib as http_client
23
 
    import SimpleHTTPServer as http_server
 
18
import http.client as http_client
 
19
import http.server as http_server
24
20
import os
25
21
import posixpath
26
22
import random
27
23
import re
28
24
import socket
29
25
import sys
30
 
try:
31
 
    from urlparse import urlparse
32
 
except ImportError:
33
 
    from urllib.parse import urlparse
 
26
from urllib.parse import urlparse
34
27
 
35
28
from .. import (
36
29
    osutils,
194
187
        header_line = '%s: %s\r\n' % (keyword, value)
195
188
        return len(header_line)
196
189
 
197
 
    def send_head(self):
198
 
        """Overrides base implementation to work around a bug in python2.5."""
199
 
        path = self.translate_path(self.path)
200
 
        if os.path.isdir(path) and not self.path.endswith('/'):
201
 
            # redirect browser - doing basically what apache does when
202
 
            # DirectorySlash option is On which is quite common (braindead, but
203
 
            # common)
204
 
            self.send_response(301)
205
 
            self.send_header("Location", self.path + "/")
206
 
            # Indicates that the body is empty for HTTP/1.1 clients
207
 
            self.send_header('Content-Length', '0')
208
 
            self.end_headers()
209
 
            return None
210
 
 
211
 
        return http_server.SimpleHTTPRequestHandler.send_head(self)
212
 
 
213
190
    def send_range_content(self, file, start, length):
214
191
        file.seek(start)
215
192
        self.wfile.write(file.read(length))
340
317
        # abandon query parameters
341
318
        path = urlparse(path)[2]
342
319
        path = posixpath.normpath(urlutils.unquote(path))
343
 
        if sys.version_info[0] == 2:
344
 
            path = path.decode('utf-8')
345
320
        words = path.split('/')
346
321
        path = self._cwd
347
322
        for num, word in enumerate(w for w in words if w):