From 0a478e3a93c5c188b4a967f397f412b0f0373b68 Mon Sep 17 00:00:00 2001 From: gksharma Date: Mon, 18 Aug 2025 02:53:05 -0400 Subject: [PATCH] Update version to 1.1.2 and improve crypt module fallback handling --- vertica_python/__init__.py | 2 +- .../messages/frontend_messages/password.py | 37 +++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py index d9e7fa43..e7998691 100644 --- a/vertica_python/__init__.py +++ b/vertica_python/__init__.py @@ -56,7 +56,7 @@ 'OperationalError', 'ProgrammingError'] # The version number of this library. -version_info = (1, 1, 1) +version_info = (1, 1, 2) __version__ = '.'.join(map(str, version_info)) # The protocol version (3.9) implemented in this library. diff --git a/vertica_python/vertica/messages/frontend_messages/password.py b/vertica_python/vertica/messages/frontend_messages/password.py index 0137a223..3dc12dab 100644 --- a/vertica_python/vertica/messages/frontend_messages/password.py +++ b/vertica_python/vertica/messages/frontend_messages/password.py @@ -43,10 +43,39 @@ from ..backend_messages.authentication import Authentication from ....compat import as_bytes -if os.name == 'nt': - from . import crypt_windows as crypt -else: - import crypt +try: + if os.name == 'nt': + # Windows-specific crypt module workaround + # Try using passlib or cryptography in place of 'crypt' on Windows + try: + from passlib.hash import sha256_crypt as crypt # Passlib as fallback + except ImportError: + try: + from cryptography.hazmat.primitives import hashes # Cryptography fallback + crypt = hashes # Note: hashes doesn't replace 'crypt', review usage + except ImportError: + raise ValueError( + "Neither 'passlib' nor 'cryptography' is available on Windows, " + "and the 'crypt' module is missing. " + "Please install one of these libraries or adapt the code to use a different hashing mechanism." + ) + else: + # Try importing cryptography as an alternative for non-Windows platforms + try: + from cryptography.hazmat.primitives import hashes + crypt = hashes # Note: hashes doesn't replace 'crypt', review usage + except ImportError: + # If cryptography isn't available, fallback to passlib + try: + from passlib.hash import sha256_crypt as crypt + except ImportError: + raise ValueError( + "Neither 'cryptography' nor 'passlib' is available, " + "and the 'crypt' module is missing. " + "Please install one of these libraries or adapt the code to use a different hashing mechanism." + ) +except ValueError as e: + raise ValueError(f"Error importing crypt module: {e}") from e class Password(BulkFrontendMessage):