Skip to content
This repository

A few pep-8 code cleanup fixes #17

Merged
merged 4 commits into from almost 2 years ago

2 participants

Chris Angove Ben Bangert
Chris Angove
cangove commented May 05, 2012

Fixing a few common pep-8 violations.

Ben Bangert
Owner

I'd love to apply this, but it doesn't cleanly apply. Can you rebase and make a pull request?

added some commits April 15, 2012
Pep8 the code
pep8 --fix --inplace --repeat --count --ignore=E501 beaker/beaker
54ba876
Pep8 fixes for has_key() ab01510
Correct typo introduced by bug in wgen/pep8 fda0177
Add .gitignore (what project does not have a .gitignore file?) af7456b
Chris Angove
cangove commented May 09, 2012

I rebase and resolved the conflict. Apparently great minds think alike and there were 2 commits with the addition of a .gitignore file. Should pull cleanly now.

Ben Bangert bbangert merged commit abf9ebf into from May 09, 2012
Ben Bangert bbangert closed this May 09, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 2 authors.

May 09, 2012
Pep8 the code
pep8 --fix --inplace --repeat --count --ignore=E501 beaker/beaker
54ba876
Pep8 fixes for has_key() ab01510
Correct typo introduced by bug in wgen/pep8 fda0177
Add .gitignore (what project does not have a .gitignore file?) af7456b
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -19,3 +19,4 @@ bookenv/
19 19
 jyenv/
20 20
 pypyenv/
21 21
 env*/
  22
+tests/test.db
58  beaker/cache.py
... ...
@@ -1,7 +1,7 @@
1 1
 """This package contains the "front end" classes and functions
2 2
 for Beaker caching.
3 3
 
4  
-Included are the :class:`.Cache` and :class:`.CacheManager` classes, 
  4
+Included are the :class:`.Cache` and :class:`.CacheManager` classes,
5 5
 as well as the function decorators :func:`.region_decorate`,
6 6
 :func:`.region_invalidate`.
7 7
 
@@ -23,7 +23,7 @@
23 23
 cache_regions = {}
24 24
 """Dictionary of 'region' arguments.
25 25
 
26  
-A "region" is a string name that refers to a series of cache 
  26
+A "region" is a string name that refers to a series of cache
27 27
 configuration arguments.    An application may have multiple
28 28
 "regions" - one which stores things in a memory cache, one
29 29
 which writes data to files, etc.
@@ -48,6 +48,7 @@
48 48
 
49 49
 cache_managers = {}
50 50
 
  51
+
51 52
 class _backends(object):
52 53
     initialized = False
53 54
 
@@ -100,19 +101,19 @@ def _init(self):
100 101
                         warnings.warn(
101 102
                             "Unable to load NamespaceManager "
102 103
                             "entry point: '%s': %s" % (
103  
-                                        entry_point, 
104  
-                                        tb.getvalue()), 
  104
+                                        entry_point,
  105
+                                        tb.getvalue()),
105 106
                                         RuntimeWarning, 2)
106 107
         except ImportError:
107 108
             pass
108 109
 
109 110
 # Initialize the basic available backends
110 111
 clsmap = _backends({
111  
-          'memory':container.MemoryNamespaceManager,
112  
-          'dbm':container.DBMNamespaceManager,
113  
-          'file':container.FileNamespaceManager,
114  
-          'ext:memcached':memcached.MemcachedNamespaceManager,
115  
-          'ext:database':database.DatabaseNamespaceManager,
  112
+          'memory': container.MemoryNamespaceManager,
  113
+          'dbm': container.DBMNamespaceManager,
  114
+          'file': container.FileNamespaceManager,
  115
+          'ext:memcached': memcached.MemcachedNamespaceManager,
  116
+          'ext:database': database.DatabaseNamespaceManager,
116 117
           'ext:sqla': sqla.SqlaNamespaceManager,
117 118
           'ext:google': google.GoogleNamespaceManager,
118 119
           })
@@ -125,7 +126,7 @@ def cache_region(region, *args):
125 126
     Example::
126 127
 
127 128
         from beaker.cache import cache_regions, cache_region
128  
-        
  129
+
129 130
         # configure regions
130 131
         cache_regions.update({
131 132
             'short_term':{
@@ -138,10 +139,10 @@ def cache_region(region, *args):
138 139
         def load(search_term, limit, offset):
139 140
             '''Load from a database given a search term, limit, offset.'''
140 141
             return database.query(search_term)[offset:offset + limit]
141  
-    
  142
+
142 143
     The decorator can also be used with object methods.  The ``self``
143  
-    argument is not part of the cache key.  This is based on the 
144  
-    actual string name ``self`` being in the first argument 
  144
+    argument is not part of the cache key.  This is based on the
  145
+    actual string name ``self`` being in the first argument
145 146
     position (new in 1.6)::
146 147
 
147 148
         class MyThing(object):
@@ -149,27 +150,27 @@ class MyThing(object):
149 150
             def load(self, search_term, limit, offset):
150 151
                 '''Load from a database given a search term, limit, offset.'''
151 152
                 return database.query(search_term)[offset:offset + limit]
152  
-    
  153
+
153 154
     Classmethods work as well - use ``cls`` as the name of the class argument,
154 155
     and place the decorator around the function underneath ``@classmethod``
155 156
     (new in 1.6)::
156  
-    
  157
+
157 158
         class MyThing(object):
158 159
             @classmethod
159 160
             @cache_region('short_term', 'load_things')
160 161
             def load(cls, search_term, limit, offset):
161 162
                 '''Load from a database given a search term, limit, offset.'''
162 163
                 return database.query(search_term)[offset:offset + limit]
163  
-    
  164
+
164 165
     :param region: String name of the region corresponding to the desired
165 166
       caching arguments, established in :attr:`.cache_regions`.
166  
-      
  167
+
167 168
     :param \*args: Optional ``str()``-compatible arguments which will uniquely
168 169
       identify the key used by this decorated function, in addition
169 170
       to the positional arguments passed to the function itself at call time.
170 171
       This is recommended as it is needed to distinguish between any two functions
171 172
       or methods that have the same name (regardless of parent class or not).
172  
-      
  173
+
173 174
     .. note::
174 175
 
175 176
         The function being decorated must only be called with
@@ -180,14 +181,15 @@ def load(cls, search_term, limit, offset):
180 181
         forms the unique cache key.
181 182
 
182 183
     .. note::
183  
-    
  184
+
184 185
         When a method on a class is decorated, the ``self`` or ``cls``
185 186
         argument in the first position is
186 187
         not included in the "key" used for caching.   New in 1.6.
187  
-        
  188
+
188 189
     """
189 190
     return _cache_decorate(args, None, None, region)
190 191
 
  192
+
191 193
 def region_invalidate(namespace, region, *args):
192 194
     """Invalidate a cache region corresponding to a function
193 195
     decorated with :func:`.cache_region`.
@@ -209,7 +211,7 @@ def region_invalidate(namespace, region, *args):
209 211
     Example::
210 212
 
211 213
         from beaker.cache import cache_regions, cache_region, region_invalidate
212  
-        
  214
+
213 215
         # configure regions
214 216
         cache_regions.update({
215 217
             'short_term':{
@@ -226,11 +228,11 @@ def load(search_term, limit, offset):
226 228
         def invalidate_search(search_term, limit, offset):
227 229
             '''Invalidate the cached storage for a given search term, limit, offset.'''
228 230
             region_invalidate(load, 'short_term', 'load_data', search_term, limit, offset)
229  
-    
  231
+
230 232
     Note that when a method on a class is decorated, the first argument ``cls``
231 233
     or ``self`` is not included in the cache key.  This means you don't send
232 234
     it to :func:`.region_invalidate`::
233  
-    
  235
+
234 236
         class MyThing(object):
235 237
             @cache_region('short_term', 'some_data')
236 238
             def load(self, search_term, limit, offset):
@@ -240,7 +242,7 @@ def load(self, search_term, limit, offset):
240 242
             def invalidate_search(self, search_term, limit, offset):
241 243
                 '''Invalidate the cached storage for a given search term, limit, offset.'''
242 244
                 region_invalidate(self.load, 'short_term', 'some_data', search_term, limit, offset)
243  
-        
  245
+
244 246
     """
245 247
     if callable(namespace):
246 248
         if not region:
@@ -331,7 +333,7 @@ def _legacy_get_value(self, key, type, **kw):
331 333
         kwargs = self.nsargs.copy()
332 334
         kwargs.update(kw)
333 335
         c = Cache(self.namespace.namespace, type=type, **kwargs)
334  
-        return c._get_value(key, expiretime=expiretime, createfunc=createfunc, 
  336
+        return c._get_value(key, expiretime=expiretime, createfunc=createfunc,
335 337
                             starttime=starttime)
336 338
 
337 339
     def clear(self):
@@ -474,7 +476,7 @@ def load(search_term, limit, offset):
474 476
         .. note::
475 477
 
476 478
             The function being decorated must only be called with
477  
-            positional arguments. 
  479
+            positional arguments.
478 480
 
479 481
         """
480 482
         return _cache_decorate(args, self, kwargs, None)
@@ -521,6 +523,7 @@ def load(search_term, limit, offset):
521 523
             key_length = kwargs.pop('key_length', 250)
522 524
         _cache_decorator_invalidate(cache, key_length, args)
523 525
 
  526
+
524 527
 def _cache_decorate(deco_args, manager, kwargs, region):
525 528
     """Return a caching function decorator."""
526 529
 
@@ -529,6 +532,7 @@ def _cache_decorate(deco_args, manager, kwargs, region):
529 532
     def decorate(func):
530 533
         namespace = util.func_namespace(func)
531 534
         skip_self = util.has_self_arg(func)
  535
+
532 536
         def cached(*args):
533 537
             if not cache[0]:
534 538
                 if region is not None:
@@ -561,6 +565,7 @@ def cached(*args):
561 565
                 key_length = kwargs.pop('key_length', 250)
562 566
             if len(cache_key) + len(namespace) > key_length:
563 567
                 cache_key = sha1(cache_key).hexdigest()
  568
+
564 569
             def go():
565 570
                 return func(*args)
566 571
 
@@ -571,6 +576,7 @@ def go():
571 576
         return cached
572 577
     return decorate
573 578
 
  579
+
574 580
 def _cache_decorator_invalidate(cache, key_length, args):
575 581
     """Invalidate a cache key based on function arguments."""
576 582
 
145  beaker/container.py
@@ -35,9 +35,9 @@ def debug(message, *args):
35 35
 class NamespaceManager(object):
36 36
     """Handles dictionary operations and locking for a namespace of
37 37
     values.
38  
-    
  38
+
39 39
     :class:`.NamespaceManager` provides a dictionary-like interface,
40  
-    implementing ``__getitem__()``, ``__setitem__()``, and 
  40
+    implementing ``__getitem__()``, ``__setitem__()``, and
41 41
     ``__contains__()``, as well as functions related to lock
42 42
     acquisition.
43 43
 
@@ -65,7 +65,6 @@ def _init_dependencies(cls):
65 65
         """Initialize module-level dependent libraries required
66 66
         by this :class:`.NamespaceManager`."""
67 67
 
68  
-
69 68
     def __init__(self, namespace):
70 69
         self._init_dependencies()
71 70
         self.namespace = namespace
@@ -74,35 +73,35 @@ def get_creation_lock(self, key):
74 73
         """Return a locking object that is used to synchronize
75 74
         multiple threads or processes which wish to generate a new
76 75
         cache value.
77  
-        
  76
+
78 77
         This function is typically an instance of
79 78
         :class:`.FileSynchronizer`, :class:`.ConditionSynchronizer`,
80  
-        or :class:`.null_synchronizer`.   
81  
-        
  79
+        or :class:`.null_synchronizer`.
  80
+
82 81
         The creation lock is only used when a requested value
83 82
         does not exist, or has been expired, and is only used
84 83
         by the :class:`.Value` key-management object in conjunction
85 84
         with a "createfunc" value-creation function.
86  
-        
  85
+
87 86
         """
88 87
         raise NotImplementedError()
89 88
 
90 89
     def do_remove(self):
91  
-        """Implement removal of the entire contents of this 
  90
+        """Implement removal of the entire contents of this
92 91
         :class:`.NamespaceManager`.
93  
-        
  92
+
94 93
         e.g. for a file-based namespace, this would remove
95 94
         all the files.
96  
-        
  95
+
97 96
         The front-end to this method is the
98 97
         :meth:`.NamespaceManager.remove` method.
99  
-        
  98
+
100 99
         """
101 100
         raise NotImplementedError()
102 101
 
103 102
     def acquire_read_lock(self):
104 103
         """Establish a read lock.
105  
-        
  104
+
106 105
         This operation is called before a key is read.    By
107 106
         default the function does nothing.
108 107
 
@@ -110,7 +109,7 @@ def acquire_read_lock(self):
110 109
 
111 110
     def release_read_lock(self):
112 111
         """Release a read lock.
113  
-        
  112
+
114 113
         This operation is called after a key is read.    By
115 114
         default the function does nothing.
116 115
 
@@ -118,31 +117,31 @@ def release_read_lock(self):
118 117
 
119 118
     def acquire_write_lock(self, wait=True, replace=False):
120 119
         """Establish a write lock.
121  
-        
122  
-        This operation is called before a key is written.   
123  
-        A return value of ``True`` indicates the lock has 
  120
+
  121
+        This operation is called before a key is written.
  122
+        A return value of ``True`` indicates the lock has
124 123
         been acquired.
125  
-        
  124
+
126 125
         By default the function returns ``True`` unconditionally.
127  
-        
  126
+
128 127
         'replace' is a hint indicating the full contents
129 128
         of the namespace may be safely discarded. Some backends
130  
-        may implement this (i.e. file backend won't unpickle the 
  129
+        may implement this (i.e. file backend won't unpickle the
131 130
         current contents).
132  
-        
  131
+
133 132
         """
134 133
         return True
135 134
 
136 135
     def release_write_lock(self):
137 136
         """Release a write lock.
138  
-        
  137
+
139 138
         This operation is called after a new value is written.
140 139
         By default this function does nothing.
141  
-        
  140
+
142 141
         """
143 142
 
144 143
     def has_key(self, key):
145  
-        """Return ``True`` if the given key is present in this 
  144
+        """Return ``True`` if the given key is present in this
146 145
         :class:`.Namespace`.
147 146
         """
148 147
         return self.__contains__(key)
@@ -155,7 +154,7 @@ def __setitem__(self, key, value):
155 154
 
156 155
     def set_value(self, key, value, expiretime=None):
157 156
         """Sets a value in this :class:`.NamespaceManager`.
158  
-        
  157
+
159 158
         This is the same as ``__setitem__()``, but
160 159
         also allows an expiration time to be passed
161 160
         at the same time.
@@ -171,17 +170,17 @@ def __delitem__(self, key):
171 170
 
172 171
     def keys(self):
173 172
         """Return the list of all keys.
174  
-        
  173
+
175 174
         This method may not be supported by all
176 175
         :class:`.NamespaceManager` implementations.
177  
-        
  176
+
178 177
         """
179 178
         raise NotImplementedError()
180 179
 
181 180
     def remove(self):
182  
-        """Remove the entire contents of this 
  181
+        """Remove the entire contents of this
183 182
         :class:`.NamespaceManager`.
184  
-        
  183
+
185 184
         e.g. for a file-based namespace, this would remove
186 185
         all the files.
187 186
         """
@@ -202,37 +201,37 @@ def __init__(self, namespace):
202 201
     def get_access_lock(self):
203 202
         raise NotImplementedError()
204 203
 
205  
-    def do_open(self, flags, replace): 
  204
+    def do_open(self, flags, replace):
206 205
         raise NotImplementedError()
207 206
 
208  
-    def do_close(self): 
  207
+    def do_close(self):
209 208
         raise NotImplementedError()
210 209
 
211  
-    def acquire_read_lock(self): 
  210
+    def acquire_read_lock(self):
212 211
         self.access_lock.acquire_read_lock()
213 212
         try:
214  
-            self.open('r', checkcount = True)
  213
+            self.open('r', checkcount=True)
215 214
         except:
216 215
             self.access_lock.release_read_lock()
217 216
             raise
218 217
 
219 218
     def release_read_lock(self):
220 219
         try:
221  
-            self.close(checkcount = True)
  220
+            self.close(checkcount=True)
222 221
         finally:
223 222
             self.access_lock.release_read_lock()
224 223
 
225  
-    def acquire_write_lock(self, wait=True, replace=False): 
  224
+    def acquire_write_lock(self, wait=True, replace=False):
226 225
         r = self.access_lock.acquire_write_lock(wait)
227 226
         try:
228  
-            if (wait or r): 
229  
-                self.open('c', checkcount = True, replace=replace)
  227
+            if (wait or r):
  228
+                self.open('c', checkcount=True, replace=replace)
230 229
             return r
231 230
         except:
232 231
             self.access_lock.release_write_lock()
233 232
             raise
234 233
 
235  
-    def release_write_lock(self): 
  234
+    def release_write_lock(self):
236 235
         try:
237 236
             self.close(checkcount=True)
238 237
         finally:
@@ -242,7 +241,7 @@ def open(self, flags, checkcount=False, replace=False):
242 241
         self.mutex.acquire()
243 242
         try:
244 243
             if checkcount:
245  
-                if self.openers == 0: 
  244
+                if self.openers == 0:
246 245
                     self.do_open(flags, replace)
247 246
                 self.openers += 1
248 247
             else:
@@ -256,7 +255,7 @@ def close(self, checkcount=False):
256 255
         try:
257 256
             if checkcount:
258 257
                 self.openers -= 1
259  
-                if self.openers == 0: 
  258
+                if self.openers == 0:
260 259
                     self.do_close()
261 260
             else:
262 261
                 if self.openers > 0:
@@ -273,6 +272,7 @@ def remove(self):
273 272
         finally:
274 273
             self.access_lock.release_write_lock()
275 274
 
  275
+
276 276
 class Value(object):
277 277
     """Implements synchronization, expiration, and value-creation logic
278 278
     for a single value stored in a :class:`.NamespaceManager`.
@@ -298,7 +298,7 @@ def has_value(self):
298 298
         """
299 299
         self.namespace.acquire_read_lock()
300 300
         try:
301  
-            return self.namespace.has_key(self.key)
  301
+            return self.key in self.namespace
302 302
         finally:
303 303
             self.namespace.release_read_lock()
304 304
 
@@ -308,7 +308,7 @@ def can_have_value(self):
308 308
     def has_current_value(self):
309 309
         self.namespace.acquire_read_lock()
310 310
         try:
311  
-            has_value = self.namespace.has_key(self.key)
  311
+            has_value = self.key in self.namespace
312 312
             if has_value:
313 313
                 try:
314 314
                     stored, expired, value = self._get_value()
@@ -404,8 +404,8 @@ def _get_value(self):
404 404
             self.set_value(value, stored)
405 405
             self.namespace.acquire_read_lock()
406 406
         except TypeError:
407  
-            # occurs when the value is None.  memcached 
408  
-            # may yank the rug from under us in which case 
  407
+            # occurs when the value is None.  memcached
  408
+            # may yank the rug from under us in which case
409 409
             # that's the result
410 410
             raise KeyError(self.key)
411 411
         return stored, expired, value
@@ -424,7 +424,7 @@ def clear_value(self):
424 424
         self.namespace.acquire_write_lock()
425 425
         try:
426 426
             debug("clear_value")
427  
-            if self.namespace.has_key(self.key):
  427
+            if self.key in self.namespace:
428 428
                 try:
429 429
                     del self.namespace[self.key]
430 430
                 except KeyError:
@@ -434,6 +434,7 @@ def clear_value(self):
434 434
         finally:
435 435
             self.namespace.release_write_lock()
436 436
 
  437
+
437 438
 class AbstractDictionaryNSManager(NamespaceManager):
438 439
     """A subclassable NamespaceManager that places data in a dictionary.
439 440
 
@@ -461,18 +462,18 @@ def __init__(self, namespace):
461 462
 
462 463
     def get_creation_lock(self, key):
463 464
         return NameLock(
464  
-            identifier="memorynamespace/funclock/%s/%s" % 
  465
+            identifier="memorynamespace/funclock/%s/%s" %
465 466
                         (self.namespace, key),
466 467
             reentrant=True
467 468
         )
468 469
 
469  
-    def __getitem__(self, key): 
  470
+    def __getitem__(self, key):
470 471
         return self.dictionary[key]
471 472
 
472  
-    def __contains__(self, key): 
  473
+    def __contains__(self, key):
473 474
         return self.dictionary.__contains__(key)
474 475
 
475  
-    def has_key(self, key): 
  476
+    def has_key(self, key):
476 477
         return self.dictionary.__contains__(key)
477 478
 
478 479
     def __setitem__(self, key, value):
@@ -487,6 +488,7 @@ def do_remove(self):
487 488
     def keys(self):
488 489
         return self.dictionary.keys()
489 490
 
  491
+
490 492
 class MemoryNamespaceManager(AbstractDictionaryNSManager):
491 493
     """:class:`.NamespaceManager` that uses a Python dictionary for storage."""
492 494
 
@@ -497,11 +499,12 @@ def __init__(self, namespace, **kwargs):
497 499
         self.dictionary = MemoryNamespaceManager.\
498 500
                                 namespaces.get(self.namespace, dict)
499 501
 
  502
+
500 503
 class DBMNamespaceManager(OpenResourceNamespaceManager):
501 504
     """:class:`.NamespaceManager` that uses ``dbm`` files for storage."""
502 505
 
503  
-    def __init__(self, namespace, dbmmodule=None, data_dir=None, 
504  
-            dbm_dir=None, lock_dir=None, 
  506
+    def __init__(self, namespace, dbmmodule=None, data_dir=None,
  507
+            dbm_dir=None, lock_dir=None,
505 508
             digest_filenames=True, **kwargs):
506 509
         self.digest_filenames = digest_filenames
507 510
 
@@ -526,7 +529,7 @@ def __init__(self, namespace, dbmmodule=None, data_dir=None,
526 529
         self.dbm = None
527 530
         OpenResourceNamespaceManager.__init__(self, namespace)
528 531
 
529  
-        self.file = util.encoded_path(root= self.dbm_dir,
  532
+        self.file = util.encoded_path(root=self.dbm_dir,
530 533
                                       identifiers=[self.namespace],
531 534
                                       extension='.dbm',
532 535
                                       digest_filenames=self.digest_filenames)
@@ -540,14 +543,14 @@ def get_access_lock(self):
540 543
 
541 544
     def get_creation_lock(self, key):
542 545
         return file_synchronizer(
543  
-                    identifier = "dbmcontainer/funclock/%s/%s" % (
  546
+                    identifier="dbmcontainer/funclock/%s/%s" % (
544 547
                         self.namespace, key
545 548
                     ),
546 549
                     lock_dir=self.lock_dir
547 550
                 )
548 551
 
549 552
     def file_exists(self, file):
550  
-        if os.access(file, os.F_OK): 
  553
+        if os.access(file, os.F_OK):
551 554
             return True
552 555
         else:
553 556
             for ext in ('db', 'dat', 'pag', 'dir'):
@@ -558,7 +561,7 @@ def file_exists(self, file):
558 561
 
559 562
     def _checkfile(self):
560 563
         if not self.file_exists(self.file):
561  
-            g = self.dbmmodule.open(self.file, 'c') 
  564
+            g = self.dbmmodule.open(self.file, 'c')
562 565
             g.close()
563 566
 
564 567
     def get_filenames(self):
@@ -588,11 +591,11 @@ def do_remove(self):
588 591
         for f in self.get_filenames():
589 592
             os.remove(f)
590 593
 
591  
-    def __getitem__(self, key): 
  594
+    def __getitem__(self, key):
592 595
         return cPickle.loads(self.dbm[key])
593 596
 
594  
-    def __contains__(self, key): 
595  
-        return self.dbm.has_key(key)
  597
+    def __contains__(self, key):
  598
+        return key in self.dbm
596 599
 
597 600
     def __setitem__(self, key, value):
598 601
         self.dbm[key] = cPickle.dumps(value)
@@ -606,11 +609,11 @@ def keys(self):
606 609
 
607 610
 class FileNamespaceManager(OpenResourceNamespaceManager):
608 611
     """:class:`.NamespaceManager` that uses binary files for storage.
609  
-    
610  
-    Each namespace is implemented as a single file storing a 
  612
+
  613
+    Each namespace is implemented as a single file storing a
611 614
     dictionary of key/value pairs, serialized using the Python
612 615
     ``pickle`` module.
613  
-    
  616
+
614 617
     """
615 618
     def __init__(self, namespace, data_dir=None, file_dir=None, lock_dir=None,
616 619
                  digest_filenames=True, **kwargs):
@@ -633,7 +636,7 @@ def __init__(self, namespace, data_dir=None, file_dir=None, lock_dir=None,
633 636
         util.verify_directory(self.lock_dir)
634 637
         OpenResourceNamespaceManager.__init__(self, namespace)
635 638
 
636  
-        self.file = util.encoded_path(root=self.file_dir, 
  639
+        self.file = util.encoded_path(root=self.file_dir,
637 640
                                       identifiers=[self.namespace],
638 641
                                       extension='.cache',
639 642
                                       digest_filenames=self.digest_filenames)
@@ -647,10 +650,10 @@ def get_access_lock(self):
647 650
 
648 651
     def get_creation_lock(self, key):
649 652
         return file_synchronizer(
650  
-                identifier = "dbmcontainer/funclock/%s/%s" % (
  653
+                identifier="dbmcontainer/funclock/%s/%s" % (
651 654
                     self.namespace, key
652 655
                 ),
653  
-                lock_dir = self.lock_dir
  656
+                lock_dir=self.lock_dir
654 657
                 )
655 658
 
656 659
     def file_exists(self, file):
@@ -682,11 +685,11 @@ def do_remove(self):
682 685
             pass
683 686
         self.hash = {}
684 687
 
685  
-    def __getitem__(self, key): 
  688
+    def __getitem__(self, key):
686 689
         return self.hash[key]
687 690
 
688  
-    def __contains__(self, key): 
689  
-        return self.hash.has_key(key)
  691
+    def __contains__(self, key):
  692
+        return key in self.hash
690 693
 
691 694
     def __setitem__(self, key, value):
692 695
         self.hash[key] = value
@@ -704,10 +707,12 @@ def keys(self):
704 707
 
705 708
 ContainerContext = dict
706 709
 
  710
+
707 711
 class ContainerMeta(type):
708 712
     def __init__(cls, classname, bases, dict_):
709 713
         namespace_classes[cls] = cls.namespace_class
710 714
         return type.__init__(cls, classname, bases, dict_)
  715
+
711 716
     def __call__(self, key, context, namespace, createfunc=None,
712 717
                  expiretime=None, starttime=None, **kwargs):
713 718
         if namespace in context:
@@ -718,23 +723,27 @@ def __call__(self, key, context, namespace, createfunc=None,
718 723
         return Value(key, ns, createfunc=createfunc,
719 724
                      expiretime=expiretime, starttime=starttime)
720 725
 
  726
+
721 727
 class Container(object):
722 728
     """Implements synchronization and value-creation logic
723 729
     for a 'value' stored in a :class:`.NamespaceManager`.
724  
-    
  730
+
725 731
     :class:`.Container` and its subclasses are deprecated.   The
726 732
     :class:`.Value` class is now used for this purpose.
727  
-    
  733
+
728 734
     """
729 735
     __metaclass__ = ContainerMeta
730 736
     namespace_class = NamespaceManager
731 737
 
  738
+
732 739
 class FileContainer(Container):
733 740
     namespace_class = FileNamespaceManager
734 741
 
  742
+
735 743
 class MemoryContainer(Container):
736 744
     namespace_class = MemoryNamespaceManager
737 745
 
  746
+
738 747
 class DBMContainer(Container):
739 748
     namespace_class = DBMNamespaceManager
740 749
 
3  beaker/converters.py
... ...
@@ -1,3 +1,5 @@
  1
+
  2
+
1 3
 # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
2 4
 # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
3 5
 def asbool(obj):
@@ -12,6 +14,7 @@ def asbool(obj):
12 14
                 "String is not true/false: %r" % obj)
13 15
     return bool(obj)
14 16
 
  17
+
15 18
 def aslist(obj, sep=None, strip=True):
16 19
     if isinstance(obj, (str, unicode)):
17 20
         lst = obj.split(sep)
2  beaker/crypto/jcecrypto.py
@@ -16,6 +16,7 @@
16 16
 # Initialization vector filled with zeros
17 17
 _iv = IvParameterSpec(jarray.zeros(16, 'b'))
18 18
 
  19
+
19 20
 def aesEncrypt(data, key):
20 21
     cipher = Cipher.getInstance('AES/CTR/NoPadding')
21 22
     skeySpec = SecretKeySpec(key, 'AES')
@@ -25,6 +26,7 @@ def aesEncrypt(data, key):
25 26
 # magic.
26 27
 aesDecrypt = aesEncrypt
27 28
 
  29
+
28 30
 def getKeyLength():
29 31
     maxlen = Cipher.getMaxAllowedKeyLength('AES/CTR/NoPadding')
30 32
     return min(maxlen, 256) / 8
31  beaker/crypto/pbkdf2.py
@@ -5,22 +5,22 @@
5 5
 #
6 6
 # Copyright (C) 2007 Dwayne C. Litzenberger <dlitz@dlitz.net>
7 7
 # All rights reserved.
8  
-# 
  8
+#
9 9
 # Permission to use, copy, modify, and distribute this software and its
10 10
 # documentation for any purpose and without fee is hereby granted,
11 11
 # provided that the above copyright notice appear in all copies and that
12 12
 # both that copyright notice and this permission notice appear in
13 13
 # supporting documentation.
14  
-# 
15  
-# THE AUTHOR PROVIDES THIS SOFTWARE ``AS IS'' AND ANY EXPRESSED OR 
16  
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
  14
+#
  15
+# THE AUTHOR PROVIDES THIS SOFTWARE ``AS IS'' AND ANY EXPRESSED OR
  16
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 17
 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
  18
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 19
 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
21  
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
22  
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
23  
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
  20
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 24
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 25
 #
26 26
 # Country of origin: Canada
@@ -74,9 +74,11 @@
74 74
 
75 75
 from beaker.crypto.util import hmac as HMAC, hmac_sha1 as SHA1
76 76
 
  77
+
77 78
 def strxor(a, b):
78 79
     return "".join([chr(ord(x) ^ ord(y)) for (x, y) in zip(a, b)])
79 80
 
  81
+
80 82
 class PBKDF2(object):
81 83
     """PBKDF2.py : PKCS#5 v2.0 Password-Based Key Derivation
82 84
 
@@ -121,7 +123,7 @@ def read(self, bytes):
121 123
         while size < bytes:
122 124
             i += 1
123 125
             if i > 0xffffffff:
124  
-                # We could return "" here, but 
  126
+                # We could return "" here, but
125 127
                 raise OverflowError("derived key too long")
126 128
             block = self.__f(i)
127 129
             blocks.append(block)
@@ -137,7 +139,7 @@ def __f(self, i):
137 139
         assert (1 <= i and i <= 0xffffffff)
138 140
         U = self.__prf(self.__passphrase, self.__salt + pack("!L", i))
139 141
         result = U
140  
-        for j in xrange(2, 1+self.__iterations):
  142
+        for j in xrange(2, 1 + self.__iterations):
141 143
             U = self.__prf(self.__passphrase, U)
142 144
             result = strxor(result, U)
143 145
         return result
@@ -192,6 +194,7 @@ def close(self):
192 194
             del self.__buf
193 195
             self.closed = True
194 196
 
  197
+
195 198
 def crypt(word, salt=None, iterations=None):
196 199
     """PBKDF2-based unix crypt(3) replacement.
197 200
 
@@ -249,6 +252,7 @@ def crypt(word, salt=None, iterations=None):
249 252
 # crypt.
250 253
 PBKDF2.crypt = staticmethod(crypt)
251 254
 
  255
+
252 256
 def _makesalt():
253 257
     """Return a 48-bit pseudorandom salt for crypt().
254 258
 
@@ -257,6 +261,7 @@ def _makesalt():
257 261
     binarysalt = "".join([pack("@H", randint(0, 0xffff)) for i in range(3)])
258 262
     return b64encode(binarysalt, "./")
259 263
 
  264
+
260 265
 def test_pbkdf2():
261 266
     """Module self-test"""
262 267
     from binascii import a2b_hex
@@ -279,14 +284,14 @@ def test_pbkdf2():
279 284
         raise RuntimeError("self-test failed")
280 285
 
281 286
     # Test 3
282  
-    result = PBKDF2("X"*64, "pass phrase equals block size", 1200).hexread(32)
  287
+    result = PBKDF2("X" * 64, "pass phrase equals block size", 1200).hexread(32)
283 288
     expected = ("139c30c0966bc32ba55fdbf212530ac9"
284 289
                 "c5ec59f1a452f5cc9ad940fea0598ed1")
285 290
     if result != expected:
286 291
         raise RuntimeError("self-test failed")
287 292
 
288 293
     # Test 4
289  
-    result = PBKDF2("X"*65, "pass phrase exceeds block size", 1200).hexread(32)
  294
+    result = PBKDF2("X" * 65, "pass phrase exceeds block size", 1200).hexread(32)
290 295
     expected = ("9ccad6d468770cd51b10e6a68721be61"
291 296
                 "1a8b4d282601db3b36be9246915ec82a")
292 297
     if result != expected:
1  beaker/crypto/pycrypto.py
@@ -27,5 +27,6 @@ def aesDecrypt(data, key):
27 27
 
28 28
         return cipher.decrypt(data).rstrip()
29 29
 
  30
+
30 31
 def getKeyLength():
31 32
     return 32
3  beaker/docs/conf.py
@@ -11,7 +11,8 @@
11 11
 # All configuration values have a default; values that are commented out
12 12
 # serve to show the default.
13 13
 
14  
-import sys, os
  14
+import sys
  15
+import os
15 16
 
16 17
 # If your extensions are in another directory, add it here. If the directory
17 18
 # is relative to the documentation root, use os.path.abspath to make it
2  beaker/exceptions.py
... ...
@@ -1,5 +1,6 @@
1 1
 """Beaker exception classes"""
2 2
 
  3
+
3 4
 class BeakerException(Exception):
4 5
     pass
5 6
 
@@ -7,6 +8,7 @@ class BeakerException(Exception):
7 8
 class BeakerWarning(RuntimeWarning):
8 9
     """Issued at runtime."""
9 10
 
  11
+
10 12
 class CreationAbortedError(Exception):
11 13
     """Deprecated."""
12 14
 
22  beaker/ext/database.py
@@ -14,6 +14,7 @@
14 14
 pool = None
15 15
 types = None
16 16
 
  17
+
17 18
 class DatabaseNamespaceManager(OpenResourceNamespaceManager):
18 19
     metadatas = SyncDict()
19 20
     tables = SyncDict()
@@ -65,9 +66,11 @@ def __init__(self, namespace, url=None, sa_opts=None, optimistic=False,
65 66
         # Check to see if the table's been created before
66 67
         url = url or sa_opts['sa.url']
67 68
         table_key = url + table_name
  69
+
68 70
         def make_cache():
69 71
             # Check to see if we have a connection pool open already
70 72
             meta_key = url + table_name
  73
+
71 74
             def make_meta():
72 75
                 # SQLAlchemy pops the url, this ensures it sticks around
73 76
                 # later
@@ -99,10 +102,10 @@ def get_access_lock(self):
99 102
 
100 103
     def get_creation_lock(self, key):
101 104
         return file_synchronizer(
102  
-            identifier ="databasecontainer/funclock/%s/%s" % (
  105
+            identifier="databasecontainer/funclock/%s/%s" % (
103 106
                 self.namespace, key
104 107
             ),
105  
-            lock_dir = self.lock_dir)
  108
+            lock_dir=self.lock_dir)
106 109
 
107 110
     def do_open(self, flags, replace):
108 111
         # If we already loaded the data, don't bother loading it again
@@ -111,8 +114,8 @@ def do_open(self, flags, replace):
111 114
             return
112 115
 
113 116
         cache = self.cache
114  
-        result = sa.select([cache.c.data], 
115  
-                           cache.c.namespace==self.namespace
  117
+        result = sa.select([cache.c.data],
  118
+                           cache.c.namespace == self.namespace
116 119
                           ).execute().fetchone()
117 120
         if not result:
118 121
             self._is_new = True
@@ -138,24 +141,24 @@ def do_close(self):
138 141
                                        created=datetime.now())
139 142
                 self._is_new = False
140 143
             else:
141  
-                cache.update(cache.c.namespace==self.namespace).execute(
  144
+                cache.update(cache.c.namespace == self.namespace).execute(
142 145
                     data=self.hash, accessed=datetime.now())
143 146
         self.flags = None
144 147
 
145 148
     def do_remove(self):
146 149
         cache = self.cache
147  
-        cache.delete(cache.c.namespace==self.namespace).execute()
  150
+        cache.delete(cache.c.namespace == self.namespace).execute()
148 151
         self.hash = {}
149 152
 
150 153
         # We can retain the fact that we did a load attempt, but since the
151 154
         # file is gone this will be a new namespace should it be saved.
152 155
         self._is_new = True
153 156
 
154  
-    def __getitem__(self, key): 
  157
+    def __getitem__(self, key):
155 158
         return self.hash[key]
156 159
 
157  
-    def __contains__(self, key): 
158  
-        return self.hash.has_key(key)
  160
+    def __contains__(self, key):
  161
+        return key in self.hash
159 162
 
160 163
     def __setitem__(self, key, value):
161 164
         self.hash[key] = value
@@ -166,5 +169,6 @@ def __delitem__(self, key):
166 169
     def keys(self):
167 170
         return self.hash.keys()
168 171
 
  172
+
169 173
 class DatabaseContainer(Container):
170 174
     namespace_manager = DatabaseNamespaceManager
5  beaker/ext/google.py
@@ -10,6 +10,7 @@
10 10
 
11 11
 db = None
12 12
 
  13
+
13 14
 class GoogleNamespaceManager(OpenResourceNamespaceManager):
14 15
     tables = {}
15 16
 
@@ -103,8 +104,8 @@ def do_remove(self):
103 104
     def __getitem__(self, key):
104 105
         return self.hash[key]
105 106
 
106  
-    def __contains__(self, key): 
107  
-        return self.hash.has_key(key)
  107
+    def __contains__(self, key):
  108
+        return key in self.hash
108 109
 
109 110
     def __setitem__(self, key, value):
110 111
         self.hash[key] = value
8  beaker/ext/memcached.py
@@ -146,9 +146,9 @@ def keys(self):
146 146
 class PyLibMCNamespaceManager(MemcachedNamespaceManager):
147 147
     """Provide thread-local support for pylibmc."""
148 148
 
149  
-    def __init__(self, *arg, **kw):        
  149
+    def __init__(self, *arg, **kw):
150 150
         super(PyLibMCNamespaceManager, self).__init__(*arg, **kw)
151  
-        
  151
+
152 152
         memcache_module = kw.get('memcache_module', 'auto')
153 153
         _memcache_module = _client_libs[memcache_module]
154 154
         protocol = kw.get('protocol', 'text')
@@ -160,8 +160,8 @@ def __init__(self, *arg, **kw):
160 160
         self.mc = MemcachedNamespaceManager.clients.get(
161 161
                         (memcache_module, url),
162 162
                         _memcache_module.Client,
163  
-                        servers=url.split(';'), behaviors=behaviors, 
164  
-                        binary=(protocol=='binary'), username=username,
  163
+                        servers=url.split(';'), behaviors=behaviors,
  164
+                        binary=(protocol == 'binary'), username=username,
165 165
                         password=password)
166 166
         self.pool = pylibmc.ThreadMappedPool(self.mc)
167 167
 
6  beaker/ext/sqla.py
@@ -13,6 +13,7 @@
13 13
 
14 14
 sa = None
15 15
 
  16
+
16 17
 class SqlaNamespaceManager(OpenResourceNamespaceManager):
17 18
     binds = SyncDict()
18 19
     tables = SyncDict()
@@ -61,7 +62,7 @@ def get_access_lock(self):
61 62
 
62 63
     def get_creation_lock(self, key):
63 64
         return file_synchronizer(
64  
-            identifier ="databasecontainer/funclock/%s" % self.namespace,
  65
+            identifier="databasecontainer/funclock/%s" % self.namespace,
65 66
             lock_dir=self.lock_dir)
66 67
 
67 68
     def do_open(self, flags, replace):
@@ -108,7 +109,7 @@ def __getitem__(self, key):
108 109
         return self.hash[key]
109 110
 
110 111
     def __contains__(self, key):
111  
-        return self.hash.has_key(key)
  112
+        return key in self.hash
112 113
 
113 114
     def __setitem__(self, key, value):
114 115
         self.hash[key] = value
@@ -123,6 +124,7 @@ def keys(self):
123 124
 class SqlaContainer(Container):
124 125
     namespace_manager = SqlaNamespaceManager
125 126
 
  127
+
126 128
 def make_cache_table(metadata, table_name='beaker_cache', schema_name=None):
127 129
     """Return a ``Table`` object suitable for storing cached values for the
128 130
     namespace manager.  Do not create the table."""
6  beaker/middleware.py
@@ -105,8 +105,8 @@ def __init__(self, wrap_app, config=None, environ_key='beaker.session',
105 105
         config = config or {}
106 106
 
107 107
         # Load up the default params
108  
-        self.options = dict(invalidate_corrupt=True, type=None, 
109  
-                           data_dir=None, key='beaker.session.id', 
  108
+        self.options = dict(invalidate_corrupt=True, type=None,
  109
+                           data_dir=None, key='beaker.session.id',
110 110
                            timeout=None, secret=None, log_file=None)
111 111
 
112 112
         # Pull out any config args meant for beaker session. if there are any
@@ -144,7 +144,7 @@ def __call__(self, environ, start_response):
144 144
         if 'paste.testing_variables' in environ and 'webtest_varname' in self.options:
145 145
             environ['paste.testing_variables'][self.options['webtest_varname']] = session
146 146
 
147  
-        def session_start_response(status, headers, exc_info = None):
  147
+        def session_start_response(status, headers, exc_info=None):
148 148
             if session.accessed():
149 149
                 session.persist()
150 150
                 if session.__dict__['_headers']['set_cookie']:
52  beaker/synchronization.py
@@ -29,7 +29,7 @@
29 29
 from beaker import util
30 30
 from beaker.exceptions import LockError
31 31
 
32  
-__all__  = ["file_synchronizer", "mutex_synchronizer", "null_synchronizer",
  32
+__all__ = ["file_synchronizer", "mutex_synchronizer", "null_synchronizer",
33 33
             "NameLock", "_threading"]
34 34
 
35 35
 
@@ -49,17 +49,18 @@ def __init__(self, reentrant):
49 49
                 self.lock = _threading.RLock()
50 50
             else:
51 51
                 self.lock = _threading.Lock()
  52
+
52 53
         def __call__(self):
53 54
             return self.lock
54 55
 
55  
-    def __init__(self, identifier = None, reentrant = False):
  56
+    def __init__(self, identifier=None, reentrant=False):
56 57
         if identifier is None:
57 58
             self._lock = NameLock.NLContainer(reentrant)
58 59
         else:
59 60
             self._lock = NameLock.locks.get(identifier, NameLock.NLContainer,
60 61
                                             reentrant)
61 62
 
62  
-    def acquire(self, wait = True):
  63
+    def acquire(self, wait=True):
63 64
         return self._lock().acquire(wait)
64 65
 
65 66
     def release(self):
@@ -67,6 +68,8 @@ def release(self):
67 68
 
68 69
 
69 70
 _synchronizers = util.WeakValuedRegistry()
  71
+
  72
+
70 73
 def _synchronizer(identifier, cls, **kwargs):
71 74
     return _synchronizers.sync_get((identifier, cls), cls, identifier, **kwargs)
72 75
 
@@ -85,14 +88,17 @@ def mutex_synchronizer(identifier, **kwargs):
85 88
 class null_synchronizer(object):
86 89
     """A 'null' synchronizer, which provides the :class:`.SynchronizerImpl` interface
87 90
     without any locking.
88  
-    
  91
+
89 92
     """
90 93
     def acquire_write_lock(self, wait=True):
91 94
         return True
  95
+
92 96
     def acquire_read_lock(self):
93 97
         pass
  98
+
94 99
     def release_write_lock(self):
95 100
         pass
  101
+
96 102
     def release_read_lock(self):
97 103
         pass
98 104
     acquire = acquire_write_lock
@@ -102,7 +108,7 @@ def release_read_lock(self):
102 108
 class SynchronizerImpl(object):
103 109
     """Base class for a synchronization object that allows
104 110
     multiple readers, single writers.
105  
-    
  111
+
106 112
     """
107 113
     def __init__(self):
108 114
         self._state = util.ThreadLocal()
@@ -127,9 +133,9 @@ def state(self):
127 133
     def release_read_lock(self):
128 134
         state = self.state
129 135
 
130  
-        if state.writing: 
  136
+        if state.writing:
131 137
             raise LockError("lock is in writing state")
132  
-        if not state.reading: 
  138
+        if not state.reading:
133 139
             raise LockError("lock is not in reading state")
134 140
 
135 141