Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Corrected a typo and made some style fixes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6626 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d453eda38852b1fb4f10a03a467abae8ca4ae927 1 parent 26ea06b
Gary Wilson Jr. authored October 28, 2007

Showing 1 changed file with 14 additions and 10 deletions. Show diff stats Hide diff stats

  1. 24  django/utils/cache.py
24  django/utils/cache.py
@@ -13,7 +13,7 @@
13 13
 different header content for headers named in "Vary" need to get different
14 14
 cache keys to prevent delivery of wrong content.
15 15
 
16  
-A example: i18n middleware would need to distinguish caches by the
  16
+An example: i18n middleware would need to distinguish caches by the
17 17
 "Accept-language" header.
18 18
 """
19 19
 
@@ -21,6 +21,7 @@
21 21
 import re
22 22
 import time
23 23
 from email.Utils import formatdate
  24
+
24 25
 from django.conf import settings
25 26
 from django.core.cache import cache
26 27
 from django.utils.encoding import smart_str, iri_to_uri
@@ -40,7 +41,7 @@ def patch_cache_control(response, **kwargs):
40 41
       str() to it.
41 42
     """
42 43
     def dictitem(s):
43  
-        t = s.split('=',1)
  44
+        t = s.split('=', 1)
44 45
         if len(t) > 1:
45 46
             return (t[0].lower(), t[1])
46 47
         else:
@@ -64,7 +65,7 @@ def dictvalue(t):
64 65
     if 'max-age' in cc and 'max_age' in kwargs:
65 66
         kwargs['max_age'] = min(cc['max-age'], kwargs['max_age'])
66 67
 
67  
-    for (k,v) in kwargs.items():
  68
+    for (k, v) in kwargs.items():
68 69
         cc[k.replace('_', '-')] = v
69 70
     cc = ', '.join([dictvalue(el) for el in cc.items()])
70 71
     response['Cache-Control'] = cc
@@ -95,8 +96,7 @@ def patch_response_headers(response, cache_timeout=None):
95 96
 
96 97
 def add_never_cache_headers(response):
97 98
     """
98  
-    Add headers to a response to indicate that
99  
-    a page should never be cached.
  99
+    Adds headers to a response to indicate that a page should never be cached.
100 100
     """
101 101
     patch_response_headers(response, cache_timeout=-1)
102 102
 
@@ -119,13 +119,14 @@ def patch_vary_headers(response, newheaders):
119 119
     response['Vary'] = ', '.join(vary)
120 120
 
121 121
 def _generate_cache_key(request, headerlist, key_prefix):
122  
-    "Returns a cache key from the headers given in the header list."
  122
+    """Returns a cache key from the headers given in the header list."""
123 123
     ctx = md5.new()
124 124
     for header in headerlist:
125 125
         value = request.META.get(header, None)
126 126
         if value is not None:
127 127
             ctx.update(value)
128  
-    return 'views.decorators.cache.cache_page.%s.%s.%s' % (key_prefix, iri_to_uri(request.path), ctx.hexdigest())
  128
+    return 'views.decorators.cache.cache_page.%s.%s.%s' % (
  129
+               key_prefix, iri_to_uri(request.path), ctx.hexdigest())
129 130
 
130 131
 def get_cache_key(request, key_prefix=None):
131 132
     """
@@ -139,7 +140,8 @@ def get_cache_key(request, key_prefix=None):
139 140
     """
140 141
     if key_prefix is None:
141 142
         key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
142  
-    cache_key = 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, iri_to_uri(request.path))
  143
+    cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
  144
+                    key_prefix, iri_to_uri(request.path))
143 145
     headerlist = cache.get(cache_key, None)
144 146
     if headerlist is not None:
145 147
         return _generate_cache_key(request, headerlist, key_prefix)
@@ -163,9 +165,11 @@ def learn_cache_key(request, response, cache_timeout=None, key_prefix=None):
163 165
         key_prefix = settings.CACHE_MIDDLEWARE_KEY_PREFIX
164 166
     if cache_timeout is None:
165 167
         cache_timeout = settings.CACHE_MIDDLEWARE_SECONDS
166  
-    cache_key = 'views.decorators.cache.cache_header.%s.%s' % (key_prefix, iri_to_uri(request.path))
  168
+    cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
  169
+                    key_prefix, iri_to_uri(request.path))
167 170
     if response.has_header('Vary'):
168  
-        headerlist = ['HTTP_'+header.upper().replace('-', '_') for header in vary_delim_re.split(response['Vary'])]
  171
+        headerlist = ['HTTP_'+header.upper().replace('-', '_')
  172
+                      for header in vary_delim_re.split(response['Vary'])]
169 173
         cache.set(cache_key, headerlist, cache_timeout)
170 174
         return _generate_cache_key(request, headerlist, key_prefix)
171 175
     else:

0 notes on commit d453eda

Please sign in to comment.
Something went wrong with that request. Please try again.