airbyte-cdk 6.8.1rc4__py3-none-any.whl → 6.8.1rc5__py3-none-any.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.
- airbyte_cdk/sources/declarative/interpolation/jinja.py +39 -36
- airbyte_cdk/sources/streams/http/http_client.py +0 -1
- {airbyte_cdk-6.8.1rc4.dist-info → airbyte_cdk-6.8.1rc5.dist-info}/METADATA +1 -1
- {airbyte_cdk-6.8.1rc4.dist-info → airbyte_cdk-6.8.1rc5.dist-info}/RECORD +7 -7
- {airbyte_cdk-6.8.1rc4.dist-info → airbyte_cdk-6.8.1rc5.dist-info}/LICENSE.txt +0 -0
- {airbyte_cdk-6.8.1rc4.dist-info → airbyte_cdk-6.8.1rc5.dist-info}/WHEEL +0 -0
- {airbyte_cdk-6.8.1rc4.dist-info → airbyte_cdk-6.8.1rc5.dist-info}/entry_points.txt +0 -0
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
import ast
|
6
6
|
from functools import cache
|
7
|
-
from typing import Any, Mapping, Optional, Tuple, Type
|
7
|
+
from typing import Any, Mapping, Optional, Set, Tuple, Type
|
8
8
|
|
9
9
|
from jinja2 import meta
|
10
10
|
from jinja2.environment import Template
|
@@ -30,6 +30,34 @@ class StreamPartitionAccessEnvironment(SandboxedEnvironment):
|
|
30
30
|
return super().is_safe_attribute(obj, attr, value) # type: ignore # for some reason, mypy says 'Returning Any from function declared to return "bool"'
|
31
31
|
|
32
32
|
|
33
|
+
# These aliases are used to deprecate existing keywords without breaking all existing connectors.
|
34
|
+
_ALIASES = {
|
35
|
+
"stream_interval": "stream_slice", # Use stream_interval to access incremental_sync values
|
36
|
+
"stream_partition": "stream_slice", # Use stream_partition to access partition router's values
|
37
|
+
}
|
38
|
+
|
39
|
+
# These extensions are not installed so they're not currently a problem,
|
40
|
+
# but we're still explicitely removing them from the jinja context.
|
41
|
+
# At worst, this is documentation that we do NOT want to include these extensions because of the potential security risks
|
42
|
+
_RESTRICTED_EXTENSIONS = ["jinja2.ext.loopcontrols"] # Adds support for break continue in loops
|
43
|
+
|
44
|
+
# By default, these Python builtin functions are available in the Jinja context.
|
45
|
+
# We explicitely remove them because of the potential security risk.
|
46
|
+
# Please add a unit test to test_jinja.py when adding a restriction.
|
47
|
+
_RESTRICTED_BUILTIN_FUNCTIONS = [
|
48
|
+
"range"
|
49
|
+
] # The range function can cause very expensive computations
|
50
|
+
|
51
|
+
_ENVIRONMENT = StreamPartitionAccessEnvironment()
|
52
|
+
_ENVIRONMENT.filters.update(**filters)
|
53
|
+
_ENVIRONMENT.globals.update(**macros)
|
54
|
+
|
55
|
+
for extension in _RESTRICTED_EXTENSIONS:
|
56
|
+
_ENVIRONMENT.extensions.pop(extension, None)
|
57
|
+
for builtin in _RESTRICTED_BUILTIN_FUNCTIONS:
|
58
|
+
_ENVIRONMENT.globals.pop(builtin, None)
|
59
|
+
|
60
|
+
|
33
61
|
class JinjaInterpolation(Interpolation):
|
34
62
|
"""
|
35
63
|
Interpolation strategy using the Jinja2 template engine.
|
@@ -48,34 +76,6 @@ class JinjaInterpolation(Interpolation):
|
|
48
76
|
Additional information on jinja templating can be found at https://jinja.palletsprojects.com/en/3.1.x/templates/#
|
49
77
|
"""
|
50
78
|
|
51
|
-
# These aliases are used to deprecate existing keywords without breaking all existing connectors.
|
52
|
-
ALIASES = {
|
53
|
-
"stream_interval": "stream_slice", # Use stream_interval to access incremental_sync values
|
54
|
-
"stream_partition": "stream_slice", # Use stream_partition to access partition router's values
|
55
|
-
}
|
56
|
-
|
57
|
-
# These extensions are not installed so they're not currently a problem,
|
58
|
-
# but we're still explicitely removing them from the jinja context.
|
59
|
-
# At worst, this is documentation that we do NOT want to include these extensions because of the potential security risks
|
60
|
-
RESTRICTED_EXTENSIONS = ["jinja2.ext.loopcontrols"] # Adds support for break continue in loops
|
61
|
-
|
62
|
-
# By default, these Python builtin functions are available in the Jinja context.
|
63
|
-
# We explicitely remove them because of the potential security risk.
|
64
|
-
# Please add a unit test to test_jinja.py when adding a restriction.
|
65
|
-
RESTRICTED_BUILTIN_FUNCTIONS = [
|
66
|
-
"range"
|
67
|
-
] # The range function can cause very expensive computations
|
68
|
-
|
69
|
-
def __init__(self) -> None:
|
70
|
-
self._environment = StreamPartitionAccessEnvironment()
|
71
|
-
self._environment.filters.update(**filters)
|
72
|
-
self._environment.globals.update(**macros)
|
73
|
-
|
74
|
-
for extension in self.RESTRICTED_EXTENSIONS:
|
75
|
-
self._environment.extensions.pop(extension, None)
|
76
|
-
for builtin in self.RESTRICTED_BUILTIN_FUNCTIONS:
|
77
|
-
self._environment.globals.pop(builtin, None)
|
78
|
-
|
79
79
|
def eval(
|
80
80
|
self,
|
81
81
|
input_str: str,
|
@@ -86,7 +86,7 @@ class JinjaInterpolation(Interpolation):
|
|
86
86
|
) -> Any:
|
87
87
|
context = {"config": config, **additional_parameters}
|
88
88
|
|
89
|
-
for alias, equivalent in
|
89
|
+
for alias, equivalent in _ALIASES.items():
|
90
90
|
if alias in context:
|
91
91
|
# This is unexpected. We could ignore or log a warning, but failing loudly should result in fewer surprises
|
92
92
|
raise ValueError(
|
@@ -105,8 +105,11 @@ class JinjaInterpolation(Interpolation):
|
|
105
105
|
raise Exception(f"Expected a string, got {input_str}")
|
106
106
|
except UndefinedError:
|
107
107
|
pass
|
108
|
-
|
109
|
-
|
108
|
+
|
109
|
+
if default is not None:
|
110
|
+
# If result is empty or resulted in an undefined error, evaluate and return the default string
|
111
|
+
return self._literal_eval(self._eval(default, context), valid_types)
|
112
|
+
raise ValueError(f"Cound not interpolate {input_str} and no default provided to fallback")
|
110
113
|
|
111
114
|
def _literal_eval(self, result: Optional[str], valid_types: Optional[Tuple[Type[Any]]]) -> Any:
|
112
115
|
try:
|
@@ -132,16 +135,16 @@ class JinjaInterpolation(Interpolation):
|
|
132
135
|
return s
|
133
136
|
|
134
137
|
@cache
|
135
|
-
def _find_undeclared_variables(self, s: Optional[str]) ->
|
138
|
+
def _find_undeclared_variables(self, s: Optional[str]) -> Set[str]:
|
136
139
|
"""
|
137
140
|
Find undeclared variables and cache them
|
138
141
|
"""
|
139
|
-
ast =
|
142
|
+
ast = _ENVIRONMENT.parse(s) # type: ignore # parse is able to handle None
|
140
143
|
return meta.find_undeclared_variables(ast)
|
141
144
|
|
142
145
|
@cache
|
143
|
-
def _compile(self, s:
|
146
|
+
def _compile(self, s: str) -> Template:
|
144
147
|
"""
|
145
148
|
We must cache the Jinja Template ourselves because we're using `from_string` instead of a template loader
|
146
149
|
"""
|
147
|
-
return
|
150
|
+
return _ENVIRONMENT.from_string(s)
|
@@ -538,7 +538,6 @@ class SkipFailureSQLiteDict(requests_cache.backends.sqlite.SQLiteDict):
|
|
538
538
|
logger.warning(f"Error while saving item to cache: {exception}")
|
539
539
|
|
540
540
|
|
541
|
-
|
542
541
|
class SkipFailureSQLiteCache(requests_cache.backends.sqlite.SQLiteCache):
|
543
542
|
def __init__( # type: ignore # ignoring as lib is not typed
|
544
543
|
self,
|
@@ -97,7 +97,7 @@ airbyte_cdk/sources/declarative/interpolation/interpolated_mapping.py,sha256=UrF
|
|
97
97
|
airbyte_cdk/sources/declarative/interpolation/interpolated_nested_mapping.py,sha256=i2L0gREX8nHA-pKokdVqwBf4aJgWP71KOxIABj_DHcY,1857
|
98
98
|
airbyte_cdk/sources/declarative/interpolation/interpolated_string.py,sha256=LYEZnZ_hB7rvBSZxG9s0RSrzsOkDWbBY0_P6qu5lEfc,3212
|
99
99
|
airbyte_cdk/sources/declarative/interpolation/interpolation.py,sha256=-V5UddGm69UKEB6o_O1EIES9kfY8FV_X4Ji8w1yOuSA,981
|
100
|
-
airbyte_cdk/sources/declarative/interpolation/jinja.py,sha256=
|
100
|
+
airbyte_cdk/sources/declarative/interpolation/jinja.py,sha256=KqsN4LNe47OcIMS6wlOXTlLZmbNniHBwrO6tMfnNzYw,6571
|
101
101
|
airbyte_cdk/sources/declarative/interpolation/macros.py,sha256=QgIfSVPHx_MMUCgbQdm-NMpUlp_cpk0OQhoRDFtkrxE,4040
|
102
102
|
airbyte_cdk/sources/declarative/manifest_declarative_source.py,sha256=FEOmFo2mwdpmO8pH9jnw-sUAnijjuigZWYqH_0Gq9oQ,12919
|
103
103
|
airbyte_cdk/sources/declarative/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -273,7 +273,7 @@ airbyte_cdk/sources/streams/http/error_handlers/json_error_message_parser.py,sha
|
|
273
273
|
airbyte_cdk/sources/streams/http/error_handlers/response_models.py,sha256=xGIVELBFY0TmH9aUq1ikoqJz8oHLr6di2JLvKWVEO-s,2236
|
274
274
|
airbyte_cdk/sources/streams/http/exceptions.py,sha256=njC7MlMJoFYcSGz4mIp6-bqLFTr6vC8ej25X0oSeyjE,1824
|
275
275
|
airbyte_cdk/sources/streams/http/http.py,sha256=h0bq4arzMeJsR-5HZNfGYXtZhgVvLbW6myi9fuhMayU,28467
|
276
|
-
airbyte_cdk/sources/streams/http/http_client.py,sha256=
|
276
|
+
airbyte_cdk/sources/streams/http/http_client.py,sha256=WxmoFeoISmRnwp2nzfJ0DeD1-05FhL0z8hIni-o7vV8,23067
|
277
277
|
airbyte_cdk/sources/streams/http/rate_limiting.py,sha256=IwdjrHKUnU97XO4qONgYRv4YYW51xQ8SJm4WLafXDB8,6351
|
278
278
|
airbyte_cdk/sources/streams/http/requests_native_auth/__init__.py,sha256=RN0D3nOX1xLgwEwKWu6pkGy3XqBFzKSNZ8Lf6umU2eY,413
|
279
279
|
airbyte_cdk/sources/streams/http/requests_native_auth/abstract_oauth.py,sha256=nxI94yJ3bGfpDO8RR3QvOJ-PSW0n9CElSAkgl5ae80Y,10321
|
@@ -330,8 +330,8 @@ airbyte_cdk/utils/slice_hasher.py,sha256=-pHexlNYoWYPnXNH-M7HEbjmeJe9Zk7SJijdQ7d
|
|
330
330
|
airbyte_cdk/utils/spec_schema_transformations.py,sha256=LVc9KbtMeV_z99jWo0Ou8u4l6eBJ0BWNhxj4zrrGKRs,763
|
331
331
|
airbyte_cdk/utils/stream_status_utils.py,sha256=ZmBoiy5HVbUEHAMrUONxZvxnvfV9CesmQJLDTAIWnWw,1171
|
332
332
|
airbyte_cdk/utils/traced_exception.py,sha256=a6q51tBS3IdtefuOiL1eBwSmnNAXfjFMlMjSIQ_Tl-o,6165
|
333
|
-
airbyte_cdk-6.8.
|
334
|
-
airbyte_cdk-6.8.
|
335
|
-
airbyte_cdk-6.8.
|
336
|
-
airbyte_cdk-6.8.
|
337
|
-
airbyte_cdk-6.8.
|
333
|
+
airbyte_cdk-6.8.1rc5.dist-info/LICENSE.txt,sha256=Wfe61S4BaGPj404v8lrAbvhjYR68SHlkzeYrg3_bbuM,1051
|
334
|
+
airbyte_cdk-6.8.1rc5.dist-info/METADATA,sha256=ohQnXZ226OXRoI0p7gVCWAgASzO_WrjRRFahcWv3wa8,13522
|
335
|
+
airbyte_cdk-6.8.1rc5.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
336
|
+
airbyte_cdk-6.8.1rc5.dist-info/entry_points.txt,sha256=fj-e3PAQvsxsQzyyq8UkG1k8spunWnD4BAH2AwlR6NM,95
|
337
|
+
airbyte_cdk-6.8.1rc5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|