3737
3838# hard coded db ports for dbnames
3939DBPORTS = {
40- 'default' : 5432
40+ 'default' : 0
4141}
4242
4343DBPASS = {}
@@ -517,9 +517,9 @@ def pgconnect(reconnect = 0, pgcnt = 0, autocommit = True):
517517 config ['host' ] = PGDBI ['DBHOST' ] if PGDBI ['DBHOST' ] else PGDBI ['DEFHOST' ]
518518 if not PGDBI ['DBPORT' ]: PGDBI ['DBPORT' ] = get_dbport (PGDBI ['DBNAME' ])
519519 if PGDBI ['DBPORT' ]: config ['port' ] = PGDBI ['DBPORT' ]
520- config ['password' ] = get_pgpass_password ()
521-
520+ config ['password' ] = '***'
522521 sqlstr = "psycopg2.connect(**{})" .format (config )
522+ config ['password' ] = get_pgpass_password ()
523523 if PgLOG .PGLOG ['DBGLEVEL' ]: PgLOG .pgdbg (1000 , sqlstr )
524524 try :
525525 PgLOG .PGLOG ['PGDBBUF' ] = pgdb = PgSQL .connect (** config )
@@ -2221,8 +2221,10 @@ def pgname(str, sign = None):
22212221def get_pgpass_password ():
22222222
22232223 if PGDBI ['PWNAME' ]: return PGDBI ['PWNAME' ]
2224- if not DBPASS : read_pgpass ()
2225- return DBPASS .get ((PGDBI ['DBSHOST' ], PGDBI ['DBPORT' ], PGDBI ['DBNAME' ], PGDBI ['LNNAME' ]))
2224+ if not DBPASS : read_pgpass ()
2225+ dbport = str (PGDBI ['DBPORT' ]) if PGDBI ['DBPORT' ] else '5432'
2226+ pwname = DBPASS .get ((PGDBI ['DBSHOST' ], dbport , PGDBI ['DBNAME' ], PGDBI ['LNNAME' ]))
2227+ if not pwname : pwname = DBPASS .get ((PGDBI ['DBHOST' ], dbport , PGDBI ['DBNAME' ], PGDBI ['LNNAME' ]))
22262228
22272229#
22282230# Reads the .pgpass file and returns a dictionary of credentials.
@@ -2234,7 +2236,7 @@ def read_pgpass():
22342236 for line in f :
22352237 line = line .strip ()
22362238 if not line or line .startswith ("#" ): continue
2237- dbhost , dbport , dbname , usname , pwname = line .split (":" )
2238- DBPASS [(dbhost , dbport , dbname , usname )] = pwname
2239+ dbhost , dbport , dbname , lnname , pwname = line .split (":" )
2240+ DBPASS [(dbhost , dbport , dbname , lnname )] = pwname
22392241 except FileNotFoundError :
22402242 pass
0 commit comments