Fixes for ruff check in utils.py

This commit is contained in:
tcely 2025-05-17 10:33:42 -04:00 committed by GitHub
parent 35d2aa7b2d
commit 58ed18519a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,14 +84,11 @@ def parse_database_connection_string(database_connection_string):
f'invalid driver, must be one of {valid_drivers}') f'invalid driver, must be one of {valid_drivers}')
django_driver = django_backends.get(driver) django_driver = django_backends.get(driver)
host_parts = user_pass_host_port.split('@') host_parts = user_pass_host_port.split('@')
if len(host_parts) != 2: user_pass_parts = host_parts[0].split(':')
raise DatabaseConnectionError(f'Database connection string netloc must be in ' if len(host_parts) != 2 or len(user_pass_parts) != 2:
f'the format of user:pass@host') raise DatabaseConnectionError('Database connection string netloc must be in '
'the format of user:pass@host')
user_pass, host_port = host_parts user_pass, host_port = host_parts
user_pass_parts = user_pass.split(':')
if len(user_pass_parts) != 2:
raise DatabaseConnectionError(f'Database connection string netloc must be in '
f'the format of user:pass@host')
username, password = user_pass_parts username, password = user_pass_parts
host_port_parts = host_port.split(':') host_port_parts = host_port.split(':')
if len(host_port_parts) == 1: if len(host_port_parts) == 1:
@ -113,13 +110,13 @@ def parse_database_connection_string(database_connection_string):
f'65535, got {port}') f'65535, got {port}')
else: else:
# Malformed # Malformed
raise DatabaseConnectionError(f'Database connection host must be a hostname or ' raise DatabaseConnectionError('Database connection host must be a hostname or '
f'a hostname:port combination') 'a hostname:port combination')
if database.startswith('/'): if database.startswith('/'):
database = database[1:] database = database[1:]
if not database: if not database:
raise DatabaseConnectionError(f'Database connection string path must be a ' raise DatabaseConnectionError('Database connection string path must be a '
f'string in the format of /databasename') 'string in the format of /databasename')
if '/' in database: if '/' in database:
raise DatabaseConnectionError(f'Database connection string path can only ' raise DatabaseConnectionError(f'Database connection string path can only '
f'contain a single string name, got: {database}') f'contain a single string name, got: {database}')