snowflake-connector-python 3.16.0__cp313-cp313-win_amd64.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 +96 -0
- snowflake/connector/_query_context_cache.py +276 -0
- snowflake/connector/_sql_util.py +48 -0
- snowflake/connector/_utils.py +70 -0
- snowflake/connector/arrow_context.py +203 -0
- snowflake/connector/auth/__init__.py +53 -0
- snowflake/connector/auth/_auth.py +586 -0
- snowflake/connector/auth/_http_server.py +220 -0
- snowflake/connector/auth/_oauth_base.py +400 -0
- snowflake/connector/auth/by_plugin.py +219 -0
- snowflake/connector/auth/default.py +36 -0
- snowflake/connector/auth/idtoken.py +72 -0
- snowflake/connector/auth/keypair.py +222 -0
- snowflake/connector/auth/no_auth.py +39 -0
- snowflake/connector/auth/oauth.py +49 -0
- snowflake/connector/auth/oauth_code.py +479 -0
- snowflake/connector/auth/oauth_credentials.py +66 -0
- snowflake/connector/auth/okta.py +335 -0
- snowflake/connector/auth/pat.py +39 -0
- snowflake/connector/auth/usrpwdmfa.py +69 -0
- snowflake/connector/auth/webbrowser.py +502 -0
- snowflake/connector/auth/workload_identity.py +94 -0
- snowflake/connector/azure_storage_client.py +276 -0
- snowflake/connector/backoff_policies.py +141 -0
- snowflake/connector/bind_upload_agent.py +89 -0
- snowflake/connector/cache.py +696 -0
- snowflake/connector/compat.py +127 -0
- snowflake/connector/config_manager.py +496 -0
- snowflake/connector/connection.py +2273 -0
- snowflake/connector/connection_diagnostic.py +776 -0
- snowflake/connector/constants.py +442 -0
- snowflake/connector/converter.py +785 -0
- snowflake/connector/converter_issue23517.py +87 -0
- snowflake/connector/converter_null.py +14 -0
- snowflake/connector/converter_snowsql.py +205 -0
- snowflake/connector/cursor.py +1951 -0
- snowflake/connector/dbapi.py +53 -0
- snowflake/connector/description.py +19 -0
- snowflake/connector/direct_file_operation_utils.py +88 -0
- snowflake/connector/encryption_util.py +220 -0
- snowflake/connector/errorcode.py +91 -0
- snowflake/connector/errors.py +615 -0
- snowflake/connector/externals_utils/__init__.py +0 -0
- snowflake/connector/externals_utils/externals_setup.py +27 -0
- snowflake/connector/feature.py +4 -0
- snowflake/connector/file_compression_type.py +118 -0
- snowflake/connector/file_lock.py +72 -0
- snowflake/connector/file_transfer_agent.py +1215 -0
- snowflake/connector/file_util.py +153 -0
- snowflake/connector/gcs_storage_client.py +474 -0
- snowflake/connector/gzip_decoder.py +85 -0
- snowflake/connector/local_storage_client.py +90 -0
- snowflake/connector/log_configuration.py +60 -0
- snowflake/connector/logging_utils/__init__.py +0 -0
- snowflake/connector/logging_utils/filters.py +72 -0
- snowflake/connector/nanoarrow_arrow_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +60 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.cpp +557 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.hpp +98 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +115 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.cpp +1005 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.hpp +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +47 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +83 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +72 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +73 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +71 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +56 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +75 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +95 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +57 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +34 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +346 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +145 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +101 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1908 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +215 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +55 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +148 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +239 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +210 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +206 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +118 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +898 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +190 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc.c +3204 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3217 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3618 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +379 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_arrow_iterator.pyx +256 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.c +512 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.h +350 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +33273 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +397 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.cpp +100 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.hpp +49 -0
- snowflake/connector/network.py +1297 -0
- snowflake/connector/ocsp_asn1crypto.py +447 -0
- snowflake/connector/ocsp_snowflake.py +1883 -0
- snowflake/connector/options.py +131 -0
- snowflake/connector/pandas_tools.py +732 -0
- snowflake/connector/proxy.py +43 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +786 -0
- snowflake/connector/result_set.py +319 -0
- snowflake/connector/s3_storage_client.py +605 -0
- snowflake/connector/secret_detector.py +181 -0
- snowflake/connector/sf_dirs.py +64 -0
- snowflake/connector/sfbinaryformat.py +35 -0
- snowflake/connector/sfdatetime.py +345 -0
- snowflake/connector/snow_logging.py +144 -0
- snowflake/connector/sqlstate.py +9 -0
- snowflake/connector/ssd_internal_keys.py +30 -0
- snowflake/connector/ssl_wrap_socket.py +134 -0
- snowflake/connector/storage_client.py +478 -0
- snowflake/connector/telemetry.py +249 -0
- snowflake/connector/telemetry_oob.py +543 -0
- snowflake/connector/test_util.py +30 -0
- snowflake/connector/time_util.py +159 -0
- snowflake/connector/token_cache.py +402 -0
- snowflake/connector/tool/__init__.py +0 -0
- snowflake/connector/tool/dump_certs.py +57 -0
- snowflake/connector/tool/dump_ocsp_response.py +139 -0
- snowflake/connector/tool/dump_ocsp_response_cache.py +194 -0
- snowflake/connector/tool/probe_connection.py +69 -0
- snowflake/connector/url_util.py +49 -0
- snowflake/connector/util_text.py +301 -0
- snowflake/connector/vendored/__init__.py +3 -0
- snowflake/connector/vendored/requests/LICENSE +175 -0
- snowflake/connector/vendored/requests/__init__.py +169 -0
- snowflake/connector/vendored/requests/__version__.py +14 -0
- snowflake/connector/vendored/requests/_internal_utils.py +50 -0
- snowflake/connector/vendored/requests/adapters.py +537 -0
- snowflake/connector/vendored/requests/api.py +157 -0
- snowflake/connector/vendored/requests/auth.py +315 -0
- snowflake/connector/vendored/requests/certs.py +17 -0
- snowflake/connector/vendored/requests/compat.py +79 -0
- snowflake/connector/vendored/requests/cookies.py +561 -0
- snowflake/connector/vendored/requests/exceptions.py +140 -0
- snowflake/connector/vendored/requests/help.py +134 -0
- snowflake/connector/vendored/requests/hooks.py +33 -0
- snowflake/connector/vendored/requests/models.py +1033 -0
- snowflake/connector/vendored/requests/sessions.py +833 -0
- snowflake/connector/vendored/requests/status_codes.py +128 -0
- snowflake/connector/vendored/requests/structures.py +99 -0
- snowflake/connector/vendored/requests/utils.py +1093 -0
- snowflake/connector/vendored/urllib3/LICENSE.txt +21 -0
- snowflake/connector/vendored/urllib3/__init__.py +85 -0
- snowflake/connector/vendored/urllib3/_collections.py +355 -0
- snowflake/connector/vendored/urllib3/_version.py +2 -0
- snowflake/connector/vendored/urllib3/connection.py +572 -0
- snowflake/connector/vendored/urllib3/connectionpool.py +1137 -0
- snowflake/connector/vendored/urllib3/contrib/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_appengine_environ.py +36 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/bindings.py +519 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/low_level.py +397 -0
- snowflake/connector/vendored/urllib3/contrib/appengine.py +314 -0
- snowflake/connector/vendored/urllib3/contrib/ntlmpool.py +130 -0
- snowflake/connector/vendored/urllib3/contrib/pyopenssl.py +509 -0
- snowflake/connector/vendored/urllib3/contrib/securetransport.py +920 -0
- snowflake/connector/vendored/urllib3/contrib/socks.py +216 -0
- snowflake/connector/vendored/urllib3/exceptions.py +323 -0
- snowflake/connector/vendored/urllib3/fields.py +274 -0
- snowflake/connector/vendored/urllib3/filepost.py +98 -0
- snowflake/connector/vendored/urllib3/packages/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/makefile.py +51 -0
- snowflake/connector/vendored/urllib3/packages/backports/weakref_finalize.py +155 -0
- snowflake/connector/vendored/urllib3/packages/six.py +1076 -0
- snowflake/connector/vendored/urllib3/poolmanager.py +540 -0
- snowflake/connector/vendored/urllib3/request.py +191 -0
- snowflake/connector/vendored/urllib3/response.py +885 -0
- snowflake/connector/vendored/urllib3/util/__init__.py +49 -0
- snowflake/connector/vendored/urllib3/util/connection.py +156 -0
- snowflake/connector/vendored/urllib3/util/proxy.py +57 -0
- snowflake/connector/vendored/urllib3/util/queue.py +22 -0
- snowflake/connector/vendored/urllib3/util/request.py +146 -0
- snowflake/connector/vendored/urllib3/util/response.py +107 -0
- snowflake/connector/vendored/urllib3/util/retry.py +620 -0
- snowflake/connector/vendored/urllib3/util/ssl_.py +495 -0
- snowflake/connector/vendored/urllib3/util/ssl_match_hostname.py +159 -0
- snowflake/connector/vendored/urllib3/util/ssltransport.py +221 -0
- snowflake/connector/vendored/urllib3/util/timeout.py +271 -0
- snowflake/connector/vendored/urllib3/util/url.py +435 -0
- snowflake/connector/vendored/urllib3/util/wait.py +152 -0
- snowflake/connector/version.py +3 -0
- snowflake/connector/wif_util.py +407 -0
- snowflake_connector_python-3.16.0.dist-info/METADATA +1475 -0
- snowflake_connector_python-3.16.0.dist-info/RECORD +246 -0
- snowflake_connector_python-3.16.0.dist-info/WHEEL +5 -0
- snowflake_connector_python-3.16.0.dist-info/entry_points.txt +4 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/LICENSE.txt +202 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/NOTICE +8 -0
- snowflake_connector_python-3.16.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import io
|
|
5
|
+
import subprocess
|
|
6
|
+
import zlib
|
|
7
|
+
from logging import getLogger
|
|
8
|
+
from typing import IO, Generator
|
|
9
|
+
|
|
10
|
+
CHUNK_SIZE = 16384
|
|
11
|
+
MAGIC_NUMBER = 16 # magic number from .vendored.requests/packages/urllib3/response.py
|
|
12
|
+
|
|
13
|
+
logger = getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def decompress_raw_data(raw_data_fd: IO, add_bracket: bool = True) -> bytes:
|
|
17
|
+
"""Decompresses raw data from file like object with zlib.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
raw_data_fd: File descriptor object.
|
|
21
|
+
add_bracket: Whether, or not to add brackets around the output. (Default value = True)
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
A byte array of the decompressed file.
|
|
25
|
+
"""
|
|
26
|
+
obj = zlib.decompressobj(MAGIC_NUMBER + zlib.MAX_WBITS)
|
|
27
|
+
writer = io.BytesIO()
|
|
28
|
+
if add_bracket:
|
|
29
|
+
writer.write(b"[")
|
|
30
|
+
d = raw_data_fd.read(CHUNK_SIZE)
|
|
31
|
+
while d:
|
|
32
|
+
writer.write(obj.decompress(d))
|
|
33
|
+
while obj.unused_data != b"":
|
|
34
|
+
unused_data = obj.unused_data
|
|
35
|
+
obj = zlib.decompressobj(MAGIC_NUMBER + zlib.MAX_WBITS)
|
|
36
|
+
writer.write(obj.decompress(unused_data))
|
|
37
|
+
d = raw_data_fd.read(CHUNK_SIZE)
|
|
38
|
+
writer.write(obj.flush())
|
|
39
|
+
if add_bracket:
|
|
40
|
+
writer.write(b"]")
|
|
41
|
+
return writer.getvalue()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def decompress_raw_data_by_zcat(raw_data_fd: IO, add_bracket: bool = True) -> bytes:
|
|
45
|
+
"""Experimental: Decompresses raw data from file like object with zcat. Otherwise same as decompress_raw_data.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
raw_data_fd: File descriptor object.
|
|
49
|
+
add_bracket: Whether, or not to add brackets around the output. (Default value = True)
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
A byte array of the decompressed file.
|
|
53
|
+
"""
|
|
54
|
+
writer = io.BytesIO()
|
|
55
|
+
if add_bracket:
|
|
56
|
+
writer.write(b"[")
|
|
57
|
+
p = subprocess.Popen(["zcat"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
|
58
|
+
writer.write(p.communicate(input=raw_data_fd.read())[0])
|
|
59
|
+
if add_bracket:
|
|
60
|
+
writer.write(b"]")
|
|
61
|
+
return writer.getvalue()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def decompress_raw_data_to_unicode_stream(
|
|
65
|
+
raw_data_fd: IO,
|
|
66
|
+
) -> Generator[str]:
|
|
67
|
+
"""Decompresses a raw data in file like object and yields a Unicode string.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
raw_data_fd: File descriptor object.
|
|
71
|
+
|
|
72
|
+
Yields:
|
|
73
|
+
A string of the decompressed file in chunks.
|
|
74
|
+
"""
|
|
75
|
+
obj = zlib.decompressobj(MAGIC_NUMBER + zlib.MAX_WBITS)
|
|
76
|
+
yield "["
|
|
77
|
+
d = raw_data_fd.read(CHUNK_SIZE)
|
|
78
|
+
while d:
|
|
79
|
+
yield obj.decompress(d).decode("utf-8")
|
|
80
|
+
while obj.unused_data != b"":
|
|
81
|
+
unused_data = obj.unused_data
|
|
82
|
+
obj = zlib.decompressobj(MAGIC_NUMBER + zlib.MAX_WBITS)
|
|
83
|
+
yield obj.decompress(unused_data).decode("utf-8")
|
|
84
|
+
d = raw_data_fd.read(CHUNK_SIZE)
|
|
85
|
+
yield obj.flush().decode("utf-8") + "]"
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
from logging import getLogger
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
from .constants import FileHeader, ResultStatus
|
|
10
|
+
from .storage_client import SnowflakeStorageClient
|
|
11
|
+
from .vendored import requests
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING: # pragma: no cover
|
|
14
|
+
from .file_transfer_agent import SnowflakeFileMeta
|
|
15
|
+
|
|
16
|
+
logger = getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SnowflakeLocalStorageClient(SnowflakeStorageClient):
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
meta: SnowflakeFileMeta,
|
|
23
|
+
stage_info: dict[str, Any],
|
|
24
|
+
chunk_size: int,
|
|
25
|
+
unsafe_file_write: bool = False,
|
|
26
|
+
) -> None:
|
|
27
|
+
super().__init__(
|
|
28
|
+
meta, stage_info, chunk_size, unsafe_file_write=unsafe_file_write
|
|
29
|
+
)
|
|
30
|
+
self.data_file = meta.src_file_name
|
|
31
|
+
self.full_dst_file_name: str = os.path.join(
|
|
32
|
+
stage_info["location"], os.path.basename(meta.dst_file_name)
|
|
33
|
+
)
|
|
34
|
+
if meta.local_location:
|
|
35
|
+
src_file_name = self.data_file
|
|
36
|
+
if src_file_name.startswith("/"):
|
|
37
|
+
src_file_name = src_file_name[1:]
|
|
38
|
+
self.stage_file_name: str = os.path.join(
|
|
39
|
+
stage_info["location"], src_file_name
|
|
40
|
+
)
|
|
41
|
+
self.full_dst_file_name = os.path.join(
|
|
42
|
+
meta.local_location, os.path.basename(meta.dst_file_name)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
def get_file_header(self, filename: str) -> FileHeader | None:
|
|
46
|
+
"""
|
|
47
|
+
Notes:
|
|
48
|
+
Checks whether the file exits in specified directory, does not return FileHeader
|
|
49
|
+
"""
|
|
50
|
+
if os.path.isfile(filename):
|
|
51
|
+
return FileHeader(None, os.stat(filename).st_size, None)
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
def download_chunk(self, chunk_id: int) -> None:
|
|
55
|
+
with open(self.stage_file_name, "rb") as sfd:
|
|
56
|
+
with open(
|
|
57
|
+
os.path.join(
|
|
58
|
+
self.meta.local_location,
|
|
59
|
+
os.path.basename(self.intermediate_dst_path),
|
|
60
|
+
),
|
|
61
|
+
"rb+",
|
|
62
|
+
) as tfd:
|
|
63
|
+
if self.num_of_chunks == 1:
|
|
64
|
+
tfd.write(sfd.read())
|
|
65
|
+
else:
|
|
66
|
+
tfd.seek(chunk_id * self.chunk_size)
|
|
67
|
+
sfd.seek(chunk_id * self.chunk_size)
|
|
68
|
+
tfd.write(sfd.read(self.chunk_size))
|
|
69
|
+
|
|
70
|
+
def finish_download(self) -> None:
|
|
71
|
+
shutil.move(self.intermediate_dst_path, self.full_dst_file_name)
|
|
72
|
+
self.meta.dst_file_size = os.stat(self.full_dst_file_name).st_size
|
|
73
|
+
self.meta.result_status = ResultStatus.DOWNLOADED
|
|
74
|
+
|
|
75
|
+
def _has_expired_token(self, response: requests.Response) -> bool:
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
def prepare_upload(self) -> None:
|
|
79
|
+
super().prepare_upload()
|
|
80
|
+
with open(self.full_dst_file_name, "wb+") as fd:
|
|
81
|
+
fd.truncate(self.meta.upload_size)
|
|
82
|
+
|
|
83
|
+
def _upload_chunk(self, chunk_id: int, chunk: bytes) -> None:
|
|
84
|
+
with open(self.full_dst_file_name, "rb+") as tfd:
|
|
85
|
+
tfd.seek(chunk_id * self.chunk_size)
|
|
86
|
+
tfd.write(chunk)
|
|
87
|
+
|
|
88
|
+
def finish_upload(self) -> None:
|
|
89
|
+
self.meta.result_status = ResultStatus.UPLOADED
|
|
90
|
+
self.meta.dst_file_size = self.meta.upload_size
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import os
|
|
5
|
+
from logging.handlers import TimedRotatingFileHandler
|
|
6
|
+
|
|
7
|
+
from snowflake.connector.config_manager import CONFIG_MANAGER
|
|
8
|
+
from snowflake.connector.constants import DIRS
|
|
9
|
+
from snowflake.connector.secret_detector import SecretDetector
|
|
10
|
+
|
|
11
|
+
LOG_FILE_NAME = "python-connector.log"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class EasyLoggingConfigPython:
|
|
15
|
+
def __init__(self):
|
|
16
|
+
self.path: str | None = None
|
|
17
|
+
self.level: str | None = None
|
|
18
|
+
self.save_logs: bool = False
|
|
19
|
+
self.parse_config_file()
|
|
20
|
+
|
|
21
|
+
def parse_config_file(self):
|
|
22
|
+
CONFIG_MANAGER.read_config()
|
|
23
|
+
data = CONFIG_MANAGER.conf_file_cache
|
|
24
|
+
if log := data.get("log"):
|
|
25
|
+
self.save_logs = log.get("save_logs", False)
|
|
26
|
+
self.level = log.get("level", "INFO")
|
|
27
|
+
self.path = log.get("path", os.path.join(DIRS.user_config_path, "logs"))
|
|
28
|
+
|
|
29
|
+
if not os.path.isabs(self.path):
|
|
30
|
+
raise FileNotFoundError(
|
|
31
|
+
f"Log path must be an absolute file path: {self.path}"
|
|
32
|
+
)
|
|
33
|
+
# if log path does not exist, create it, else check accessibility
|
|
34
|
+
if not os.path.exists(self.path):
|
|
35
|
+
os.makedirs(self.path, exist_ok=True)
|
|
36
|
+
elif not os.access(self.path, os.R_OK | os.W_OK):
|
|
37
|
+
raise PermissionError(
|
|
38
|
+
f"log path: {self.path} is not accessible, please verify your config file"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# create_log() is called outside __init__() so that it can be easily turned off
|
|
42
|
+
def create_log(self):
|
|
43
|
+
if self.save_logs:
|
|
44
|
+
logging.basicConfig(
|
|
45
|
+
filename=os.path.join(self.path, LOG_FILE_NAME),
|
|
46
|
+
level=logging.getLevelName(self.level),
|
|
47
|
+
)
|
|
48
|
+
for logger_name in ["snowflake.connector", "botocore", "boto3"]:
|
|
49
|
+
logger = logging.getLogger(logger_name)
|
|
50
|
+
logger.setLevel(logging.getLevelName(self.level))
|
|
51
|
+
ch = TimedRotatingFileHandler(
|
|
52
|
+
os.path.join(self.path, LOG_FILE_NAME), when="midnight"
|
|
53
|
+
)
|
|
54
|
+
ch.setLevel(logging.getLevelName(self.level))
|
|
55
|
+
ch.setFormatter(
|
|
56
|
+
SecretDetector(
|
|
57
|
+
"%(asctime)s - %(threadName)s %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s"
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
logger.addHandler(ch)
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
|
|
5
|
+
from snowflake.connector.secret_detector import SecretDetector
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def add_filter_to_logger_and_children(
|
|
9
|
+
base_logger_name: str, filter_instance: logging.Filter
|
|
10
|
+
) -> None:
|
|
11
|
+
# Ensure the base logger exists and apply filter
|
|
12
|
+
base_logger = logging.getLogger(base_logger_name)
|
|
13
|
+
if filter_instance not in base_logger.filters:
|
|
14
|
+
base_logger.addFilter(filter_instance)
|
|
15
|
+
|
|
16
|
+
all_loggers_pairs = logging.root.manager.loggerDict.items()
|
|
17
|
+
for name, obj in all_loggers_pairs:
|
|
18
|
+
if not name.startswith(base_logger_name + "."):
|
|
19
|
+
continue
|
|
20
|
+
|
|
21
|
+
if not isinstance(obj, logging.Logger):
|
|
22
|
+
continue # Skip placeholders
|
|
23
|
+
|
|
24
|
+
if filter_instance not in obj.filters:
|
|
25
|
+
obj.addFilter(filter_instance)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SecretMaskingFilter(logging.Filter):
|
|
29
|
+
"""
|
|
30
|
+
A logging filter that masks sensitive information in log messages using the SecretDetector utility.
|
|
31
|
+
|
|
32
|
+
This filter is designed for scenarios where you want to avoid applying SecretDetector globally
|
|
33
|
+
as a formatter on all logging handlers. Global masking can introduce unnecessary computational
|
|
34
|
+
overhead, particularly for internal logs where secrets are already handled explicitly.
|
|
35
|
+
It would be also easy to bypass unintentionally by simply adding a neighbouring handler to a logger
|
|
36
|
+
- without SecretDetector set as a formatter.
|
|
37
|
+
|
|
38
|
+
On the other hand, libraries or submodules often do not have any handler attached, so formatting can't be
|
|
39
|
+
configured on those level, while attaching new handler for that can cause unintended log output or its duplication.
|
|
40
|
+
|
|
41
|
+
⚠ Important:
|
|
42
|
+
- Logging filters do **not** propagate down the logger hierarchy.
|
|
43
|
+
To apply this filter across a hierarchy, use the `add_filter_to_logger_and_children` utility.
|
|
44
|
+
- This filter causes **early formatting** of the log message (`record.getMessage()`),
|
|
45
|
+
meaning `record.args` are merged into `record.msg` prematurely.
|
|
46
|
+
If you rely on `record.args`, ensure this is the **last** filter in the chain.
|
|
47
|
+
|
|
48
|
+
Notes:
|
|
49
|
+
- The filter directly modifies `record.msg` with the masked version of the message.
|
|
50
|
+
- It clears `record.args` to prevent re-formatting and ensure safe message output.
|
|
51
|
+
|
|
52
|
+
Example:
|
|
53
|
+
logger.addFilter(SecretMaskingFilter())
|
|
54
|
+
handler.addFilter(SecretMaskingFilter())
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def filter(self, record: logging.LogRecord) -> bool:
|
|
58
|
+
try:
|
|
59
|
+
# Format the message as it would be
|
|
60
|
+
message = record.getMessage()
|
|
61
|
+
|
|
62
|
+
# Run masking on the whole message
|
|
63
|
+
masked_data = SecretDetector.mask_secrets(message)
|
|
64
|
+
record.msg = masked_data.masked_text
|
|
65
|
+
except Exception as ex:
|
|
66
|
+
record.msg = SecretDetector.create_formatting_error_log(
|
|
67
|
+
record, "EXCEPTION - " + str(ex)
|
|
68
|
+
)
|
|
69
|
+
finally:
|
|
70
|
+
record.args = () # Avoid format re-application of formatting
|
|
71
|
+
|
|
72
|
+
return True # allow all logs through
|
|
Binary file
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#include "ArrayConverter.hpp"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
#include "CArrowChunkIterator.hpp"
|
|
6
|
+
#include "CArrowIterator.hpp"
|
|
7
|
+
#include "SnowflakeType.hpp"
|
|
8
|
+
|
|
9
|
+
namespace sf {
|
|
10
|
+
Logger* ArrayConverter::logger =
|
|
11
|
+
new Logger("snowflake.connector.ArrayConverter");
|
|
12
|
+
|
|
13
|
+
void ArrayConverter::generateError(const std::string& msg) const {
|
|
14
|
+
logger->error(__FILE__, __func__, __LINE__, msg.c_str());
|
|
15
|
+
PyErr_SetString(PyExc_Exception, msg.c_str());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
ArrayConverter::ArrayConverter(ArrowSchemaView* schemaView,
|
|
19
|
+
ArrowArrayView* array, PyObject* context,
|
|
20
|
+
bool useNumpy) {
|
|
21
|
+
m_array = array;
|
|
22
|
+
|
|
23
|
+
if (schemaView->schema->n_children != 1) {
|
|
24
|
+
std::string errorInfo = Logger::formatString(
|
|
25
|
+
"[Snowflake Exception] invalid arrow schema for array items expected 1 "
|
|
26
|
+
"schema child, but got %d",
|
|
27
|
+
schemaView->schema->n_children);
|
|
28
|
+
this->generateError(errorInfo);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
ArrowSchema* item_schema = schemaView->schema->children[0];
|
|
33
|
+
ArrowArrayView* item_array = array->children[0];
|
|
34
|
+
m_item_converter = getConverterFromSchema(item_schema, item_array, context,
|
|
35
|
+
useNumpy, logger);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
PyObject* ArrayConverter::toPyObject(int64_t rowIndex) const {
|
|
39
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
40
|
+
Py_RETURN_NONE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Array item offsets are stored in the second array buffers
|
|
44
|
+
// Infer start an end of this rows slice by looking at the
|
|
45
|
+
// current and next offset. If there isn't another offset use
|
|
46
|
+
// the end of the array instead.
|
|
47
|
+
int start = m_array->buffer_views[1].data.as_int32[rowIndex];
|
|
48
|
+
int end = m_array->children[0]->length;
|
|
49
|
+
if (rowIndex + 1 < m_array->length) {
|
|
50
|
+
end = m_array->buffer_views[1].data.as_int32[rowIndex + 1];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
PyObject* list = PyList_New(end - start);
|
|
54
|
+
for (int i = start; i < end; i++) {
|
|
55
|
+
PyList_SetItem(list, i - start, m_item_converter->toPyObject(i));
|
|
56
|
+
}
|
|
57
|
+
return list;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
} // namespace sf
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#ifndef PC_ARRAYCONVERTER_HPP
|
|
2
|
+
#define PC_ARRAYCONVERTER_HPP
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "IColumnConverter.hpp"
|
|
7
|
+
#include "logging.hpp"
|
|
8
|
+
#include "nanoarrow.h"
|
|
9
|
+
#include "nanoarrow.hpp"
|
|
10
|
+
|
|
11
|
+
namespace sf {
|
|
12
|
+
|
|
13
|
+
class ArrayConverter : public IColumnConverter {
|
|
14
|
+
public:
|
|
15
|
+
explicit ArrayConverter(ArrowSchemaView* schemaView, ArrowArrayView* array,
|
|
16
|
+
PyObject* context, bool useNumpy);
|
|
17
|
+
|
|
18
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
19
|
+
|
|
20
|
+
private:
|
|
21
|
+
void generateError(const std::string& msg) const;
|
|
22
|
+
|
|
23
|
+
ArrowArrayView* m_array;
|
|
24
|
+
std::shared_ptr<sf::IColumnConverter> m_item_converter;
|
|
25
|
+
static Logger* logger;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
} // namespace sf
|
|
29
|
+
#endif // PC_ARRAYCONVERTER_HPP
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "BinaryConverter.hpp"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
namespace sf {
|
|
6
|
+
Logger* BinaryConverter::logger =
|
|
7
|
+
new Logger("snowflake.connector.BinaryConverter");
|
|
8
|
+
|
|
9
|
+
BinaryConverter::BinaryConverter(ArrowArrayView* array) : m_array(array) {}
|
|
10
|
+
|
|
11
|
+
PyObject* BinaryConverter::toPyObject(int64_t rowIndex) const {
|
|
12
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
13
|
+
Py_RETURN_NONE;
|
|
14
|
+
}
|
|
15
|
+
ArrowStringView stringView = ArrowArrayViewGetStringUnsafe(m_array, rowIndex);
|
|
16
|
+
return PyByteArray_FromStringAndSize(stringView.data, stringView.size_bytes);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
} // namespace sf
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#ifndef PC_BINARYCONVERTER_HPP
|
|
2
|
+
#define PC_BINARYCONVERTER_HPP
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "IColumnConverter.hpp"
|
|
7
|
+
#include "logging.hpp"
|
|
8
|
+
#include "nanoarrow.h"
|
|
9
|
+
|
|
10
|
+
namespace sf {
|
|
11
|
+
|
|
12
|
+
class BinaryConverter : public IColumnConverter {
|
|
13
|
+
public:
|
|
14
|
+
explicit BinaryConverter(ArrowArrayView* array);
|
|
15
|
+
|
|
16
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
17
|
+
|
|
18
|
+
private:
|
|
19
|
+
ArrowArrayView* m_array;
|
|
20
|
+
|
|
21
|
+
static Logger* logger;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
} // namespace sf
|
|
25
|
+
|
|
26
|
+
#endif // PC_BINARYCONVERTER_HPP
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#include "BooleanConverter.hpp"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
|
|
5
|
+
namespace sf {
|
|
6
|
+
|
|
7
|
+
BooleanConverter::BooleanConverter(ArrowArrayView* array) : m_array(array) {}
|
|
8
|
+
|
|
9
|
+
PyObject* BooleanConverter::toPyObject(int64_t rowIndex) const {
|
|
10
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
11
|
+
Py_RETURN_NONE;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (ArrowArrayViewGetIntUnsafe(m_array, rowIndex)) {
|
|
15
|
+
Py_RETURN_TRUE;
|
|
16
|
+
} else {
|
|
17
|
+
Py_RETURN_FALSE;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace sf
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#ifndef PC_BOOLEANCONVERTER_HPP
|
|
2
|
+
#define PC_BOOLEANCONVERTER_HPP
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "IColumnConverter.hpp"
|
|
7
|
+
#include "nanoarrow.h"
|
|
8
|
+
|
|
9
|
+
namespace sf {
|
|
10
|
+
|
|
11
|
+
class BooleanConverter : public IColumnConverter {
|
|
12
|
+
public:
|
|
13
|
+
explicit BooleanConverter(ArrowArrayView* array);
|
|
14
|
+
|
|
15
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
16
|
+
|
|
17
|
+
private:
|
|
18
|
+
ArrowArrayView* m_array;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
} // namespace sf
|
|
22
|
+
|
|
23
|
+
#endif // PC_BOOLEANCONVERTER_HPP
|