@@ -36,27 +36,6 @@ def close(self, needs_lock=True):
36
36
raise NotImplementedError
37
37
38
38
39
- class _RefCounter (object ):
40
- """Class for keeping track of reference counts."""
41
- def __init__ (self , counts ):
42
- self ._counts = counts
43
- self ._lock = threading .Lock ()
44
-
45
- def increment (self , name ):
46
- with self ._lock :
47
- count = self ._counts [name ] = self ._counts .get (name , 0 ) + 1
48
- return count
49
-
50
- def decrement (self , name ):
51
- with self ._lock :
52
- count = self ._counts [name ] - 1
53
- if count :
54
- self ._counts [name ] = count
55
- else :
56
- del self ._counts [name ]
57
- return count
58
-
59
-
60
39
class CachingFileManager (FileManager ):
61
40
"""Wrapper for automatically opening and closing file objects.
62
41
@@ -240,8 +219,8 @@ def __del__(self):
240
219
241
220
def __getstate__ (self ):
242
221
"""State for pickling."""
243
- # cache and ref_counts are intentionally omited : we don't want to try
244
- # to serailize these objects.
222
+ # cache and ref_counts are intentionally omitted : we don't want to try
223
+ # to serialize these global objects.
245
224
lock = None if self ._default_lock else self ._lock
246
225
return (self ._opener , self ._args , self ._mode , self ._kwargs , lock )
247
226
@@ -258,6 +237,27 @@ def __repr__(self):
258
237
type (self ).__name__ , self ._opener , args_string , self ._kwargs )
259
238
260
239
240
+ class _RefCounter (object ):
241
+ """Class for keeping track of reference counts."""
242
+ def __init__ (self , counts ):
243
+ self ._counts = counts
244
+ self ._lock = threading .Lock ()
245
+
246
+ def increment (self , name ):
247
+ with self ._lock :
248
+ count = self ._counts [name ] = self ._counts .get (name , 0 ) + 1
249
+ return count
250
+
251
+ def decrement (self , name ):
252
+ with self ._lock :
253
+ count = self ._counts [name ] - 1
254
+ if count :
255
+ self ._counts [name ] = count
256
+ else :
257
+ del self ._counts [name ]
258
+ return count
259
+
260
+
261
261
class _HashedSequence (list ):
262
262
"""Speedup repeated look-ups by caching hash values.
263
263
0 commit comments