Author: gwilson
Date: 2007-11-18 22:00:41 -0600 (Sun, 18 Nov 2007)
New Revision: 6698

Modified:
   django/trunk/django/utils/cache.py
Log:
Some minor changes to the `patch_vary_headers` function:
 * Replaced a for loop with a list comprehension.
 * Used a set instead of a dict with dummy values.
 * Used a bit more readable variable names.


Modified: django/trunk/django/utils/cache.py
===================================================================
--- django/trunk/django/utils/cache.py  2007-11-19 03:41:46 UTC (rev 6697)
+++ django/trunk/django/utils/cache.py  2007-11-19 04:00:41 UTC (rev 6698)
@@ -20,6 +20,10 @@
 import md5
 import re
 import time
+try:
+    set
+except NameError:
+    from sets import Set as set   # Python 2.3 fallback
 
 from django.conf import settings
 from django.core.cache import cache
@@ -107,14 +111,15 @@
     # Note that we need to keep the original order intact, because cache
     # implementations may rely on the order of the Vary contents in, say,
     # computing an MD5 hash.
-    vary = []
     if response.has_header('Vary'):
-        vary = cc_delim_re.split(response['Vary'])
-    oldheaders = dict([(el.lower(), 1) for el in vary])
-    for newheader in newheaders:
-        if not newheader.lower() in oldheaders:
-            vary.append(newheader)
-    response['Vary'] = ', '.join(vary)
+        vary_headers = cc_delim_re.split(response['Vary'])
+    else:
+        vary_headers = []
+    # Use .lower() here so we treat headers as case-insensitive.
+    existing_headers = set([header.lower() for header in vary_headers])
+    additional_headers = [newheader for newheader in newheaders
+                          if newheader.lower() not in existing_headers]
+    response['Vary'] = ', '.join(vary_headers + additional_headers)
 
 def _generate_cache_key(request, headerlist, key_prefix):
     """Returns a cache key from the headers given in the header list."""


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to