dory-processor-sdk 0.0.1__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.
- dory/__init__.py +101 -0
- dory/auth/__init__.py +10 -0
- dory/auth/oauth2.py +153 -0
- dory/auto_instrument.py +142 -0
- dory/cli/__init__.py +5 -0
- dory/cli/main.py +137 -0
- dory/cli/templates.py +123 -0
- dory/config/__init__.py +23 -0
- dory/config/defaults.py +24 -0
- dory/config/loader.py +430 -0
- dory/config/presets.py +73 -0
- dory/config/schema.py +84 -0
- dory/core/__init__.py +27 -0
- dory/core/app.py +434 -0
- dory/core/context.py +209 -0
- dory/core/lifecycle.py +214 -0
- dory/core/meta.py +121 -0
- dory/core/modes.py +479 -0
- dory/core/processor.py +564 -0
- dory/core/signals.py +122 -0
- dory/decorators.py +142 -0
- dory/edge/__init__.py +88 -0
- dory/edge/adaptive.py +644 -0
- dory/edge/detector.py +546 -0
- dory/edge/fencing.py +488 -0
- dory/edge/heartbeat.py +598 -0
- dory/edge/role.py +419 -0
- dory/errors/__init__.py +139 -0
- dory/errors/classification.py +362 -0
- dory/errors/codes.py +498 -0
- dory/geo/__init__.py +40 -0
- dory/geo/geolocalizer.py +1034 -0
- dory/health/__init__.py +12 -0
- dory/health/probes.py +210 -0
- dory/health/server.py +635 -0
- dory/k8s/__init__.py +80 -0
- dory/k8s/annotation_watcher.py +184 -0
- dory/k8s/client.py +251 -0
- dory/k8s/labels.py +505 -0
- dory/k8s/pod_metadata.py +182 -0
- dory/logging/__init__.py +9 -0
- dory/logging/logger.py +148 -0
- dory/metrics/__init__.py +7 -0
- dory/metrics/collector.py +301 -0
- dory/middleware/__init__.py +46 -0
- dory/middleware/connection_tracker.py +608 -0
- dory/middleware/request_id.py +325 -0
- dory/middleware/request_tracker.py +511 -0
- dory/migration/__init__.py +33 -0
- dory/migration/configmap.py +232 -0
- dory/migration/s3_store.py +594 -0
- dory/migration/serialization.py +135 -0
- dory/migration/state_manager.py +286 -0
- dory/migration/transfer.py +382 -0
- dory/monitoring/__init__.py +29 -0
- dory/monitoring/opentelemetry.py +489 -0
- dory/output/__init__.py +31 -0
- dory/output/envelope.py +137 -0
- dory/output/formatter.py +113 -0
- dory/output/rabbitmq.py +632 -0
- dory/output/routing.py +318 -0
- dory/output/validator.py +199 -0
- dory/py.typed +2 -0
- dory/recovery/__init__.py +60 -0
- dory/recovery/golden_image.py +487 -0
- dory/recovery/golden_snapshot.py +713 -0
- dory/recovery/golden_validator.py +518 -0
- dory/recovery/partial_recovery.py +482 -0
- dory/recovery/recovery_decision.py +242 -0
- dory/recovery/restart_detector.py +142 -0
- dory/recovery/state_validator.py +183 -0
- dory/resilience/__init__.py +45 -0
- dory/resilience/circuit_breaker.py +457 -0
- dory/resilience/retry.py +389 -0
- dory/simple.py +342 -0
- dory/types.py +68 -0
- dory/utils/__init__.py +31 -0
- dory/utils/errors.py +59 -0
- dory/utils/retry.py +115 -0
- dory/utils/timeout.py +80 -0
- dory_processor_sdk-0.0.1.dist-info/METADATA +424 -0
- dory_processor_sdk-0.0.1.dist-info/RECORD +86 -0
- dory_processor_sdk-0.0.1.dist-info/WHEEL +5 -0
- dory_processor_sdk-0.0.1.dist-info/entry_points.txt +2 -0
- dory_processor_sdk-0.0.1.dist-info/licenses/LICENSE +201 -0
- dory_processor_sdk-0.0.1.dist-info/top_level.txt +1 -0
dory/output/formatter.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Output formatting for processor results.
|
|
3
|
+
|
|
4
|
+
Provides pluggable formatters for serializing data before publishing.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import dataclasses
|
|
8
|
+
import json
|
|
9
|
+
import logging
|
|
10
|
+
from abc import ABC, abstractmethod
|
|
11
|
+
from datetime import datetime, date
|
|
12
|
+
from enum import Enum
|
|
13
|
+
from typing import Any
|
|
14
|
+
from uuid import UUID
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OutputFormatter(ABC):
|
|
20
|
+
"""Abstract base class for output formatters."""
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def format(self, data: Any) -> bytes:
|
|
24
|
+
"""Serialize data to bytes.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
data: Data to serialize.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Serialized bytes.
|
|
31
|
+
"""
|
|
32
|
+
raise NotImplementedError
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def content_type(self) -> str:
|
|
37
|
+
"""MIME type for the formatted output."""
|
|
38
|
+
raise NotImplementedError
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class JSONFormatter(OutputFormatter):
|
|
42
|
+
"""JSON output formatter with support for common Python types.
|
|
43
|
+
|
|
44
|
+
Handles serialization of datetime, UUID, Enum, and dataclass objects
|
|
45
|
+
via a custom default handler.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
indent: JSON indentation level (None for compact).
|
|
49
|
+
sort_keys: Whether to sort dictionary keys.
|
|
50
|
+
max_size_bytes: Maximum allowed output size in bytes (0 = unlimited).
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
def __init__(
|
|
54
|
+
self,
|
|
55
|
+
indent: int | None = None,
|
|
56
|
+
sort_keys: bool = False,
|
|
57
|
+
max_size_bytes: int = 0,
|
|
58
|
+
):
|
|
59
|
+
self._indent = indent
|
|
60
|
+
self._sort_keys = sort_keys
|
|
61
|
+
self._max_size_bytes = max_size_bytes
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def content_type(self) -> str:
|
|
65
|
+
return "application/json"
|
|
66
|
+
|
|
67
|
+
def format(self, data: Any) -> bytes:
|
|
68
|
+
"""Serialize data to UTF-8 encoded JSON bytes.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
data: Data to serialize. Must be JSON-serializable
|
|
72
|
+
(with support for datetime, UUID, Enum, dataclass).
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
UTF-8 encoded JSON bytes.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
TypeError: If data contains non-serializable types.
|
|
79
|
+
ValueError: If serialized output exceeds max_size_bytes.
|
|
80
|
+
"""
|
|
81
|
+
encoded = json.dumps(
|
|
82
|
+
data,
|
|
83
|
+
default=self._default_handler,
|
|
84
|
+
indent=self._indent,
|
|
85
|
+
sort_keys=self._sort_keys,
|
|
86
|
+
ensure_ascii=False,
|
|
87
|
+
).encode("utf-8")
|
|
88
|
+
|
|
89
|
+
if self._max_size_bytes > 0 and len(encoded) > self._max_size_bytes:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
f"Serialized output size {len(encoded)} bytes exceeds "
|
|
92
|
+
f"max_size_bytes limit of {self._max_size_bytes}"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
return encoded
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def _default_handler(obj: Any) -> Any:
|
|
99
|
+
"""Handle non-standard JSON types.
|
|
100
|
+
|
|
101
|
+
Supports: datetime, date, UUID, Enum, dataclass.
|
|
102
|
+
"""
|
|
103
|
+
if isinstance(obj, datetime):
|
|
104
|
+
return obj.isoformat()
|
|
105
|
+
if isinstance(obj, date):
|
|
106
|
+
return obj.isoformat()
|
|
107
|
+
if isinstance(obj, UUID):
|
|
108
|
+
return str(obj)
|
|
109
|
+
if isinstance(obj, Enum):
|
|
110
|
+
return obj.value
|
|
111
|
+
if dataclasses.is_dataclass(obj) and not isinstance(obj, type):
|
|
112
|
+
return dataclasses.asdict(obj)
|
|
113
|
+
raise TypeError(f"Object of type {type(obj).__name__} is not JSON serializable")
|