@@ -72,7 +72,7 @@ def flush_changes(self, *args, **kwargs):
72
72
73
73
74
74
75
- class GitConfigParser (cp .RawConfigParser , LockFile ):
75
+ class GitConfigParser (cp .RawConfigParser , object ):
76
76
"""
77
77
Implements specifics required to read git style configuration files.
78
78
@@ -91,6 +91,15 @@ class GitConfigParser(cp.RawConfigParser, LockFile):
91
91
"""
92
92
__metaclass__ = _MetaParserBuilder
93
93
94
+
95
+ #{ Configuration
96
+ # The lock type determines the type of lock to use in new configuration readers.
97
+ # They must be compatible to the LockFile interface.
98
+ # A suitable alternative would be the BlockingLockFile
99
+ t_lock = LockFile
100
+
101
+ #} END configuration
102
+
94
103
OPTCRE = re .compile (
95
104
r'\s?(?P<option>[^:=\s][^:=]*)' # very permissive, incuding leading whitespace
96
105
r'\s*(?P<vi>[:=])\s*' # any number of space/tab,
@@ -102,7 +111,7 @@ class GitConfigParser(cp.RawConfigParser, LockFile):
102
111
103
112
# list of RawConfigParser methods able to change the instance
104
113
_mutating_methods_ = ("add_section" , "remove_section" , "remove_option" , "set" )
105
- __slots__ = ("_sections" , "_defaults" , "_file_or_files" , "_read_only" ,"_is_initialized" )
114
+ __slots__ = ("_sections" , "_defaults" , "_file_or_files" , "_read_only" ,"_is_initialized" , '_lock' )
106
115
107
116
def __init__ (self , file_or_files , read_only = True ):
108
117
"""
@@ -125,7 +134,7 @@ def __init__(self, file_or_files, read_only=True):
125
134
self ._file_or_files = file_or_files
126
135
self ._read_only = read_only
127
136
self ._is_initialized = False
128
-
137
+ self . _lock = None
129
138
130
139
if not read_only :
131
140
if isinstance (file_or_files , (tuple , list )):
@@ -136,9 +145,9 @@ def __init__(self, file_or_files, read_only=True):
136
145
file_or_files = file_or_files .name
137
146
# END get filename from handle/stream
138
147
# initialize lock base - we want to write
139
- LockFile . __init__ ( self , file_or_files )
148
+ self . _lock = self . t_lock ( file_or_files )
140
149
141
- self ._obtain_lock_or_raise ()
150
+ self ._lock . _obtain_lock ()
142
151
# END read-only check
143
152
144
153
@@ -148,7 +157,7 @@ def __del__(self):
148
157
"""
149
158
# checking for the lock here makes sure we do not raise during write()
150
159
# in case an invalid parser was created who could not get a lock
151
- if self .read_only or not self ._has_lock ():
160
+ if self .read_only or not self ._lock . _has_lock ():
152
161
return
153
162
154
163
try :
@@ -157,7 +166,7 @@ def __del__(self):
157
166
except IOError ,e :
158
167
print "Exception during destruction of GitConfigParser: %s" % str (e )
159
168
finally :
160
- self ._release_lock ()
169
+ self ._lock . _release_lock ()
161
170
162
171
def optionxform (self , optionstr ):
163
172
"""
@@ -303,7 +312,7 @@ def write(self):
303
312
a file lock
304
313
"""
305
314
self ._assure_writable ("write" )
306
- self ._obtain_lock_or_raise ()
315
+ self ._lock . _obtain_lock ()
307
316
308
317
309
318
fp = self ._file_or_files
0 commit comments