[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/publication/ requests containing a content-type header like 'text/xml; charset=utf-8'

Andreas Jung andreas at andreas-jung.com
Sun Oct 23 08:43:15 EDT 2005


Log message for revision 39563:
  requests containing a content-type header like 'text/xml; charset=utf-8'
  caused a wrong publisher choice since publishers are registered per-mimetype
  and not per-mimetype+charset
  

Changed:
  U   Zope3/trunk/src/zope/app/publication/requestpublicationregistry.py
  U   Zope3/trunk/src/zope/app/publication/tests/test_requestpublicationregistry.py

-=-
Modified: Zope3/trunk/src/zope/app/publication/requestpublicationregistry.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/requestpublicationregistry.py	2005-10-23 09:46:52 UTC (rev 39562)
+++ Zope3/trunk/src/zope/app/publication/requestpublicationregistry.py	2005-10-23 12:43:14 UTC (rev 39563)
@@ -72,9 +72,15 @@
 
 
     def getFactoriesFor(self, method, mimetype):
+
+        if ';' in mimetype:
+            # 'mimetype' might be something like 'text/xml; charset=utf8'. In 
+            # this case we are only interested in the first part.
+            mimetype = mimetype.split(';')[0]
+
         try:
             return self._d[method][mimetype]
-        except:
+        except KeyError:
             return None
 
 

Modified: Zope3/trunk/src/zope/app/publication/tests/test_requestpublicationregistry.py
===================================================================
--- Zope3/trunk/src/zope/app/publication/tests/test_requestpublicationregistry.py	2005-10-23 09:46:52 UTC (rev 39562)
+++ Zope3/trunk/src/zope/app/publication/tests/test_requestpublicationregistry.py	2005-10-23 12:43:14 UTC (rev 39563)
@@ -95,6 +95,7 @@
         r.register('*', '*', 'http', 1, BrowserFactory())
 
         self.assertEqual(len(r.getFactoriesFor('POST', 'text/xml')) , 2)
+        self.assertEqual(len(r.getFactoriesFor('POST', 'text/xml; charset=utf-8')) , 2)
         self.assertEqual(len(r.getFactoriesFor('POST', '*')) , 1)
         self.assertEqual(r.getFactoriesFor('GET', 'text/html') , None)
         self.assertEqual(len(r.getFactoriesFor('HEAD', '*')) , 1)



More information about the Zope3-Checkins mailing list