8
8
9
9
import re
10
10
import os
11
- import ConfigParser as cp
11
+ import configparser as cp
12
12
import inspect
13
- import cStringIO
13
+ import io
14
14
15
15
from git .odict import OrderedDict
16
16
from git .util import LockFile
@@ -97,7 +97,7 @@ def config(self):
97
97
return self ._config
98
98
99
99
100
- class GitConfigParser (cp .RawConfigParser , object ):
100
+ class GitConfigParser (cp .RawConfigParser , object , metaclass = MetaParserBuilder ):
101
101
"""Implements specifics required to read git style configuration files.
102
102
103
103
This variation behaves much like the git.config command such that the configuration
@@ -112,7 +112,6 @@ class GitConfigParser(cp.RawConfigParser, object):
112
112
:note:
113
113
The config is case-sensitive even when queried, hence section and option names
114
114
must match perfectly."""
115
- __metaclass__ = MetaParserBuilder
116
115
117
116
118
117
#{ Configuration
@@ -163,7 +162,7 @@ def __init__(self, file_or_files, read_only=True):
163
162
raise ValueError ("Write-ConfigParsers can operate on a single file only, multiple files have been passed" )
164
163
# END single file check
165
164
166
- if not isinstance (file_or_files , basestring ):
165
+ if not isinstance (file_or_files , str ):
167
166
file_or_files = file_or_files .name
168
167
# END get filename from handle/stream
169
168
# initialize lock base - we want to write
@@ -183,8 +182,8 @@ def __del__(self):
183
182
try :
184
183
try :
185
184
self .write ()
186
- except IOError , e :
187
- print "Exception during destruction of GitConfigParser: %s" % str (e )
185
+ except IOError as e :
186
+ print ( "Exception during destruction of GitConfigParser: %s" % str (e ) )
188
187
finally :
189
188
self ._lock ._release_lock ()
190
189
@@ -283,7 +282,7 @@ def read(self):
283
282
try :
284
283
fp = open (file_object )
285
284
close_fp = True
286
- except IOError , e :
285
+ except IOError as e :
287
286
continue
288
287
# END fp handling
289
288
@@ -301,15 +300,15 @@ def _write(self, fp):
301
300
git compatible format"""
302
301
def write_section (name , section_dict ):
303
302
fp .write ("[%s]\n " % name )
304
- for (key , value ) in section_dict .items ():
303
+ for (key , value ) in list ( section_dict .items () ):
305
304
if key != "__name__" :
306
305
fp .write ("\t %s = %s\n " % (key , str (value ).replace ('\n ' , '\n \t ' )))
307
306
# END if key is not __name__
308
307
# END section writing
309
308
310
309
if self ._defaults :
311
310
write_section (cp .DEFAULTSECT , self ._defaults )
312
- map (lambda t : write_section (t [0 ],t [1 ]), self ._sections .items ())
311
+ list ( map (lambda t : write_section (t [0 ],t [1 ]), list ( self ._sections .items ()) ))
313
312
314
313
315
314
@needs_values
@@ -324,7 +323,7 @@ def write(self):
324
323
close_fp = False
325
324
326
325
# we have a physical file on disk, so get a lock
327
- if isinstance (fp , (basestring , file )):
326
+ if isinstance (fp , (str , file )):
328
327
self ._lock ._obtain_lock ()
329
328
# END get lock for physical files
330
329
@@ -382,7 +381,7 @@ def get_value(self, section, option, default = None):
382
381
return default
383
382
raise
384
383
385
- types = ( long , float )
384
+ types = ( int , float )
386
385
for numtype in types :
387
386
try :
388
387
val = numtype ( valuestr )
@@ -403,7 +402,7 @@ def get_value(self, section, option, default = None):
403
402
if vl == 'true' :
404
403
return True
405
404
406
- if not isinstance ( valuestr , basestring ):
405
+ if not isinstance ( valuestr , str ):
407
406
raise TypeError ( "Invalid value type: only int, long, float and str are allowed" , valuestr )
408
407
409
408
return valuestr
0 commit comments