6
6
import subprocess
7
7
import time
8
8
9
- from collections import Iterable
9
+ try :
10
+ from collections .abc import Iterable
11
+ except ImportError :
12
+ from collections import Iterable
13
+
10
14
from shutil import rmtree
11
15
from six import raise_from , iteritems , text_type
12
16
from tempfile import mkstemp , mkdtemp
@@ -91,7 +95,6 @@ class ProcessProxy(object):
91
95
process: wrapped psutill.Process object
92
96
ptype: instance of ProcessType
93
97
"""
94
-
95
98
def __init__ (self , process , ptype = None ):
96
99
self .process = process
97
100
self .ptype = ptype or ProcessType .from_process (process )
@@ -196,7 +199,6 @@ def auxiliary_processes(self):
196
199
Returns a list of auxiliary processes.
197
200
Each process is represented by :class:`.ProcessProxy` object.
198
201
"""
199
-
200
202
def is_aux (process ):
201
203
return process .ptype != ProcessType .Unknown
202
204
@@ -430,10 +432,9 @@ def init(self, initdb_params=None, **kwargs):
430
432
"""
431
433
432
434
# initialize this PostgreSQL node
433
- cached_initdb (
434
- data_dir = self .data_dir ,
435
- logfile = self .utils_log_file ,
436
- params = initdb_params )
435
+ cached_initdb (data_dir = self .data_dir ,
436
+ logfile = self .utils_log_file ,
437
+ params = initdb_params )
437
438
438
439
# initialize default config files
439
440
self .default_conf (** kwargs )
@@ -480,8 +481,8 @@ def default_conf(self,
480
481
if allow_streaming :
481
482
# get auth method for host or local users
482
483
def get_auth_method (t ):
483
- return next ((s .split ()[- 1 ] for s in lines
484
- if s .startswith (t )), 'trust' )
484
+ return next ((s .split ()[- 1 ]
485
+ for s in lines if s .startswith (t )), 'trust' )
485
486
486
487
# get auth methods
487
488
auth_local = get_auth_method ('local' )
@@ -760,12 +761,11 @@ def promote(self, dbname=None, username=None):
760
761
if self ._pg_version < '10' :
761
762
check_query = "SELECT pg_is_in_recovery()"
762
763
763
- self .poll_query_until (
764
- query = check_query ,
765
- expected = False ,
766
- dbname = dbname ,
767
- username = username ,
768
- max_attempts = 0 ) # infinite
764
+ self .poll_query_until (query = check_query ,
765
+ expected = False ,
766
+ dbname = dbname ,
767
+ username = username ,
768
+ max_attempts = 0 ) # infinite
769
769
770
770
# node becomes master itself
771
771
self ._master = None
@@ -884,11 +884,10 @@ def psql(self,
884
884
psql_params .append (dbname )
885
885
886
886
# start psql process
887
- process = subprocess .Popen (
888
- psql_params ,
889
- stdin = subprocess .PIPE ,
890
- stdout = subprocess .PIPE ,
891
- stderr = subprocess .PIPE )
887
+ process = subprocess .Popen (psql_params ,
888
+ stdin = subprocess .PIPE ,
889
+ stdout = subprocess .PIPE ,
890
+ stderr = subprocess .PIPE )
892
891
893
892
# wait until it finishes and get stdout and stderr
894
893
out , err = process .communicate (input = input )
@@ -1043,11 +1042,10 @@ def poll_query_until(self,
1043
1042
attempts = 0
1044
1043
while max_attempts == 0 or attempts < max_attempts :
1045
1044
try :
1046
- res = self .execute (
1047
- dbname = dbname ,
1048
- query = query ,
1049
- username = username ,
1050
- commit = commit )
1045
+ res = self .execute (dbname = dbname ,
1046
+ query = query ,
1047
+ username = username ,
1048
+ commit = commit )
1051
1049
1052
1050
if expected is None and res is None :
1053
1051
return # done
@@ -1165,8 +1163,8 @@ def set_synchronous_standbys(self, standbys):
1165
1163
standbys = First (1 , standbys )
1166
1164
else :
1167
1165
if isinstance (standbys , Iterable ):
1168
- standbys = u", " .join (
1169
- u" \" {} \" " . format ( r . name ) for r in standbys )
1166
+ standbys = u", " .join (u" \" {} \" " . format ( r . name )
1167
+ for r in standbys )
1170
1168
else :
1171
1169
raise TestgresException ("Feature isn't supported in "
1172
1170
"Postgres 9.5 and below" )
@@ -1195,11 +1193,10 @@ def catchup(self, dbname=None, username=None):
1195
1193
username = username )[0 ][0 ] # yapf: disable
1196
1194
1197
1195
# wait until this LSN reaches replica
1198
- self .poll_query_until (
1199
- query = wait_lsn .format (lsn ),
1200
- dbname = dbname ,
1201
- username = username ,
1202
- max_attempts = 0 ) # infinite
1196
+ self .poll_query_until (query = wait_lsn .format (lsn ),
1197
+ dbname = dbname ,
1198
+ username = username ,
1199
+ max_attempts = 0 ) # infinite
1203
1200
except Exception as e :
1204
1201
raise_from (CatchUpException ("Failed to catch up" , poll_lsn ), e )
1205
1202
@@ -1215,7 +1212,11 @@ def publish(self, name, **kwargs):
1215
1212
"""
1216
1213
return Publication (name = name , node = self , ** kwargs )
1217
1214
1218
- def subscribe (self , publication , name , dbname = None , username = None ,
1215
+ def subscribe (self ,
1216
+ publication ,
1217
+ name ,
1218
+ dbname = None ,
1219
+ username = None ,
1219
1220
** params ):
1220
1221
"""
1221
1222
Create subscription for logical replication
0 commit comments