Rev 3229: * Fix the test HTTPServer to be isolated from chdir calls made while it is in http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

Robert Collins robertc at robertcollins.net
Tue Feb 26 02:02:16 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/shallow-branch

------------------------------------------------------------
revno: 3229
revision-id:robertc at robertcollins.net-20080226020203-6d91tyui6iacd2in
parent: robertc at robertcollins.net-20080221225343-lp5xf6hl5g91088a
committer: Robert Collins <robertc at robertcollins.net>
branch nick: HTTPServer.chdir-isolation
timestamp: Tue 2008-02-26 13:02:03 +1100
message:
   * Fix the test HTTPServer to be isolated from chdir calls made while it is
     running, allowing it to be used in blackbox tests. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
=== modified file 'NEWS'
--- a/NEWS	2008-02-20 01:40:08 +0000
+++ b/NEWS	2008-02-26 02:02:03 +0000
@@ -30,6 +30,9 @@
 
   TESTING:
 
+    * Fix the test HTTPServer to be isolated from chdir calls made while it is
+      running, allowing it to be used in blackbox tests. (Robert Collins)
+
   INTERNALS:
 
     * New remote method ``RemoteBzrDir.find_repositoryV2`` adding support for

=== modified file 'bzrlib/tests/http_server.py'
--- a/bzrlib/tests/http_server.py	2008-01-03 08:44:12 +0000
+++ b/bzrlib/tests/http_server.py	2008-02-26 02:02:03 +0000
@@ -58,6 +58,7 @@
 
     def setup(self):
         SimpleHTTPServer.SimpleHTTPRequestHandler.setup(self)
+        self._cwd = self.server._home_dir
         tcs = self.server.test_case_server
         if tcs.protocol_version is not None:
             # If the test server forced a protocol version, use it
@@ -284,8 +285,26 @@
         return self._translate_path(path)
 
     def _translate_path(self, path):
-        return SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(
-            self, path)
+        """Translate a /-separated PATH to the local filename syntax.
+
+        Components that mean special things to the local file system
+        (e.g. drive or directory names) are ignored.  (XXX They should
+        probably be diagnosed.)
+
+        Override from python standard library to stop it calling os.getcwd()
+        """
+        # abandon query parameters
+        path = urlparse.urlparse(path)[2]
+        path = posixpath.normpath(urllib.unquote(path))
+        words = path.split('/')
+        words = filter(None, words)
+        path = self._cwd
+        for word in words:
+            drive, word = os.path.splitdrive(word)
+            head, word = os.path.split(word)
+            if word in (os.curdir, os.pardir): continue
+            path = os.path.join(path, word)
+        return path
 
     if sys.platform == 'win32':
         # On win32 you cannot access non-ascii filenames without
@@ -307,7 +326,7 @@
             path = path.decode('utf-8')
             words = path.split('/')
             words = filter(None, words)
-            path = os.getcwdu()
+            path = self._cwd
             for word in words:
                 drive, word = os.path.splitdrive(word)
                 head, word = os.path.split(word)
@@ -324,6 +343,7 @@
         # server), allowing dynamic behaviors to be defined from
         # the tests cases.
         self.test_case_server = test_case_server
+        self._home_dir = test_case_server._home_dir
 
     def tearDown(self):
          """Called to clean-up the server.
@@ -355,6 +375,7 @@
          # Let the server properly close the socket
          self.server_close()
 
+
 class TestingHTTPServer(SocketServer.TCPServer, TestingHTTPServerMixin):
 
     def __init__(self, server_address, request_handler_class,



More information about the bazaar-commits mailing list