[rhmessaging-commits] rhmessaging commits: r4389 - mgmt/trunk/wooly/python/wooly.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Fri Oct 15 12:39:45 EDT 2010


Author: justi9
Date: 2010-10-15 12:39:45 -0400 (Fri, 15 Oct 2010)
New Revision: 4389

Modified:
   mgmt/trunk/wooly/python/wooly/pages.py
Log:
Use a map to lookup content types; tolerate resource names with leading slashes

Modified: mgmt/trunk/wooly/python/wooly/pages.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/pages.py	2010-10-15 15:46:31 UTC (rev 4388)
+++ mgmt/trunk/wooly/python/wooly/pages.py	2010-10-15 16:39:45 UTC (rev 4389)
@@ -323,6 +323,16 @@
         return self.get_javascript()
 
 class ResourcePage(Page):
+    content_types_by_extension = {
+        ".css": "text/css",
+        ".gif": "image/gif",
+        ".html": "text/html",
+        ".jpeg": "image/jpeg",
+        ".jpg": "image/jpeg",
+        ".js": "test/javascript",
+        ".png": "image/png",
+        }
+
     def __init__(self, app, name):
         super(ResourcePage, self).__init__(app, name)
 
@@ -336,29 +346,19 @@
 
     def get_content_type(self, session):
         name = self.rname.get(session)
+        base, ext = os.path.splitext(name)
+        ext = ext.lower()
+        content_type = self.content_types_by_extension.get(ext, "text/plain")
 
-        if name:
-            if name.endswith(".png"):
-                type = "image/png"
-            if name.endswith(".gif"):
-                type = "image/gif"
-            elif name.endswith(".jpeg"):
-                type = "image/jpeg"
-            elif name.endswith(".html"):
-                type = "text/html"
-            elif name.endswith(".css"):
-                type = "text/css"
-            elif name.endswith(".js"):
-                type = "text/javascript"
-            else:
-                type = "text/plain"
+        return content_type
 
-            return type
-
     def do_render(self, session, *args):
         name = self.rname.get(session)
 
         if name:
+            if name.startswith("/"):
+                name = name[1:]
+
             resource = self.app.get_resource(name)
 
             if resource:



More information about the rhmessaging-commits mailing list