Skip to content

Commit 4271571

Browse files
author
vshepard
committed
Move _get_ssl_options in separate function
1 parent e729c2f commit 4271571

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

testgres/operations/os_ops.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,27 @@ def get_pid(self):
124124
def get_process_children(self, pid):
125125
raise NotImplementedError()
126126

127+
def _get_ssl_options(self):
128+
"""
129+
Determine the SSL options based on available modules.
130+
"""
131+
if self.conn_params.skip_ssl:
132+
if 'psycopg2' in sys.modules:
133+
return {"sslmode": "disable"}
134+
elif 'pg8000' in sys.modules:
135+
return {"ssl_context": None}
136+
return {}
137+
127138
# Database control
128139
def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
129-
ssl_options = {"sslmode": "disable"} if self.conn_params.skip_ssl and 'psycopg2' in sys.modules else {}
140+
ssl_options = self._get_ssl_options()
130141
conn = pglib.connect(
131142
host=host,
132143
port=port,
133144
database=dbname,
134145
user=user,
135146
password=password,
136-
**({"ssl_context": None} if self.conn_params.skip_ssl and 'pg8000' in sys.modules else ssl_options)
147+
**ssl_options
137148
)
138149

139150
return conn

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy