~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/HTTPTestUtil.py

MergeĀ fromĀ martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import BaseHTTPServer, SimpleHTTPServer, socket, errno, time
18
18
from bzrlib.tests import TestCaseInTempDir
 
19
from bzrlib.osutils import relpath
19
20
 
20
21
 
21
22
class WebserverNotAvailable(Exception):
22
23
    pass
23
24
 
24
 
class BadWebserverPath(ValueError):
25
 
    def __str__(self):
26
 
        return 'path %s is not in %s' % self.args
27
 
 
28
25
class TestingHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
29
26
    def log_message(self, format, *args):
30
27
        self.server.test_case.log("webserver - %s - - [%s] %s",
116
113
    def get_remote_url(self, path):
117
114
        import os
118
115
 
119
 
        path_parts = path.split(os.path.sep)
120
116
        if os.path.isabs(path):
121
 
            if path_parts[:len(self._local_path_parts)] != \
122
 
                   self._local_path_parts:
123
 
                raise BadWebserverPath(path, self.test_dir)
124
 
            remote_path = '/'.join(path_parts[len(self._local_path_parts):])
 
117
            remote_path = relpath(self.test_dir, path)
125
118
        else:
126
 
            remote_path = '/'.join(path_parts)
 
119
            remote_path = path
127
120
 
128
121
        self._http_starting.acquire()
129
122
        self._http_starting.release()
132
125
    def setUp(self):
133
126
        TestCaseInTempDir.setUp(self)
134
127
        import threading, os
135
 
        self._local_path_parts = self.test_dir.split(os.path.sep)
136
128
        self._http_starting = threading.Lock()
137
129
        self._http_starting.acquire()
138
130
        self._http_running = True