DefStream 0.1.13__44-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.
Files changed (56) hide show
  1. DefStream/Broker/Configuration.py +18 -0
  2. DefStream/Broker/Connection.py +141 -0
  3. DefStream/Broker/Consumer.py +59 -0
  4. DefStream/Broker/Errors.py +14 -0
  5. DefStream/Broker/Event.py +35 -0
  6. DefStream/Broker/Implements/__init__.py +1 -0
  7. DefStream/Broker/Policies.py +25 -0
  8. DefStream/Broker/Priority.py +26 -0
  9. DefStream/Broker/Protocol.py +45 -0
  10. DefStream/Broker/__init__.py +59 -0
  11. DefStream/Descriptor/DataObject.py +409 -0
  12. DefStream/Descriptor/Types.py +248 -0
  13. DefStream/Descriptor/Value.py +188 -0
  14. DefStream/Descriptor/__init__.py +172 -0
  15. DefStream/Inspector/Extension.py +69 -0
  16. DefStream/Inspector/Extensions/Console.html +373 -0
  17. DefStream/Inspector/Extensions/Console.py +415 -0
  18. DefStream/Inspector/Extensions/Dashboard.html +206 -0
  19. DefStream/Inspector/Extensions/Dashboard.py +124 -0
  20. DefStream/Inspector/Extensions/HealthCheck.py +107 -0
  21. DefStream/Inspector/Extensions/Metrics.py +316 -0
  22. DefStream/Inspector/Extensions/Specifications.py +176 -0
  23. DefStream/Inspector/Extensions/__init__.py +13 -0
  24. DefStream/Inspector/Inspector.py +347 -0
  25. DefStream/Inspector/Response.py +14 -0
  26. DefStream/Inspector/__init__.py +9 -0
  27. DefStream/Validator/Pattern.py +36 -0
  28. DefStream/Validator/Patterns/Array.py +30 -0
  29. DefStream/Validator/Patterns/Common.py +93 -0
  30. DefStream/Validator/Patterns/Compare.py +180 -0
  31. DefStream/Validator/Patterns/Condition.py +60 -0
  32. DefStream/Validator/Patterns/DataObject.py +85 -0
  33. DefStream/Validator/Patterns/DateTime.py +111 -0
  34. DefStream/Validator/Patterns/Number.py +43 -0
  35. DefStream/Validator/Patterns/Object.py +150 -0
  36. DefStream/Validator/Patterns/Size.py +110 -0
  37. DefStream/Validator/Patterns/String.py +85 -0
  38. DefStream/Validator/Patterns/Type.py +350 -0
  39. DefStream/Validator/Patterns/__init__.py +137 -0
  40. DefStream/Validator/Validate.py +29 -0
  41. DefStream/Validator/Validator.py +30 -0
  42. DefStream/Validator/__init__.py +11 -0
  43. DefStream/Worker/Executor.py +371 -0
  44. DefStream/Worker/Message.py +180 -0
  45. DefStream/Worker/Pool.py +245 -0
  46. DefStream/Worker/Run.py +357 -0
  47. DefStream/Worker/Specification.py +87 -0
  48. DefStream/Worker/Startup.py +174 -0
  49. DefStream/Worker/Worker.py +421 -0
  50. DefStream/Worker/__init__.py +47 -0
  51. DefStream/__init__.py +0 -0
  52. defstream-0.1.13.dist-info/METADATA +679 -0
  53. defstream-0.1.13.dist-info/RECORD +56 -0
  54. defstream-0.1.13.dist-info/WHEEL +6 -0
  55. defstream-0.1.13.dist-info/licenses/LICENSE +674 -0
  56. defstream-0.1.13.dist-info/top_level.txt +1 -0
@@ -0,0 +1,188 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from collections.abc import Mapping
4
+
5
+ from enum import Enum
6
+ from typing import (
7
+ Any,
8
+ Iterator,
9
+ KeysView,
10
+ ItemsView,
11
+ ValuesView,
12
+ Optional,
13
+ Dict,
14
+ Union,
15
+ Iterable,
16
+ Tuple,
17
+ )
18
+ from abc import (
19
+ ABCMeta,
20
+ ABC,
21
+ )
22
+
23
+ __all__ = (
24
+ 'Type',
25
+ 'Value',
26
+ 'Condition',
27
+ 'Schema',
28
+ 'OneOf',
29
+ 'AllOf',
30
+ 'TypeMapper',
31
+ 'TypeEncoder',
32
+ )
33
+
34
+
35
+ class Descriptor(Mapping[str, Any]):
36
+ def __init__(
37
+ self,
38
+ **kwargs: Any,
39
+ ) -> None:
40
+ self.__properties__: Dict[str, Any] = kwargs
41
+ return
42
+
43
+ def __getitem__(
44
+ self,
45
+ key: str,
46
+ ) -> Any:
47
+ return self.__properties__.__getitem__(key)
48
+
49
+ def __setitem__(
50
+ self,
51
+ key: str,
52
+ value: Any,
53
+ ) -> None:
54
+ return self.__properties__.__setitem__(key, value)
55
+
56
+ def __delitem__(
57
+ self,
58
+ key: str,
59
+ ) -> None:
60
+ return self.__properties__.__delitem__(key)
61
+
62
+ def __iter__(self) -> Iterator[str]:
63
+ return self.__properties__.__iter__()
64
+
65
+ def __len__(self) -> int:
66
+ return self.__properties__.__len__()
67
+
68
+ def __contains__(
69
+ self,
70
+ key: object,
71
+ ) -> bool:
72
+ return self.__properties__.__contains__(key)
73
+
74
+ def keys(self) -> KeysView[str]:
75
+ return self.__properties__.keys()
76
+
77
+ def items(self) -> ItemsView[str, Any]:
78
+ return self.__properties__.items()
79
+
80
+ def values(self) -> ValuesView[Any]:
81
+ return self.__properties__.values()
82
+
83
+ def __eq__(
84
+ self,
85
+ other: object,
86
+ ) -> bool:
87
+ return self.__properties__.__eq__(other)
88
+
89
+ def __ne__(
90
+ self,
91
+ value: object,
92
+ ) -> bool:
93
+ return self.__properties__.__ne__(value)
94
+
95
+ def get(
96
+ self,
97
+ key: str,
98
+ default: Any = None,
99
+ ) -> Any:
100
+ return self.__properties__.get(key, default)
101
+
102
+
103
+ class Type(str, Enum):
104
+ Boolean = 'boolean'
105
+ Integer = 'integer'
106
+ Number = 'number'
107
+ String = 'string'
108
+ Array = 'array'
109
+ Object = 'object'
110
+
111
+
112
+ class Value(Descriptor):
113
+ def __init__(
114
+ self,
115
+ type: Type,
116
+ description: Optional[str] = None,
117
+ format: Optional[str] = None,
118
+ min: Any = None,
119
+ max: Any = None,
120
+ default: Any = None,
121
+ enum: Optional[Iterable[Any]] = None,
122
+ required: bool = True,
123
+ ) -> None:
124
+ super().__init__(type=type)
125
+ if description: self['description'] = description
126
+ if format: self['format'] = format
127
+ if min is not None: self['minimum'] = min
128
+ if max is not None: self['maximum'] = max
129
+ if not required: self['default'] = default
130
+ if enum: self['enum'] = enum
131
+ self.required = required
132
+ return
133
+
134
+
135
+ class Condition(ABC):
136
+ def __init__(
137
+ self,
138
+ *args: Union[Descriptor, 'Condition', 'Schema'],
139
+ ) -> None:
140
+ self.args = args
141
+ return
142
+
143
+
144
+ class Schema(object):
145
+ """Descriptor 노드, 조건 또는 JSON Schema 매핑을 이름으로 감싼다."""
146
+
147
+ def __init__(
148
+ self,
149
+ name: str,
150
+ format: Optional[Union[Mapping[str, Any], Condition, 'Schema']] = None,
151
+ ) -> None:
152
+ self.name = name
153
+ self.format = format
154
+ return
155
+
156
+
157
+ class OneOf(Condition):
158
+ def __init__(
159
+ self,
160
+ *args: Union[Descriptor, Condition, Schema],
161
+ discriminator: Optional[str] = None,
162
+ required: bool = True,
163
+ ) -> None:
164
+ super().__init__(*args)
165
+ self.discriminator = discriminator
166
+ self.required = required
167
+ return
168
+
169
+
170
+ class AllOf(Condition): pass
171
+
172
+
173
+ class TypeMapper(metaclass=ABCMeta):
174
+ """사용자 타입을 Value 파생 클래스와 생성 인자로 변환한다."""
175
+
176
+ def __call__(
177
+ self,
178
+ o: type,
179
+ ) -> Tuple[type[Value], Dict[str, Any]]:
180
+ raise NotImplementedError('{} must be implemented __call__'.format(self.__class__.__name__))
181
+
182
+
183
+ class TypeEncoder(metaclass=ABCMeta):
184
+ def __call__(
185
+ self,
186
+ o: Any,
187
+ ) -> Any:
188
+ raise NotImplementedError('{} must be implemented __call__'.format(self.__class__.__name__))
@@ -0,0 +1,172 @@
1
+ from collections.abc import (
2
+ Mapping,
3
+ Sequence,
4
+ )
5
+ from dataclasses import is_dataclass
6
+ from json import (
7
+ dumps,
8
+ loads,
9
+ )
10
+ from typing import (
11
+ Any,
12
+ Optional,
13
+ Type,
14
+ )
15
+
16
+ from .Value import (
17
+ Value,
18
+ Condition,
19
+ Schema,
20
+ OneOf,
21
+ AllOf,
22
+ TypeMapper,
23
+ TypeEncoder,
24
+ )
25
+ from .Types import (
26
+ Boolean,
27
+ IntegerFormat,
28
+ Integer,
29
+ NumberFormat,
30
+ Number,
31
+ StringFormat,
32
+ String,
33
+ Binary,
34
+ BinaryBase64Encoded,
35
+ Array,
36
+ Object,
37
+ Properties,
38
+ )
39
+ from .DataObject import (
40
+ DataObjectToSchema,
41
+ DataObjectToObject,
42
+ )
43
+
44
+ __all__ = (
45
+ 'Value',
46
+ 'Condition',
47
+ 'Schema',
48
+ 'OneOf',
49
+ 'AllOf',
50
+ 'TypeMapper',
51
+ 'TypeEncoder',
52
+ 'Boolean',
53
+ 'IntegerFormat',
54
+ 'Integer',
55
+ 'NumberFormat',
56
+ 'Number',
57
+ 'StringFormat',
58
+ 'String',
59
+ 'Binary',
60
+ 'BinaryBase64Encoded',
61
+ 'Array',
62
+ 'Object',
63
+ 'Properties',
64
+ 'ToSchema',
65
+ 'DumpSchema',
66
+ 'ToObject',
67
+ )
68
+
69
+
70
+ def schema_value(
71
+ value: Any,
72
+ ) -> Any:
73
+ if isinstance(
74
+ value,
75
+ Schema,
76
+ ):
77
+ return schema_value(value.format)
78
+ if isinstance(
79
+ value,
80
+ Condition,
81
+ ):
82
+ if isinstance(
83
+ value,
84
+ OneOf,
85
+ ):
86
+ key = 'oneOf'
87
+ elif isinstance(
88
+ value,
89
+ AllOf,
90
+ ):
91
+ key = 'allOf'
92
+ else:
93
+ raise TypeError('Unsupported schema condition: ' + type(value).__name__)
94
+ return {key: [schema_value(arg) for arg in value.args]}
95
+ if isinstance(
96
+ value,
97
+ Mapping,
98
+ ):
99
+ return {
100
+ key: schema_value(item) for key, item in value.items()
101
+ }
102
+ if isinstance(
103
+ value,
104
+ Sequence,
105
+ ) and not isinstance(
106
+ value,
107
+ (
108
+ str,
109
+ bytes,
110
+ bytearray,
111
+ ),
112
+ ):
113
+ return [schema_value(item) for item in value]
114
+ if value is None or isinstance(
115
+ value,
116
+ (
117
+ str,
118
+ int,
119
+ float,
120
+ bool,
121
+ ),
122
+ ):
123
+ return value
124
+ raise TypeError('Unsupported schema value: ' + type(value).__name__)
125
+
126
+
127
+ def DumpSchema(
128
+ o: Schema,
129
+ ) -> dict:
130
+ if not isinstance(
131
+ o,
132
+ Schema,
133
+ ):
134
+ raise TypeError('A Schema is required')
135
+ result = schema_value(o)
136
+ if not isinstance(
137
+ result,
138
+ dict,
139
+ ):
140
+ raise TypeError('A schema must describe an object, value or condition')
141
+ return loads(dumps(
142
+ result,
143
+ allow_nan=False,
144
+ ))
145
+
146
+
147
+ def ToSchema(
148
+ o: Type[object],
149
+ description: Optional[str] = None,
150
+ typedef: Optional[TypeMapper] = None,
151
+ ) -> Schema:
152
+ if not isinstance(
153
+ o,
154
+ type,
155
+ ) or not is_dataclass(o):
156
+ raise TypeError('A dataclass type is required')
157
+ return DataObjectToSchema(mapper=typedef)(
158
+ o,
159
+ description,
160
+ )
161
+
162
+
163
+ def ToObject(
164
+ o: object,
165
+ typeenc: Optional[TypeEncoder] = None,
166
+ ) -> dict:
167
+ if isinstance(
168
+ o,
169
+ type,
170
+ ) or not is_dataclass(o):
171
+ raise TypeError('A dataclass instance is required')
172
+ return DataObjectToObject(encoder=typeenc)(o)
@@ -0,0 +1,69 @@
1
+ from abc import (
2
+ ABC,
3
+ abstractmethod,
4
+ )
5
+ from typing import (
6
+ Optional,
7
+ TYPE_CHECKING,
8
+ )
9
+
10
+ from .Response import Response
11
+
12
+ if TYPE_CHECKING:
13
+ from .Inspector import Inspector
14
+
15
+ __all__ = (
16
+ 'Extension',
17
+ )
18
+
19
+
20
+ class Extension(ABC):
21
+ methods = (
22
+ 'GET',
23
+ 'HEAD',
24
+ )
25
+
26
+ def __init__(
27
+ self,
28
+ path: str,
29
+ ):
30
+ if not isinstance(
31
+ path,
32
+ str,
33
+ ) or not path.startswith('/') or '?' in path or '#' in path:
34
+ raise ValueError('An absolute HTTP path without a query or fragment is required')
35
+ self.path = path
36
+
37
+ def start(
38
+ self,
39
+ inspector: 'Inspector',
40
+ ) -> None:
41
+ pass
42
+
43
+ def begin(
44
+ self,
45
+ task: str,
46
+ ) -> object:
47
+ return None
48
+
49
+ def end(
50
+ self,
51
+ task: str,
52
+ context: object,
53
+ success: Optional[bool],
54
+ ) -> None:
55
+ pass
56
+
57
+ def handle(
58
+ self,
59
+ inspector: 'Inspector',
60
+ environ: dict,
61
+ ) -> Response:
62
+ return self(inspector)
63
+
64
+ @abstractmethod
65
+ def __call__(
66
+ self,
67
+ inspector: 'Inspector',
68
+ ) -> Response:
69
+ raise NotImplementedError