netra-zen 1.2.1__py3-none-any.whl → 1.2.3__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,124 +1,124 @@
1
- """
2
- WebSocket closure code definitions and categorization.
3
-
4
- Provides enums and helper functions for validating and categorizing WebSocket
5
- closure codes according to RFC 6455 and common extensions.
6
- """
7
-
8
- from enum import IntEnum
9
- from typing import Optional
10
-
11
-
12
- class WebSocketClosureCode(IntEnum):
13
- """
14
- Standard WebSocket closure codes from RFC 6455 and extensions.
15
-
16
- See: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1
17
- """
18
- # Standard codes (1000-1015)
19
- NORMAL_CLOSURE = 1000
20
- GOING_AWAY = 1001
21
- PROTOCOL_ERROR = 1002
22
- UNSUPPORTED_DATA = 1003
23
- # 1004 is reserved
24
- NO_STATUS_RECEIVED = 1005
25
- ABNORMAL_CLOSURE = 1006
26
- INVALID_FRAME_PAYLOAD_DATA = 1007
27
- POLICY_VIOLATION = 1008
28
- MESSAGE_TOO_BIG = 1009
29
- MANDATORY_EXTENSION = 1010
30
- INTERNAL_SERVER_ERROR = 1011
31
- SERVICE_RESTART = 1012
32
- TRY_AGAIN_LATER = 1013
33
- BAD_GATEWAY = 1014
34
- TLS_HANDSHAKE_FAILURE = 1015
35
-
36
- # Custom application codes (4000-4999)
37
- # These are application-specific and can be defined as needed
38
-
39
-
40
- class WebSocketClosureCategory(IntEnum):
41
- """
42
- Categories for WebSocket closure codes to classify failure types.
43
- """
44
- NORMAL = 0 # Expected closures (1000, 1001)
45
- CLIENT_ERROR = 1 # Client-side errors (1002-1003, 1007-1010)
46
- SERVER_ERROR = 2 # Server-side errors (1011-1014)
47
- INFRASTRUCTURE = 3 # Infrastructure/network errors (1006, 1015)
48
- UNKNOWN = 4 # Unrecognized codes
49
-
50
-
51
- def categorize_closure_code(code: int) -> WebSocketClosureCategory:
52
- """
53
- Categorize a WebSocket closure code into a failure category.
54
-
55
- Args:
56
- code: The WebSocket closure code
57
-
58
- Returns:
59
- The category of the closure code
60
- """
61
- # Normal closures
62
- if code in (1000, 1001):
63
- return WebSocketClosureCategory.NORMAL
64
-
65
- # Infrastructure/network errors
66
- if code in (1006, 1015):
67
- return WebSocketClosureCategory.INFRASTRUCTURE
68
-
69
- # Server errors
70
- if code in (1011, 1012, 1013, 1014):
71
- return WebSocketClosureCategory.SERVER_ERROR
72
-
73
- # Client errors
74
- if code in (1002, 1003, 1007, 1008, 1009, 1010):
75
- return WebSocketClosureCategory.CLIENT_ERROR
76
-
77
- # Unknown/unrecognized codes
78
- return WebSocketClosureCategory.UNKNOWN
79
-
80
-
81
- def is_infrastructure_error(code: int) -> bool:
82
- """
83
- Check if a closure code represents an infrastructure/network error.
84
-
85
- Infrastructure errors are typically transient and may be retryable.
86
-
87
- Args:
88
- code: The WebSocket closure code
89
-
90
- Returns:
91
- True if the code represents an infrastructure error
92
- """
93
- return categorize_closure_code(code) == WebSocketClosureCategory.INFRASTRUCTURE
94
-
95
-
96
- def get_closure_description(code: int) -> str:
97
- """
98
- Get a human-readable description of a WebSocket closure code.
99
-
100
- Args:
101
- code: The WebSocket closure code
102
-
103
- Returns:
104
- A description of what the closure code means
105
- """
106
- descriptions = {
107
- 1000: "Normal closure - connection completed successfully",
108
- 1001: "Going away - endpoint is going away (e.g., server shutdown, browser navigation)",
109
- 1002: "Protocol error - endpoint received a malformed message",
110
- 1003: "Unsupported data - endpoint received data of unsupported type",
111
- 1005: "No status received - no status code was provided (internal use only)",
112
- 1006: "Abnormal closure - connection closed without close frame (network/infrastructure issue)",
113
- 1007: "Invalid frame payload data - message contains invalid UTF-8 or violates payload requirements",
114
- 1008: "Policy violation - endpoint received message that violates its policy",
115
- 1009: "Message too big - endpoint received message that is too large to process",
116
- 1010: "Mandatory extension - client expected server to negotiate an extension",
117
- 1011: "Internal server error - server encountered unexpected condition",
118
- 1012: "Service restart - server is restarting",
119
- 1013: "Try again later - server is temporarily overloaded or under maintenance",
120
- 1014: "Bad gateway - server acting as gateway received invalid response",
121
- 1015: "TLS handshake failure - TLS handshake failed (internal use only)",
122
- }
123
-
124
- return descriptions.get(code, f"Unknown closure code: {code}")
1
+ """
2
+ WebSocket closure code definitions and categorization.
3
+
4
+ Provides enums and helper functions for validating and categorizing WebSocket
5
+ closure codes according to RFC 6455 and common extensions.
6
+ """
7
+
8
+ from enum import IntEnum
9
+ from typing import Optional
10
+
11
+
12
+ class WebSocketClosureCode(IntEnum):
13
+ """
14
+ Standard WebSocket closure codes from RFC 6455 and extensions.
15
+
16
+ See: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1
17
+ """
18
+ # Standard codes (1000-1015)
19
+ NORMAL_CLOSURE = 1000
20
+ GOING_AWAY = 1001
21
+ PROTOCOL_ERROR = 1002
22
+ UNSUPPORTED_DATA = 1003
23
+ # 1004 is reserved
24
+ NO_STATUS_RECEIVED = 1005
25
+ ABNORMAL_CLOSURE = 1006
26
+ INVALID_FRAME_PAYLOAD_DATA = 1007
27
+ POLICY_VIOLATION = 1008
28
+ MESSAGE_TOO_BIG = 1009
29
+ MANDATORY_EXTENSION = 1010
30
+ INTERNAL_SERVER_ERROR = 1011
31
+ SERVICE_RESTART = 1012
32
+ TRY_AGAIN_LATER = 1013
33
+ BAD_GATEWAY = 1014
34
+ TLS_HANDSHAKE_FAILURE = 1015
35
+
36
+ # Custom application codes (4000-4999)
37
+ # These are application-specific and can be defined as needed
38
+
39
+
40
+ class WebSocketClosureCategory(IntEnum):
41
+ """
42
+ Categories for WebSocket closure codes to classify failure types.
43
+ """
44
+ NORMAL = 0 # Expected closures (1000, 1001)
45
+ CLIENT_ERROR = 1 # Client-side errors (1002-1003, 1007-1010)
46
+ SERVER_ERROR = 2 # Server-side errors (1011-1014)
47
+ INFRASTRUCTURE = 3 # Infrastructure/network errors (1006, 1015)
48
+ UNKNOWN = 4 # Unrecognized codes
49
+
50
+
51
+ def categorize_closure_code(code: int) -> WebSocketClosureCategory:
52
+ """
53
+ Categorize a WebSocket closure code into a failure category.
54
+
55
+ Args:
56
+ code: The WebSocket closure code
57
+
58
+ Returns:
59
+ The category of the closure code
60
+ """
61
+ # Normal closures
62
+ if code in (1000, 1001):
63
+ return WebSocketClosureCategory.NORMAL
64
+
65
+ # Infrastructure/network errors
66
+ if code in (1006, 1015):
67
+ return WebSocketClosureCategory.INFRASTRUCTURE
68
+
69
+ # Server errors
70
+ if code in (1011, 1012, 1013, 1014):
71
+ return WebSocketClosureCategory.SERVER_ERROR
72
+
73
+ # Client errors
74
+ if code in (1002, 1003, 1007, 1008, 1009, 1010):
75
+ return WebSocketClosureCategory.CLIENT_ERROR
76
+
77
+ # Unknown/unrecognized codes
78
+ return WebSocketClosureCategory.UNKNOWN
79
+
80
+
81
+ def is_infrastructure_error(code: int) -> bool:
82
+ """
83
+ Check if a closure code represents an infrastructure/network error.
84
+
85
+ Infrastructure errors are typically transient and may be retryable.
86
+
87
+ Args:
88
+ code: The WebSocket closure code
89
+
90
+ Returns:
91
+ True if the code represents an infrastructure error
92
+ """
93
+ return categorize_closure_code(code) == WebSocketClosureCategory.INFRASTRUCTURE
94
+
95
+
96
+ def get_closure_description(code: int) -> str:
97
+ """
98
+ Get a human-readable description of a WebSocket closure code.
99
+
100
+ Args:
101
+ code: The WebSocket closure code
102
+
103
+ Returns:
104
+ A description of what the closure code means
105
+ """
106
+ descriptions = {
107
+ 1000: "Normal closure - connection completed successfully",
108
+ 1001: "Going away - endpoint is going away (e.g., server shutdown, browser navigation)",
109
+ 1002: "Protocol error - endpoint received a malformed message",
110
+ 1003: "Unsupported data - endpoint received data of unsupported type",
111
+ 1005: "No status received - no status code was provided (internal use only)",
112
+ 1006: "Abnormal closure - connection closed without close frame (network/infrastructure issue)",
113
+ 1007: "Invalid frame payload data - message contains invalid UTF-8 or violates payload requirements",
114
+ 1008: "Policy violation - endpoint received message that violates its policy",
115
+ 1009: "Message too big - endpoint received message that is too large to process",
116
+ 1010: "Mandatory extension - client expected server to negotiate an extension",
117
+ 1011: "Internal server error - server encountered unexpected condition",
118
+ 1012: "Service restart - server is restarting",
119
+ 1013: "Try again later - server is temporarily overloaded or under maintenance",
120
+ 1014: "Bad gateway - server acting as gateway received invalid response",
121
+ 1015: "TLS handshake failure - TLS handshake failed (internal use only)",
122
+ }
123
+
124
+ return descriptions.get(code, f"Unknown closure code: {code}")
@@ -1,45 +1,45 @@
1
- """
2
- Windows UTF-8 console encoding fixes.
3
-
4
- Ensures proper UTF-8 handling on Windows consoles by setting appropriate
5
- encoding for stdin, stdout, and stderr streams.
6
- """
7
-
8
- import sys
9
- import io
10
-
11
-
12
- def setup_windows_encoding():
13
- """
14
- Configure Windows console to use UTF-8 encoding.
15
-
16
- This function reconfigures sys.stdin, sys.stdout, and sys.stderr to use
17
- UTF-8 encoding with error handling on Windows platforms. This prevents
18
- Unicode encoding errors when displaying special characters or emoji.
19
-
20
- Must be called early in the startup sequence before any console I/O.
21
- """
22
- if sys.platform == "win32":
23
- # Reconfigure stdout and stderr to use UTF-8 with error handling
24
- if sys.stdout is not None:
25
- sys.stdout = io.TextIOWrapper(
26
- sys.stdout.buffer,
27
- encoding='utf-8',
28
- errors='replace',
29
- line_buffering=True
30
- )
31
-
32
- if sys.stderr is not None:
33
- sys.stderr = io.TextIOWrapper(
34
- sys.stderr.buffer,
35
- encoding='utf-8',
36
- errors='replace',
37
- line_buffering=True
38
- )
39
-
40
- if sys.stdin is not None:
41
- sys.stdin = io.TextIOWrapper(
42
- sys.stdin.buffer,
43
- encoding='utf-8',
44
- errors='replace'
45
- )
1
+ """
2
+ Windows UTF-8 console encoding fixes.
3
+
4
+ Ensures proper UTF-8 handling on Windows consoles by setting appropriate
5
+ encoding for stdin, stdout, and stderr streams.
6
+ """
7
+
8
+ import sys
9
+ import io
10
+
11
+
12
+ def setup_windows_encoding():
13
+ """
14
+ Configure Windows console to use UTF-8 encoding.
15
+
16
+ This function reconfigures sys.stdin, sys.stdout, and sys.stderr to use
17
+ UTF-8 encoding with error handling on Windows platforms. This prevents
18
+ Unicode encoding errors when displaying special characters or emoji.
19
+
20
+ Must be called early in the startup sequence before any console I/O.
21
+ """
22
+ if sys.platform == "win32":
23
+ # Reconfigure stdout and stderr to use UTF-8 with error handling
24
+ if sys.stdout is not None:
25
+ sys.stdout = io.TextIOWrapper(
26
+ sys.stdout.buffer,
27
+ encoding='utf-8',
28
+ errors='replace',
29
+ line_buffering=True
30
+ )
31
+
32
+ if sys.stderr is not None:
33
+ sys.stderr = io.TextIOWrapper(
34
+ sys.stderr.buffer,
35
+ encoding='utf-8',
36
+ errors='replace',
37
+ line_buffering=True
38
+ )
39
+
40
+ if sys.stdin is not None:
41
+ sys.stdin = io.TextIOWrapper(
42
+ sys.stdin.buffer,
43
+ encoding='utf-8',
44
+ errors='replace'
45
+ )
zen/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
- """Zen namespace package placeholder.
2
-
3
- This lightweight module exists so repository scripts can import
4
- `zen.telemetry` directly without requiring the full orchestrator package.
5
- """
6
-
7
- __all__: list[str] = []
1
+ """Zen namespace package placeholder.
2
+
3
+ This lightweight module exists so repository scripts can import
4
+ `zen.telemetry` directly without requiring the full orchestrator package.
5
+ """
6
+
7
+ __all__: list[str] = []
zen/__main__.py CHANGED
@@ -1,11 +1,11 @@
1
- """Module entry point to support `python -m zen` invocation."""
2
-
3
- from zen_orchestrator import run
4
-
5
-
6
- def main() -> None:
7
- run()
8
-
9
-
10
- if __name__ == "__main__":
11
- main()
1
+ """Module entry point to support `python -m zen` invocation."""
2
+
3
+ from zen_orchestrator import run
4
+
5
+
6
+ def main() -> None:
7
+ run()
8
+
9
+
10
+ if __name__ == "__main__":
11
+ main()
zen/telemetry/__init__.py CHANGED
@@ -1,14 +1,14 @@
1
- """Telemetry utilities exposed by the Zen package."""
2
-
3
- from .embedded_credentials import get_embedded_credentials, get_project_id
4
- from .manager import TelemetryManager, telemetry_manager
5
- from .apex_telemetry import run_apex_with_telemetry, ApexTelemetryWrapper
6
-
7
- __all__ = [
8
- "TelemetryManager",
9
- "telemetry_manager",
10
- "get_embedded_credentials",
11
- "get_project_id",
12
- "run_apex_with_telemetry",
13
- "ApexTelemetryWrapper",
14
- ]
1
+ """Telemetry utilities exposed by the Zen package."""
2
+
3
+ from .embedded_credentials import get_embedded_credentials, get_project_id
4
+ from .manager import TelemetryManager, telemetry_manager
5
+ from .apex_telemetry import run_apex_with_telemetry, ApexTelemetryWrapper
6
+
7
+ __all__ = [
8
+ "TelemetryManager",
9
+ "telemetry_manager",
10
+ "get_embedded_credentials",
11
+ "get_project_id",
12
+ "run_apex_with_telemetry",
13
+ "ApexTelemetryWrapper",
14
+ ]