[pypy-svn] r38789 - in pypy/dist/pypy/translator/js/lib: . test

fijal at codespeak.net fijal at codespeak.net
Wed Feb 14 10:47:12 CET 2007


Author: fijal
Date: Wed Feb 14 10:47:11 2007
New Revision: 38789

Modified:
   pypy/dist/pypy/translator/js/lib/server.py
   pypy/dist/pypy/translator/js/lib/test/test_url.py
   pypy/dist/pypy/translator/js/lib/url.py
Log:
* Minor tweaks around cgiparse problems
* allow staticdir to specify content-type


Modified: pypy/dist/pypy/translator/js/lib/server.py
==============================================================================
--- pypy/dist/pypy/translator/js/lib/server.py	(original)
+++ pypy/dist/pypy/translator/js/lib/server.py	Wed Feb 14 10:47:11 2007
@@ -106,11 +106,15 @@
 class StaticDir(object):
     exposed = True
 
-    def __init__(self, path):
+    def __init__(self, path, type=None):
         self.path = path
+        self.type = type
 
     def __call__(self, path):
-        return open(os.path.join(str(self.path), str(path))).read()
+        data = open(os.path.join(str(self.path), str(path))).read()
+        if self.type:
+            return self.type, data
+        return data
 
 def create_server(server_address = ('', 8000), handler=TestHandler,
                  server=HTTPServer):

Modified: pypy/dist/pypy/translator/js/lib/test/test_url.py
==============================================================================
--- pypy/dist/pypy/translator/js/lib/test/test_url.py	(original)
+++ pypy/dist/pypy/translator/js/lib/test/test_url.py	Wed Feb 14 10:47:11 2007
@@ -7,4 +7,5 @@
     assert parse_url("/a/b") == (["a", "b"], {})
     assert parse_url("/a/b/c/") == (["a", "b", "c"], {})
     assert parse_url("a/b?q=a&c=z") == (["a","b"], {"q":"a", "c":"z"})
-
+    got = parse_url('/get_message?sid=2ed&pid=-1')
+    assert got == (["get_message"], {'pid':'-1', 'sid':'2ed'})

Modified: pypy/dist/pypy/translator/js/lib/url.py
==============================================================================
--- pypy/dist/pypy/translator/js/lib/url.py	(original)
+++ pypy/dist/pypy/translator/js/lib/url.py	Wed Feb 14 10:47:11 2007
@@ -31,7 +31,14 @@
     """
     if '?' in path:
         path, var_str = path.split("?")
-        vars = cgi.parse_qs(var_str)
+        vars_orig = cgi.parse_qs(var_str)
+        # if vars has a list inside...
+        vars = {}
+        for i, v in vars_orig.items():
+            if isinstance(v, list):
+                vars[i] = v[0]
+            else:
+                vars[i] = v
     else:
         vars = {}
     parts = [urllib.unquote(i) for i in path.split("/") if i]



More information about the Pypy-commit mailing list