iris-pex-embedded-python 3.3.1__py3-none-any.whl → 3.4.0b1__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.

Potentially problematic release.


This version of iris-pex-embedded-python might be problematic. Click here for more details.

iop/__init__.py CHANGED
@@ -4,6 +4,7 @@ from iop._business_service import _BusinessService
4
4
  from iop._director import _Director
5
5
  from iop._inbound_adapter import _InboundAdapter
6
6
  from iop._message import _Message
7
+ from iop._pydantic_message import _PydanticMessage
7
8
  from iop._outbound_adapter import _OutboundAdapter
8
9
  from iop._pickle_message import _PickleMessage
9
10
  from iop._private_session_duplex import _PrivateSessionDuplex
@@ -21,4 +22,5 @@ class DuplexOperation(_PrivateSessionDuplex): pass
21
22
  class DuplexProcess(_PrivateSessionProcess): pass
22
23
  class Message(_Message): pass
23
24
  class PickleMessage(_PickleMessage): pass
25
+ class PydanticMessage(_PydanticMessage): pass
24
26
  class Director(_Director): pass
iop/_dispatch.py CHANGED
@@ -7,6 +7,7 @@ from typing import Any, Dict, List, Type
7
7
 
8
8
  import iris
9
9
  from dacite import Config, from_dict
10
+ from pydantic import BaseModel
10
11
 
11
12
  from iop._utils import _Utils
12
13
  from iop._serialization import IrisJSONEncoder, IrisJSONDecoder
@@ -165,17 +166,20 @@ def dataclass_from_dict(klass: Type, dikt: Dict) -> Any:
165
166
  Returns:
166
167
  A dataclass object with the fields of the dataclass and the fields of the dictionary.
167
168
  """
168
- ret = from_dict(klass, dikt, Config(check_types=False))
169
-
170
- try:
171
- fieldtypes = klass.__annotations__
172
- except Exception as e:
173
- fieldtypes = []
174
-
175
- for key, val in dikt.items():
176
- if key not in fieldtypes:
177
- setattr(ret, key, val)
178
- return ret
169
+ if issubclass(klass, BaseModel):
170
+ return klass.model_validate(dikt)
171
+ else:
172
+ ret = from_dict(klass, dikt, Config(check_types=False))
173
+
174
+ try:
175
+ fieldtypes = klass.__annotations__
176
+ except Exception as e:
177
+ fieldtypes = []
178
+
179
+ for key, val in dikt.items():
180
+ if key not in fieldtypes:
181
+ setattr(ret, key, val)
182
+ return ret
179
183
 
180
184
  def dispach_message(host, request: Any) -> Any:
181
185
  """Dispatches the message to the appropriate method.
iop/_message_validator.py CHANGED
@@ -1,9 +1,13 @@
1
1
  import dataclasses
2
2
  from typing import Any, Type
3
+ from pydantic import BaseModel
4
+ from iop._message import _Message
3
5
 
4
6
 
5
7
  def is_message_instance(obj: Any) -> bool:
6
8
  """Check if object is a valid Message instance."""
9
+ if isinstance(obj, BaseModel):
10
+ return True
7
11
  if is_message_class(type(obj)):
8
12
  if not dataclasses.is_dataclass(obj):
9
13
  raise TypeError(f"{type(obj).__module__}.{type(obj).__qualname__} must be a dataclass")
@@ -27,10 +31,12 @@ def is_iris_object_instance(obj: Any) -> bool:
27
31
 
28
32
  def is_message_class(klass: Type) -> bool:
29
33
  """Check if class is a Message type."""
30
- name = f"{klass.__module__}.{klass.__qualname__}"
31
- if name in ("iop.Message", "grongier.pex.Message"):
34
+ if issubclass(klass, BaseModel):
35
+ return True
36
+ if issubclass(klass, _Message):
32
37
  return True
33
- return any(is_message_class(c) for c in klass.__bases__)
38
+ return False
39
+
34
40
 
35
41
 
36
42
  def is_pickle_message_class(klass: Type) -> bool:
@@ -0,0 +1,9 @@
1
+
2
+ from typing import Any
3
+ from pydantic import BaseModel
4
+
5
+ class _PydanticMessage(BaseModel):
6
+ """Base class for Pydantic-based messages that can be serialized to IRIS."""
7
+
8
+ def __init__(self, **data: Any):
9
+ super().__init__(**data)
iop/_serialization.py CHANGED
@@ -15,6 +15,7 @@ from dacite import Config, from_dict
15
15
  import iris
16
16
 
17
17
  from iop._utils import _Utils
18
+ from pydantic import BaseModel
18
19
 
19
20
  # Constants
20
21
  DATETIME_FORMAT_LENGTH = 23
@@ -91,6 +92,8 @@ class IrisJSONEncoder(json.JSONEncoder):
91
92
  """JSONEncoder that handles dates, decimals, UUIDs, etc."""
92
93
 
93
94
  def default(self, obj: Any) -> Any:
95
+ if isinstance(obj, BaseModel):
96
+ return obj.model_dump()
94
97
  if obj.__class__.__name__ == 'DataFrame':
95
98
  return f'dataframe:{TypeConverter.convert_to_string("dataframe", obj)}'
96
99
  elif isinstance(obj, datetime.datetime):
@@ -134,6 +137,9 @@ class MessageSerializer:
134
137
  @staticmethod
135
138
  def serialize(message: Any, use_pickle: bool = False) -> iris.cls:
136
139
  """Serializes a message to IRIS format."""
140
+ if isinstance(message, BaseModel):
141
+ return (MessageSerializer._serialize_pickle(message)
142
+ if use_pickle else MessageSerializer._serialize_json(message))
137
143
  if use_pickle:
138
144
  return MessageSerializer._serialize_pickle(message)
139
145
  return MessageSerializer._serialize_json(message)
@@ -155,7 +161,11 @@ class MessageSerializer:
155
161
 
156
162
  @staticmethod
157
163
  def _serialize_json(message: Any) -> iris.cls:
158
- json_string = json.dumps(message, cls=IrisJSONEncoder, ensure_ascii=False)
164
+ if isinstance(message, BaseModel):
165
+ json_string = json.dumps(message.model_dump(), cls=IrisJSONEncoder, ensure_ascii=False)
166
+ else:
167
+ json_string = json.dumps(message, cls=IrisJSONEncoder, ensure_ascii=False)
168
+
159
169
  msg = iris.cls('IOP.Message')._New()
160
170
  msg.classname = f"{message.__class__.__module__}.{message.__class__.__name__}"
161
171
 
@@ -187,7 +197,10 @@ class MessageSerializer:
187
197
 
188
198
  try:
189
199
  json_dict = json.loads(json_string, cls=IrisJSONDecoder)
190
- return dataclass_from_dict(msg_class, json_dict)
200
+ if issubclass(msg_class, BaseModel):
201
+ return msg_class.model_validate(json_dict)
202
+ else:
203
+ return dataclass_from_dict(msg_class, json_dict)
191
204
  except Exception as e:
192
205
  raise SerializationError(f"Failed to deserialize JSON: {str(e)}")
193
206
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: iris_pex_embedded_python
3
- Version: 3.3.1
3
+ Version: 3.4.0b1
4
4
  Summary: Iris Interoperability based on Embedded Python
5
5
  Author-email: grongier <guillaume.rongier@intersystems.com>
6
6
  License: MIT License
@@ -45,6 +45,7 @@ Classifier: Topic :: Utilities
45
45
  Description-Content-Type: text/markdown
46
46
  License-File: LICENSE
47
47
  Requires-Dist: dacite>=1.6.0
48
+ Requires-Dist: pydantic>=2.0.0
48
49
  Requires-Dist: xmltodict>=0.12.0
49
50
  Requires-Dist: iris-embedded-python-wrapper>=0.0.6
50
51
  Requires-Dist: setuptools>=40.8.0
@@ -90,7 +90,7 @@ intersystems_iris/pex/_InboundAdapter.py,sha256=gZlWl7afumamkj8pNbpLyKFSzhaTAiAX
90
90
  intersystems_iris/pex/_Message.py,sha256=Ugaa_lsEYke__pI5kdC7phAuyPQ7rxXUcROJL4cUxVQ,320
91
91
  intersystems_iris/pex/_OutboundAdapter.py,sha256=ao2Ubbta2DcrQGdzDUD_j1Zsk8bvUfcZNKTZkzPTNBU,1628
92
92
  intersystems_iris/pex/__init__.py,sha256=l_I1dpnluWawbFrGMDC0GLHpuHwjbpd-nho8otFX6TE,1379
93
- iop/__init__.py,sha256=fX1Osx2Dmcuv8C5hmvoG4fPDIbk0qksJcIgpQibJ_p4,1067
93
+ iop/__init__.py,sha256=-7_A7epvomoAFBIevir_8f82mEQ6pzIhhKVgP2KFMoU,1166
94
94
  iop/__main__.py,sha256=pQzVtkDhAeI6dpNRC632dVk2SGZZIEDwDufdgZe8VWs,98
95
95
  iop/_async_request.py,sha256=btDFNFaO-Yvl6wvgXrCYNWoQb2RtbzEvTJsk7j03b30,2170
96
96
  iop/_business_host.py,sha256=wI2LlVTVjEqE8GWE9nSz1WHvqTduAuJQTk7Ky7qkz4U,9658
@@ -101,16 +101,17 @@ iop/_cli.py,sha256=IwvVxglSTVkCDXwANLMqnd8mfxGtWB6GjBSdEy8EMm0,7551
101
101
  iop/_common.py,sha256=E_Mn2t--klAtT4p1MzW1KtcKcLrB1g4Flq5H4JlV8Vs,11619
102
102
  iop/_decorators.py,sha256=ZpgEETLdKWv58AoSMfXnm3_mA-6qPphIegjG-npDgwg,2324
103
103
  iop/_director.py,sha256=DrswFoqJ6IG62hkW-0ZffTtZdxw6KNozlZSIq3O6d-o,11629
104
- iop/_dispatch.py,sha256=4317Z0ujXxDGUQaL7WX6zfGzBPOdw70MWiqmLUKxhik,6611
104
+ iop/_dispatch.py,sha256=q9oCE4b5FazW1t2oczvBGQtKzip_-yykY9WvXUp1urE,6775
105
105
  iop/_inbound_adapter.py,sha256=PS5ToqhrYcXq9ZdLbCBqAfVp8kCeRACm_KF66pwBO9U,1652
106
106
  iop/_log_manager.py,sha256=PZnGWsi-zvWo-bumQO5BK-8kHG2XW-WnZ6ShL7QeZ4c,3499
107
107
  iop/_message.py,sha256=LSkfZcmEu1aj2hdSg3sUHSWNc8tWWZR8Q2_h9_axVrs,325
108
- iop/_message_validator.py,sha256=xMMPOZOop3Nv12E3_QPI5caTgYgAzoKlRxcMmUkrj2c,1379
108
+ iop/_message_validator.py,sha256=LAHrgXEA6WfWjrVcBA6Hc9RwjPK0PRItq-0nzXAayUo,1438
109
109
  iop/_outbound_adapter.py,sha256=YTAhLrRf9chEAd53mV6KKbpaHOKNOKJHoGgj5wakRR0,726
110
110
  iop/_pickle_message.py,sha256=noKfc2VkXufV3fqjKvNHN_oANQ1YN9ffCaSV0XSTAIE,331
111
111
  iop/_private_session_duplex.py,sha256=mzlFABh-ly51X1uSWw9YwQbktfMvuNdp2ALlRvlDow4,5152
112
112
  iop/_private_session_process.py,sha256=todprfYFSDr-h-BMvWL_IGC6wbQqkMy3mPHWEWCUSE0,1686
113
- iop/_serialization.py,sha256=jHJGTMpKI2QDcF_m7R0WyH_J-vjQyYpNpD0ktn9Rqo4,8106
113
+ iop/_pydantic_message.py,sha256=KGpHWI-o8ZW7ZgiyLf-FoN5_k5uxhZv_3odrg7x22XU,246
114
+ iop/_serialization.py,sha256=UVc1sV-oAwWSmVJw3GWe1aYERKocMv2gpXhHgARRlxI,8707
114
115
  iop/_utils.py,sha256=Aqtp9Jx3ghzkNs4f2cOZXYwv8cGsjmdBocnkP64fa3M,19574
115
116
  iop/cls/IOP/BusinessOperation.cls,sha256=lrymqZ8wHl5kJjXwdjbQVs5sScV__yIWGh-oGbiB_X0,914
116
117
  iop/cls/IOP/BusinessProcess.cls,sha256=s3t38w1ykHqM26ETcbCYLt0ocjZyVVahm-_USZkuJ1E,2855
@@ -136,9 +137,9 @@ iop/cls/IOP/Service/WSGI.cls,sha256=VLNCXEwmHW9dBnE51uGE1nvGX6T4HjhqePT3LVhsjAE,
136
137
  iop/wsgi/handlers.py,sha256=NrFLo_YbAh-x_PlWhAiWkQnUUN2Ss9HoEm63dDWCBpQ,2947
137
138
  irisnative/_IRISNative.py,sha256=HQ4nBhc8t8_5OtxdMG-kx1aa-T1znf2I8obZOPLOPzg,665
138
139
  irisnative/__init__.py,sha256=6YmvBLQSURsCPKaNg7LK-xpo4ipDjrlhKuwdfdNb3Kg,341
139
- iris_pex_embedded_python-3.3.1.dist-info/LICENSE,sha256=rZSiBFId_sfbJ6RL0GjjPX-InNLkNS9ou7eQsikciI8,1089
140
- iris_pex_embedded_python-3.3.1.dist-info/METADATA,sha256=dsJ4pvP-mBaxashySn6A9FgZ6pKVLjidQBu_dRC_fZY,4425
141
- iris_pex_embedded_python-3.3.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
142
- iris_pex_embedded_python-3.3.1.dist-info/entry_points.txt,sha256=pj-i4LSDyiSP6xpHlVjMCbg1Pik7dC3_sdGY3Yp9Vhk,38
143
- iris_pex_embedded_python-3.3.1.dist-info/top_level.txt,sha256=VWDlX4YF4qFVRGrG3-Gs0kgREol02i8gIpsHNbhfFPw,42
144
- iris_pex_embedded_python-3.3.1.dist-info/RECORD,,
140
+ iris_pex_embedded_python-3.4.0b1.dist-info/LICENSE,sha256=rZSiBFId_sfbJ6RL0GjjPX-InNLkNS9ou7eQsikciI8,1089
141
+ iris_pex_embedded_python-3.4.0b1.dist-info/METADATA,sha256=Llw7FI-38MNAaB9Ri1AxjYSEsI22-qmaT1D3z1T7xzo,4458
142
+ iris_pex_embedded_python-3.4.0b1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
143
+ iris_pex_embedded_python-3.4.0b1.dist-info/entry_points.txt,sha256=pj-i4LSDyiSP6xpHlVjMCbg1Pik7dC3_sdGY3Yp9Vhk,38
144
+ iris_pex_embedded_python-3.4.0b1.dist-info/top_level.txt,sha256=VWDlX4YF4qFVRGrG3-Gs0kgREol02i8gIpsHNbhfFPw,42
145
+ iris_pex_embedded_python-3.4.0b1.dist-info/RECORD,,