snowflake-connector-python 5.0.0__cp312-cp312-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/connector/__init__.py +136 -0
- snowflake/connector/_common/__init__.py +0 -0
- snowflake/connector/_common/extras.py +134 -0
- snowflake/connector/_common/telemetry.py +221 -0
- snowflake/connector/_common/wif_util.py +92 -0
- snowflake/connector/_core/sf_core_python.cp312-win_arm64.pyd +0 -0
- snowflake/connector/_core/sf_core_python.pyi +67 -0
- snowflake/connector/_internal/__init__.py +6 -0
- snowflake/connector/_internal/_private_key_helper.py +50 -0
- snowflake/connector/_internal/api_client/__init__.py +93 -0
- snowflake/connector/_internal/api_client/bridge.py +41 -0
- snowflake/connector/_internal/api_client/client_api.py +976 -0
- snowflake/connector/_internal/arrow.py +47 -0
- snowflake/connector/_internal/arrow_context.py +240 -0
- snowflake/connector/_internal/arrow_stream_async.py +266 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp312-win_arm64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
- snowflake/connector/_internal/arrow_stream_utils.py +171 -0
- snowflake/connector/_internal/authenticator_type.py +53 -0
- snowflake/connector/_internal/backward_compatibility.py +245 -0
- snowflake/connector/_internal/binding_converters.py +741 -0
- snowflake/connector/_internal/config_utils.py +71 -0
- snowflake/connector/_internal/connection/__init__.py +39 -0
- snowflake/connector/_internal/connection/connection.py +618 -0
- snowflake/connector/_internal/connection/connection_types.py +13 -0
- snowflake/connector/_internal/connection/constants.py +25 -0
- snowflake/connector/_internal/connection/decorators.py +31 -0
- snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
- snowflake/connector/_internal/connection/queries.py +10 -0
- snowflake/connector/_internal/connection_config_mixin.py +744 -0
- snowflake/connector/_internal/cursor/__init__.py +25 -0
- snowflake/connector/_internal/cursor/base.py +719 -0
- snowflake/connector/_internal/cursor/cursor_types.py +13 -0
- snowflake/connector/_internal/cursor/decorators.py +56 -0
- snowflake/connector/_internal/cursor/query_result.py +202 -0
- snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
- snowflake/connector/_internal/cursor/result_metadata.py +255 -0
- snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
- snowflake/connector/_internal/decorators.py +539 -0
- snowflake/connector/_internal/error_kinds.py +111 -0
- snowflake/connector/_internal/errorcode.py +35 -0
- snowflake/connector/_internal/errorhandler.py +278 -0
- snowflake/connector/_internal/fips.py +28 -0
- snowflake/connector/_internal/logging/__init__.py +52 -0
- snowflake/connector/_internal/logging/config.py +134 -0
- snowflake/connector/_internal/logging/core_logger.py +218 -0
- snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
- snowflake/connector/_internal/logout_config_mapping.py +187 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +45 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +87 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13273 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +203 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29300 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +99 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +44 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
- snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
- snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
- snowflake/connector/_internal/result_batch.py +150 -0
- snowflake/connector/_internal/snowflake_restful.py +222 -0
- snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
- snowflake/connector/_internal/sqlstate.py +11 -0
- snowflake/connector/_internal/statement_utils.py +207 -0
- snowflake/connector/_internal/text_utils.py +283 -0
- snowflake/connector/_internal/type_codes.py +139 -0
- snowflake/connector/_internal/utils.py +65 -0
- snowflake/connector/_internal/write_pandas_operation.py +629 -0
- snowflake/connector/aio/README.md +168 -0
- snowflake/connector/aio/__init__.py +37 -0
- snowflake/connector/aio/connection/__init__.py +17 -0
- snowflake/connector/aio/connection/_connection.py +478 -0
- snowflake/connector/aio/cursor/__init__.py +35 -0
- snowflake/connector/aio/cursor/_base.py +1021 -0
- snowflake/connector/aio/cursor/_dict_cursor.py +58 -0
- snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/aio/cursor/_snowflake_cursor.py +52 -0
- snowflake/connector/aio/pandas_tools.py +278 -0
- snowflake/connector/aio/result_batch.py +165 -0
- snowflake/connector/auth/__init__.py +0 -0
- snowflake/connector/auth/workload_identity.py +5 -0
- snowflake/connector/compat.py +22 -0
- snowflake/connector/config_manager.py +392 -0
- snowflake/connector/connection/__init__.py +30 -0
- snowflake/connector/connection/_connection.py +613 -0
- snowflake/connector/connection_config.py +489 -0
- snowflake/connector/constants.py +52 -0
- snowflake/connector/cursor/__init__.py +37 -0
- snowflake/connector/cursor/_base.py +1156 -0
- snowflake/connector/cursor/_chunked_download_reader.py +75 -0
- snowflake/connector/cursor/_dict_cursor.py +58 -0
- snowflake/connector/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/cursor/_snowflake_cursor.py +52 -0
- snowflake/connector/description.py +7 -0
- snowflake/connector/errors.py +472 -0
- snowflake/connector/network.py +71 -0
- snowflake/connector/pandas_tools.py +191 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +216 -0
- snowflake/connector/telemetry.py +40 -0
- snowflake/connector/time_util.py +11 -0
- snowflake/connector/types.py +134 -0
- snowflake/connector/util_text.py +3 -0
- snowflake/connector/version.py +23 -0
- snowflake_connector_python-5.0.0.dist-info/METADATA +190 -0
- snowflake_connector_python-5.0.0.dist-info/RECORD +197 -0
- snowflake_connector_python-5.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Helper functions for private key conversion."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from ..errors import ProgrammingError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def normalize_private_key(private_key: Any) -> bytes | str:
|
|
11
|
+
"""
|
|
12
|
+
Normalize private_key to a format that can be sent to the Rust core.
|
|
13
|
+
|
|
14
|
+
The Rust core handles:
|
|
15
|
+
- bytes: DER format (sent via connection_set_option_bytes)
|
|
16
|
+
- str: base64-encoded PEM or DER (sent via connection_set_option_string)
|
|
17
|
+
|
|
18
|
+
This function only converts RSAPrivateKey objects to bytes.
|
|
19
|
+
bytes and str are passed through as-is.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
private_key: Private key in one of the supported formats:
|
|
23
|
+
- bytes (DER format)
|
|
24
|
+
- str (base64-encoded PEM or DER)
|
|
25
|
+
- RSAPrivateKey object
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
bytes or str: Private key ready to be sent to Rust core
|
|
29
|
+
|
|
30
|
+
Raises:
|
|
31
|
+
ProgrammingError: If the private_key type is not supported or conversion fails
|
|
32
|
+
"""
|
|
33
|
+
if isinstance(private_key, (bytes, str)):
|
|
34
|
+
# Pass through - Rust handles DER bytes and base64-encoded strings (PEM or DER)
|
|
35
|
+
return private_key
|
|
36
|
+
|
|
37
|
+
# Handle RSAPrivateKey object from cryptography library
|
|
38
|
+
from cryptography.hazmat.primitives import serialization
|
|
39
|
+
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPrivateKey
|
|
40
|
+
|
|
41
|
+
if isinstance(private_key, RSAPrivateKey):
|
|
42
|
+
return private_key.private_bytes(
|
|
43
|
+
encoding=serialization.Encoding.DER,
|
|
44
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
45
|
+
encryption_algorithm=serialization.NoEncryption(),
|
|
46
|
+
)
|
|
47
|
+
raise ProgrammingError(
|
|
48
|
+
f"Unsupported private_key type: {type(private_key)}. "
|
|
49
|
+
"Expected bytes, str (base64-encoded), or RSAPrivateKey object."
|
|
50
|
+
)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Initialize the core API with the default logger callback."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from snowflake.connector.errors import OperationalError
|
|
6
|
+
|
|
7
|
+
from ..logging import _get_connector_stdlib_logger, _get_sf_core_stdlib_logger
|
|
8
|
+
from ..logging.config import LoggingConfiguration
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from snowflake.connector._core import sf_core_python
|
|
13
|
+
except ImportError as err:
|
|
14
|
+
raise OperationalError(
|
|
15
|
+
msg=(
|
|
16
|
+
"Couldn't load the native library (sf_core_python). "
|
|
17
|
+
"Ensure the package was installed from a pre-built wheel or built locally."
|
|
18
|
+
)
|
|
19
|
+
) from err
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _sf_core_level_to_python(level: int) -> int | None:
|
|
23
|
+
"""Map sf_core wire level to stdlib logging level.
|
|
24
|
+
|
|
25
|
+
DEBUG is the finest level Python supports. Core's ``normalize_event`` collapses
|
|
26
|
+
finer levels (Rust ``tracing::trace!``, legacy TRACE) to wire level 3 before
|
|
27
|
+
the callback, so level 4 should not normally reach this path. The ``>= 3``
|
|
28
|
+
branch is defensive: any wire level 3 or higher is delivered as DEBUG rather
|
|
29
|
+
than dropped.
|
|
30
|
+
"""
|
|
31
|
+
if level >= 3:
|
|
32
|
+
return logging.DEBUG
|
|
33
|
+
match level:
|
|
34
|
+
case 0:
|
|
35
|
+
return logging.ERROR
|
|
36
|
+
case 1:
|
|
37
|
+
return logging.WARNING
|
|
38
|
+
case 2:
|
|
39
|
+
return logging.INFO
|
|
40
|
+
case _:
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _logger_callback(
|
|
45
|
+
level: int,
|
|
46
|
+
message: str,
|
|
47
|
+
filename: str,
|
|
48
|
+
line: int,
|
|
49
|
+
function: str,
|
|
50
|
+
logger_name: str,
|
|
51
|
+
) -> int:
|
|
52
|
+
py_level = _sf_core_level_to_python(level)
|
|
53
|
+
if py_level is None:
|
|
54
|
+
return 0
|
|
55
|
+
|
|
56
|
+
target_logger = logging.getLogger(logger_name) if logger_name else _get_sf_core_stdlib_logger()
|
|
57
|
+
|
|
58
|
+
if not target_logger.isEnabledFor(py_level):
|
|
59
|
+
return 0
|
|
60
|
+
|
|
61
|
+
record = target_logger.makeRecord(
|
|
62
|
+
target_logger.name,
|
|
63
|
+
py_level,
|
|
64
|
+
filename,
|
|
65
|
+
line,
|
|
66
|
+
message,
|
|
67
|
+
(),
|
|
68
|
+
None,
|
|
69
|
+
func=function,
|
|
70
|
+
)
|
|
71
|
+
target_logger.handle(record)
|
|
72
|
+
return 0
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def register_default_logger_callback() -> None:
|
|
76
|
+
"""Register the default logger callback with the core API."""
|
|
77
|
+
status, troubleshooting_enabled = sf_core_python.init(_logger_callback)
|
|
78
|
+
if status != 0:
|
|
79
|
+
raise OperationalError(
|
|
80
|
+
msg=(
|
|
81
|
+
f"sf_core_python.init failed (status={status}). "
|
|
82
|
+
"Ensure the package was installed from a pre-built wheel or built locally."
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
LoggingConfiguration.initialize(troubleshooting_enabled=troubleshooting_enabled)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
register_default_logger_callback()
|
|
89
|
+
|
|
90
|
+
from snowflake.connector.version import __version__ # noqa: E402
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
_get_connector_stdlib_logger().info("Python connector starting v%s", __version__)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from snowflake.connector.errors import OperationalError
|
|
4
|
+
|
|
5
|
+
from ..protobuf_gen.proto_exception import ProtoTransportException
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
from snowflake.connector._core import sf_core_python
|
|
10
|
+
except ImportError as err:
|
|
11
|
+
raise OperationalError(
|
|
12
|
+
msg=(
|
|
13
|
+
"Couldn't load the native library (sf_core_python). "
|
|
14
|
+
"Ensure the package was installed from a pre-built wheel or built locally."
|
|
15
|
+
)
|
|
16
|
+
) from err
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ProtoTransport:
|
|
20
|
+
"""Bridge between Python proto RPC calls and the Rust core via PyO3.
|
|
21
|
+
|
|
22
|
+
:meth:`handle_message_async` — returns a native awaitable from Rust. The
|
|
23
|
+
request runs as a tokio task; dropping the awaitable (which is what
|
|
24
|
+
cancelling the surrounding asyncio task does) cancels the operation's
|
|
25
|
+
token in core.
|
|
26
|
+
|
|
27
|
+
:meth:`handle_message` — blocking call (releases the GIL).
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
async def handle_message_async(self, api: str, method: str, message: bytes) -> tuple[int, bytes]:
|
|
31
|
+
result: tuple[int, bytes] = await sf_core_python.call_proto_async(api, method, message) # type: ignore[assignment]
|
|
32
|
+
status, response_bytes = result
|
|
33
|
+
if status in (0, 1, 2):
|
|
34
|
+
return status, response_bytes
|
|
35
|
+
raise ProtoTransportException(f"Unknown error code: {status}")
|
|
36
|
+
|
|
37
|
+
def handle_message(self, api: str, method: str, message: bytes) -> tuple[int, bytes]:
|
|
38
|
+
status, response_bytes = sf_core_python.call_proto(api, method, message)
|
|
39
|
+
if status in (0, 1, 2):
|
|
40
|
+
return status, response_bytes
|
|
41
|
+
raise ProtoTransportException(f"Unknown error code: {status}")
|