/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: 2020-07-05 12:50:01 UTC
  • mfrom: (7490.40.46 work)
  • mto: (7490.40.48 work)
  • mto: This revision was merged to the branch mainline in revision 7519.
  • Revision ID: jelmer@jelmer.uk-20200705125001-7s3vo0p55szbbws7
Merge lp:brz/3.1.

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
 
import http.client as http_client
19
 
import http.server as http_server
 
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
20
24
import os
21
25
import posixpath
22
26
import random
23
27
import re
24
28
import socket
25
29
import sys
26
 
from urllib.parse import urlparse
 
30
try:
 
31
    from urlparse import urlparse
 
32
except ImportError:
 
33
    from urllib.parse import urlparse
27
34
 
28
35
from .. import (
29
36
    osutils,
187
194
        header_line = '%s: %s\r\n' % (keyword, value)
188
195
        return len(header_line)
189
196
 
 
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
 
190
213
    def send_range_content(self, file, start, length):
191
214
        file.seek(start)
192
215
        self.wfile.write(file.read(length))
317
340
        # abandon query parameters
318
341
        path = urlparse(path)[2]
319
342
        path = posixpath.normpath(urlutils.unquote(path))
 
343
        if sys.version_info[0] == 2:
 
344
            path = path.decode('utf-8')
320
345
        words = path.split('/')
321
346
        path = self._cwd
322
347
        for num, word in enumerate(w for w in words if w):