Commits

Anonymous committed 8d847f1

fix uri handling. should be better with django

  • Participants
  • Parent commits 0644f39

Comments (0)

Files changed (2)

File restclient/rest.py

     200
 """
 
+import cgi
 import mimetypes
 import os
 import StringIO
         string parameters.
 
         """
-        trailing_slash = False
+        base_trailing_slash = False
         if base and base.endswith("/"):
-            trailing_slash = True
+            base_trailing_slash = True
             base = base[:-1]
         retval = [base]
 
         # build the path
-        path = "/".join([''] +
-                        [url_quote(s.strip('/'), self.charset, self.safe) for s in path
-                         if s is not None and isinstance(s, basestring)])
-                         
-        if trailing_slash and not path:
-            path = path + "/"
+        _path = []
+        trailing_slash = False       
+        for s in path:
+            if s is not None and isinstance(s, basestring):
+                if len(s) > 1 and s.endswith('/'):
+                    trailing_slash = True
+                else:
+                    trailing_slash = False
+                _path.append(url_quote(s.strip('/'), self.charset, self.safe))
+                       
+        path_str =""
+        if _path:
+            path_str = "/".join([''] + _path)
+            if trailing_slash:
+                path_str = path_str + "/" 
+        elif base_trailing_slash:
+            path_str = path_str + "/" 
             
-        if path:
-            retval.append(path)
+        if path_str:
+            retval.append(path_str)
 
         params = []
         for k, v in query.items():
                 url_quote(value)))
     return to_bytestring(";".join(tmp))
 
-import cgi
+
 
 def _getCharacterEncoding(http_headers, xml_data):
     '''Get the character encoding of the XML document

File tests/resource_test.py

 
 from _server_test import HOST, PORT, run_server_test
 
+
+class RestClientTestCase(unittest.TestCase):
+    
+    def setUp(self):
+        self.transport = transport = HTTPLib2Transport()
+        self.client = RestClient(transport)
+        
+    def testMakeUri(self):
+        self.assert_(self.client.make_uri("http://localhost", "/") == "http://localhost/")
+        self.assert_(self.client.make_uri("http://localhost/") == "http://localhost/")
+        self.assert_(self.client.make_uri("http://localhost/", "/test/echo") == "http://localhost/test/echo")
+        self.assert_(self.client.make_uri("http://localhost/", "/test/echo/") == "http://localhost/test/echo/")
+        self.assert_(self.client.make_uri("http://localhost", "/test/echo/") == "http://localhost/test/echo/")
+        self.assert_(self.client.make_uri("http://localhost", "test/echo") == "http://localhost/test/echo")
+        self.assert_(self.client.make_uri("http://localhost", "test/echo/") == "http://localhost/test/echo/")
+        
 class ResourceTestCase(unittest.TestCase):
 
     def setUp(self):