@@ -111,11 +111,9 @@ def begin(self, isolation_level=0):
111111
112112 # Something is wrong, emit exception
113113 else :
114- raise QueryException ('Invalid isolation level "%s"'
115- % isolation_level )
114+ raise QueryException ('Invalid isolation level "{}"' .format (isolation_level ))
116115
117- self .cursor .execute ('SET TRANSACTION ISOLATION LEVEL %s'
118- % isolation_level )
116+ self .cursor .execute ('SET TRANSACTION ISOLATION LEVEL {}' .format (isolation_level ))
119117
120118 def commit (self ):
121119 self .connection .commit ()
@@ -165,7 +163,7 @@ def error_filename(self):
165163
166164 @property
167165 def connstr (self ):
168- return "port=%s" % self .port
166+ return "port={}" . format ( self .port )
169167 # return "port=%s host=%s" % (self.port, self.host)
170168
171169 def get_bin_path (self , filename ):
@@ -184,7 +182,7 @@ def init(self, allows_streaming=False):
184182 if os .path .isfile (postgres_conf ):
185183 # if data directory exists then we don't need reinit it
186184 with open (postgres_conf , "a" ) as conf :
187- conf .write ("port = %s \n " % self .port )
185+ conf .write ("port = {} \n " . format ( self .port ) )
188186 return self
189187
190188 # initialize cluster
@@ -205,11 +203,11 @@ def init(self, allows_streaming=False):
205203 conf .write (
206204 "fsync = off\n "
207205 "log_statement = all\n "
208- "port = %s \n " % self .port )
206+ "port = {} \n " . format ( self .port ) )
209207 conf .write (
210208 # "unix_socket_directories = '%s'\n"
211209 # "listen_addresses = ''\n";)
212- "listen_addresses = '%s' \n " % self .host )
210+ "listen_addresses = {} \n " . format ( self .host ) )
213211
214212 if allows_streaming :
215213 # TODO: wal_level = hot_standby (9.5)
@@ -241,7 +239,7 @@ def init_from_backup(self, root_node, backup_name, has_streaming=False, hba_perm
241239 # Change port in config file
242240 self .append_conf (
243241 "postgresql.conf" ,
244- "port = %s" % self .port
242+ "port = {}" . format ( self .port )
245243 )
246244 # Enable streaming
247245 if hba_permit_replication :
@@ -259,9 +257,8 @@ def enable_streaming(self, root_node):
259257 recovery_conf = os .path .join (self .data_dir , "recovery.conf" )
260258 with open (recovery_conf , "a" ) as conf :
261259 conf .write (
262- "primary_conninfo='%s application_name=%s'\n "
263- "standby_mode=on\n "
264- % (root_node .connstr , self .name ))
260+ "primary_conninfo='{} application_name={}'\n "
261+ "standby_mode=on\n " .format (root_node .connstr , self .name ))
265262
266263 def append_conf (self , filename , string ):
267264 """Appends line to a config file like "postgresql.conf"
@@ -363,7 +360,7 @@ def psql(self, dbname, query=None, filename=None):
363360 """
364361 psql = self .get_bin_path ("psql" )
365362 psql_params = [
366- psql , "-XAtq" , "-p %s" % self .port , dbname
363+ psql , "-XAtq" , "-p {}" . format ( self .port ) , dbname
367364 ]
368365
369366 if query :
@@ -400,7 +397,7 @@ def dump(self, dbname, filename):
400397 path = os .path .join (self .base_dir , filename )
401398 params = [
402399 self .get_bin_path ("pg_dump" ),
403- "-p %s" % self .port ,
400+ "-p {}" . format ( self .port ) ,
404401 "-f" , path ,
405402 dbname
406403 ]
@@ -449,7 +446,7 @@ def backup(self, name):
449446 pg_basebackup = self .get_bin_path ("pg_basebackup" )
450447 backup_path = os .path .join (self .base_dir , name )
451448 os .makedirs (backup_path )
452- params = [pg_basebackup , "-D" , backup_path , "-p %s" % self .port , "-x" ]
449+ params = [pg_basebackup , "-D" , backup_path , "-p {}" . format ( self .port ) , "-x" ]
453450 with open (self .output_filename , "a" ) as file_out , \
454451 open (self .error_filename , "a" ) as file_err :
455452 ret = subprocess .call (
0 commit comments