88
99import re
1010import os
11- import ConfigParser as cp
11+ import configparser as cp
1212import inspect
13- import cStringIO
13+ import io
1414
1515from git .odict import OrderedDict
1616from git .util import LockFile
@@ -97,7 +97,7 @@ def config(self):
9797 return self ._config
9898
9999
100- class GitConfigParser (cp .RawConfigParser , object ):
100+ class GitConfigParser (cp .RawConfigParser , object , metaclass = MetaParserBuilder ):
101101 """Implements specifics required to read git style configuration files.
102102
103103 This variation behaves much like the git.config command such that the configuration
@@ -112,7 +112,6 @@ class GitConfigParser(cp.RawConfigParser, object):
112112 :note:
113113 The config is case-sensitive even when queried, hence section and option names
114114 must match perfectly."""
115- __metaclass__ = MetaParserBuilder
116115
117116
118117 #{ Configuration
@@ -163,7 +162,7 @@ def __init__(self, file_or_files, read_only=True):
163162 raise ValueError ("Write-ConfigParsers can operate on a single file only, multiple files have been passed" )
164163 # END single file check
165164
166- if not isinstance (file_or_files , basestring ):
165+ if not isinstance (file_or_files , str ):
167166 file_or_files = file_or_files .name
168167 # END get filename from handle/stream
169168 # initialize lock base - we want to write
@@ -183,8 +182,8 @@ def __del__(self):
183182 try :
184183 try :
185184 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 ) )
188187 finally :
189188 self ._lock ._release_lock ()
190189
@@ -283,7 +282,7 @@ def read(self):
283282 try :
284283 fp = open (file_object )
285284 close_fp = True
286- except IOError , e :
285+ except IOError as e :
287286 continue
288287 # END fp handling
289288
@@ -301,15 +300,15 @@ def _write(self, fp):
301300 git compatible format"""
302301 def write_section (name , section_dict ):
303302 fp .write ("[%s]\n " % name )
304- for (key , value ) in section_dict .items ():
303+ for (key , value ) in list ( section_dict .items () ):
305304 if key != "__name__" :
306305 fp .write ("\t %s = %s\n " % (key , str (value ).replace ('\n ' , '\n \t ' )))
307306 # END if key is not __name__
308307 # END section writing
309308
310309 if self ._defaults :
311310 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 ()) ))
313312
314313
315314 @needs_values
@@ -324,7 +323,7 @@ def write(self):
324323 close_fp = False
325324
326325 # we have a physical file on disk, so get a lock
327- if isinstance (fp , (basestring , file )):
326+ if isinstance (fp , (str , file )):
328327 self ._lock ._obtain_lock ()
329328 # END get lock for physical files
330329
@@ -382,7 +381,7 @@ def get_value(self, section, option, default = None):
382381 return default
383382 raise
384383
385- types = ( long , float )
384+ types = ( int , float )
386385 for numtype in types :
387386 try :
388387 val = numtype ( valuestr )
@@ -403,7 +402,7 @@ def get_value(self, section, option, default = None):
403402 if vl == 'true' :
404403 return True
405404
406- if not isinstance ( valuestr , basestring ):
405+ if not isinstance ( valuestr , str ):
407406 raise TypeError ( "Invalid value type: only int, long, float and str are allowed" , valuestr )
408407
409408 return valuestr
0 commit comments