datadog-checks-base 37.13.0__py2.py3-none-any.whl → 37.15.0__py2.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.
@@ -1,4 +1,4 @@
1
1
  # (C) Datadog, Inc. 2018-present
2
2
  # All rights reserved
3
3
  # Licensed under a 3-clause BSD style license (see LICENSE)
4
- __version__ = "37.13.0"
4
+ __version__ = "37.15.0"
@@ -0,0 +1,84 @@
1
+ import ast
2
+ from enum import Enum
3
+ from typing import Any
4
+
5
+ # This module is used to parse and modify the config AST before it is loaded.
6
+ # It is used to handle special float values (inf, -inf, nan) and replace them with placeholders since those
7
+ # are not valid Python literals.
8
+
9
+
10
+ class SpecialFloatPlaceholder(str, Enum):
11
+ INF = '__PYTHON_INF__'
12
+ NEG_INF = '__PYTHON_NEG_INF__'
13
+ NAN = '__PYTHON_NAN__'
14
+
15
+
16
+ class _SpecialFloatValuesTransformer(ast.NodeTransformer):
17
+ def visit_Name(self, node: ast.Name) -> ast.AST:
18
+ """
19
+ Processes named constants like 'inf' and 'nan'.
20
+ If the name is 'inf', it's replaced with a placeholder for positive infinity.
21
+ If the name is 'nan', it's replaced with a placeholder for Not a Number.
22
+ Other names are returned unchanged.
23
+ """
24
+ if node.id == 'inf':
25
+ return ast.Constant(value=SpecialFloatPlaceholder.INF.value)
26
+ elif node.id == 'nan':
27
+ return ast.Constant(value=SpecialFloatPlaceholder.NAN.value)
28
+ return node # Leaf node, no children to visit
29
+
30
+ def visit_UnaryOp(self, node: ast.UnaryOp) -> ast.AST:
31
+ """
32
+ Processes unary operations like negation.
33
+ If the operation is a negation ('-') applied to the name 'inf',
34
+ it's replaced with a placeholder for negative infinity.
35
+ We can't use visit_Name for this because the constant is 'inf' and not '-inf'.
36
+ Other unary operations are processed as normal.
37
+ """
38
+ if isinstance(node.op, ast.USub) and isinstance(node.operand, ast.Name) and node.operand.id == 'inf':
39
+ return ast.Constant(value=SpecialFloatPlaceholder.NEG_INF.value)
40
+ return self.generic_visit(node)
41
+
42
+
43
+ def _restore_special_floats(data: Any) -> Any:
44
+ """
45
+ Restores placeholders for special float values (inf, -inf, nan) to their actual
46
+ float values in a nested data structure.
47
+ """
48
+ if isinstance(data, dict):
49
+ return {key: _restore_special_floats(value) for key, value in data.items()}
50
+ elif isinstance(data, list):
51
+ return [_restore_special_floats(item) for item in data]
52
+ elif isinstance(data, str):
53
+ if data == SpecialFloatPlaceholder.INF.value:
54
+ return float('inf')
55
+ elif data == SpecialFloatPlaceholder.NEG_INF.value:
56
+ return float('-inf')
57
+ elif data == SpecialFloatPlaceholder.NAN.value:
58
+ return float('nan')
59
+ return data
60
+
61
+
62
+ def parse(object_string: str) -> Any:
63
+ """
64
+ Parses a printed Python object, handling special float values (inf, -inf, nan).
65
+ If any error occurs, the original string is returned.
66
+ """
67
+ try:
68
+ if not object_string:
69
+ return None
70
+
71
+ # Parse the string as a Python expression
72
+ ast_node = ast.parse(object_string, mode='eval').body
73
+
74
+ # Replace inf/nan with placeholders
75
+ transformer = _SpecialFloatValuesTransformer()
76
+ transformed_ast_node = transformer.visit(ast_node)
77
+
78
+ # Evaluate the AST node to get the actual value.
79
+ data_with_placeholders = ast.literal_eval(transformed_ast_node)
80
+
81
+ # Restore placeholders to actual float values
82
+ return _restore_special_floats(data_with_placeholders)
83
+ except Exception:
84
+ return object_string
@@ -48,6 +48,7 @@ from ..utils.common import ensure_bytes, to_native_string
48
48
  from ..utils.fips import enable_fips
49
49
  from ..utils.tagging import GENERIC_TAGS
50
50
  from ..utils.tracing import traced_class
51
+ from ._config_ast import parse as _parse_ast_config
51
52
 
52
53
  if AGENT_RUNNING:
53
54
  from ..log import CheckLoggingAdapter, init_logging
@@ -1488,9 +1489,4 @@ class AgentCheck(object):
1488
1489
  if process.returncode != 0:
1489
1490
  raise ValueError(f'Failed to load config: {stderr.decode()}')
1490
1491
 
1491
- decoded = stdout.strip().decode()
1492
- try:
1493
- return eval(decoded)
1494
- # a single, literal unquoted string
1495
- except Exception:
1496
- return decoded
1492
+ return _parse_ast_config(stdout.strip().decode())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: datadog-checks-base
3
- Version: 37.13.0
3
+ Version: 37.15.0
4
4
  Summary: The Datadog Check Toolkit
5
5
  Project-URL: Source, https://github.com/DataDog/integrations-core
6
6
  Author-email: Datadog <packages@datadoghq.com>
@@ -18,24 +18,24 @@ Provides-Extra: deps
18
18
  Requires-Dist: binary==1.0.1; extra == 'deps'
19
19
  Requires-Dist: cachetools==6.0.0; extra == 'deps'
20
20
  Requires-Dist: cryptography==45.0.3; extra == 'deps'
21
- Requires-Dist: ddtrace==3.8.0; extra == 'deps'
21
+ Requires-Dist: ddtrace==3.9.1; extra == 'deps'
22
22
  Requires-Dist: jellyfish==1.2.0; extra == 'deps'
23
23
  Requires-Dist: lazy-loader==0.4; extra == 'deps'
24
- Requires-Dist: prometheus-client==0.22.0; extra == 'deps'
25
- Requires-Dist: protobuf==6.31.0; extra == 'deps'
24
+ Requires-Dist: prometheus-client==0.22.1; extra == 'deps'
25
+ Requires-Dist: protobuf==6.31.1; extra == 'deps'
26
26
  Requires-Dist: pydantic==2.11.5; extra == 'deps'
27
27
  Requires-Dist: python-dateutil==2.9.0.post0; extra == 'deps'
28
28
  Requires-Dist: pywin32==310; (sys_platform == 'win32') and extra == 'deps'
29
29
  Requires-Dist: pyyaml==6.0.2; extra == 'deps'
30
30
  Requires-Dist: requests-toolbelt==1.0.0; extra == 'deps'
31
31
  Requires-Dist: requests-unixsocket2==1.0.0; extra == 'deps'
32
- Requires-Dist: requests==2.32.3; extra == 'deps'
32
+ Requires-Dist: requests==2.32.4; extra == 'deps'
33
33
  Requires-Dist: simplejson==3.20.1; extra == 'deps'
34
34
  Requires-Dist: urllib3==2.4.0; extra == 'deps'
35
35
  Requires-Dist: wrapt==1.17.2; extra == 'deps'
36
36
  Provides-Extra: http
37
37
  Requires-Dist: aws-requests-auth==0.4.3; extra == 'http'
38
- Requires-Dist: botocore==1.38.24; extra == 'http'
38
+ Requires-Dist: botocore==1.38.32; extra == 'http'
39
39
  Requires-Dist: oauthlib==3.2.2; extra == 'http'
40
40
  Requires-Dist: pyjwt==2.10.1; extra == 'http'
41
41
  Requires-Dist: pyopenssl==25.1.0; extra == 'http'
@@ -3,7 +3,7 @@ datadog_checks/config.py,sha256=PrAXGdlLnoV2VMQff_noSaSJJ0wg4BAiGnw7jCQLSik,196
3
3
  datadog_checks/errors.py,sha256=eFwmnrX-batIgbu-iJyseqAPNO_4rk1UuaKK89evLhg,155
4
4
  datadog_checks/log.py,sha256=orvOgMKGNEsqSTLalCAQpWP-ouorpG1A7Gn-j2mRD80,301
5
5
  datadog_checks/py.typed,sha256=la67KBlbjXN-_-DfGNcdOcjYumVpKG_Tkw-8n5dnGB4,8
6
- datadog_checks/base/__about__.py,sha256=lB4-_xYUmOUSD8CzIo0yXKB4H2tiej7dQ2fEkgCdyHw,139
6
+ datadog_checks/base/__about__.py,sha256=FWWR7jAyvwkUM_4VgFGv7MU2D_yjzNuII5JoID5lwPQ,139
7
7
  datadog_checks/base/__init__.py,sha256=yWegSLE-TZWIGSvAiJj9PSrUxzlOo_UVJLt2zORZ8Ek,363
8
8
  datadog_checks/base/__init__.pyi,sha256=eH8XhrtvnD6uE6FWfEyCmKwOaaLJxNolS08D6IRHZuU,995
9
9
  datadog_checks/base/agent.py,sha256=nX9x_BYYizRKGNYfXq5z7S0FZ9xcX_wd2tuxpGe3_8k,350
@@ -14,7 +14,8 @@ datadog_checks/base/log.py,sha256=gSfzYimmg0z3Dgmn8NpXuyMNjgXwmTbn0NcyUX8B1ls,62
14
14
  datadog_checks/base/types.py,sha256=anajZS0W0TsxUHJQw-JHOP2NSeuC9BisXSy9mAStlxQ,1623
15
15
  datadog_checks/base/checks/__init__.py,sha256=q7V6v-FwQWkQC1QWaVzKaPjZMaxPJHJcLd71C0uM7bA,211
16
16
  datadog_checks/base/checks/__init__.pyi,sha256=LASfm-daLNQIYe6-w0NPqBw4cl83nYIX5_B-VhV6ARo,262
17
- datadog_checks/base/checks/base.py,sha256=gIXjMpJPn9j6cBUA8949vPFculWB6bG-V7WvO_ce4RA,59948
17
+ datadog_checks/base/checks/_config_ast.py,sha256=v1rAhwORF80b3kfZKhf6zXZ7S5D3A2QPUK4tSo8eo-Y,3268
18
+ datadog_checks/base/checks/base.py,sha256=q-V8fzkJ3MMbRnhHzhE7wyuolfukXsZ_sq-Ih_PWWkw,59873
18
19
  datadog_checks/base/checks/network.py,sha256=UijP1OVBCpCNKMy6bVkNazHgy6Sdm8qCvCYGPaWuTDo,1968
19
20
  datadog_checks/base/checks/kube_leader/__init__.py,sha256=q7V6v-FwQWkQC1QWaVzKaPjZMaxPJHJcLd71C0uM7bA,211
20
21
  datadog_checks/base/checks/kube_leader/__init__.pyi,sha256=UGDywoRwmCIz3Zii1uHsp7jiFGWRdn5fFMZZxgGGlQs,398
@@ -217,6 +218,6 @@ datadog_checks/utils/tracing.py,sha256=HQbQakKM-Lw75MDkItaYJYipS6YO24Z_ymDVxDsx5
217
218
  datadog_checks/utils/prometheus/__init__.py,sha256=8WwXnM9g1sfS5267QYCJX_hd8MZl5kRgBgQ_SzdNdXs,161
218
219
  datadog_checks/utils/prometheus/functions.py,sha256=4vWsTGLgujHwdYZo0tlAQkqDPHofqUJM3k9eItJqERQ,197
219
220
  datadog_checks/utils/prometheus/metrics_pb2.py,sha256=xg3UdUHe4TjeR4s13LUKZ2U1WVSt6U6zjsVRG6lX6dc,173
220
- datadog_checks_base-37.13.0.dist-info/METADATA,sha256=fEpcawGlBAaVY_ESNFrALlVN9FGTQBSt5fUByiRAPA0,4245
221
- datadog_checks_base-37.13.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
222
- datadog_checks_base-37.13.0.dist-info/RECORD,,
221
+ datadog_checks_base-37.15.0.dist-info/METADATA,sha256=CUQ731u-GuA4NgGfXFBBLL5wAjuvDdbsqIC3SYgbT34,4245
222
+ datadog_checks_base-37.15.0.dist-info/WHEEL,sha256=tkmg4JIqwd9H8mL30xA7crRmoStyCtGp0VWshokd1Jc,105
223
+ datadog_checks_base-37.15.0.dist-info/RECORD,,