iris-pex-embedded-python 3.4.0b2__py3-none-any.whl → 3.4.0b4__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/_common.py CHANGED
@@ -17,7 +17,19 @@ class _Common(metaclass=abc.ABCMeta):
17
17
  INFO_URL: ClassVar[str]
18
18
  ICON_URL: ClassVar[str]
19
19
  iris_handle: Any = None
20
- log_to_console: bool = False
20
+ _log_to_console: bool = False
21
+
22
+ @property
23
+ def log_to_console(self) -> bool:
24
+ return self._log_to_console
25
+
26
+ @log_to_console.setter
27
+ def log_to_console(self, value: bool) -> None:
28
+ self._log_to_console = value
29
+ self.logger = LogManager.get_logger(self.__class__.__name__,value)
30
+
31
+ def __init__(self):
32
+ self.logger = LogManager.get_logger(self.__class__.__name__)
21
33
 
22
34
  # Lifecycle methods
23
35
  def on_init(self) -> None:
@@ -172,7 +184,7 @@ class _Common(metaclass=abc.ABCMeta):
172
184
  except:
173
185
  pass
174
186
  return ret
175
-
187
+
176
188
  # Logging methods
177
189
  def _log(self) -> Tuple[str, Optional[str]]:
178
190
  """Get class and method name for logging.
@@ -189,15 +201,27 @@ class _Common(metaclass=abc.ABCMeta):
189
201
  pass
190
202
  return current_class, current_method
191
203
 
192
- @property
193
- def logger(self) -> logging.Logger:
194
- """Get a logger instance for this component.
204
+ def _logging(self, message: str, level: int, to_console: Optional[bool] = None) -> None:
205
+ """Write log entry.
195
206
 
196
- Returns:
197
- Logger configured for IRIS integration
207
+ Args:
208
+ message: Message to log
209
+ level: Log level
210
+ to_console: If True, log to console instead of IRIS
198
211
  """
199
- class_name, method_name = self._log()
200
- return LogManager.get_logger(class_name, method_name, self.log_to_console)
212
+ current_class, current_method = self._log()
213
+ if to_console is None:
214
+ to_console = self.log_to_console
215
+ if level == logging.DEBUG:
216
+ self.logger.debug(message, extra={'to_console': to_console, 'class_name': current_class, 'method_name': current_method})
217
+ elif level == logging.INFO:
218
+ self.logger.info(message, extra={'to_console': to_console, 'class_name': current_class, 'method_name': current_method})
219
+ elif level == logging.CRITICAL:
220
+ self.logger.critical(message, extra={'to_console': to_console, 'class_name': current_class, 'method_name': current_method})
221
+ elif level == logging.WARNING:
222
+ self.logger.warning(message, extra={'to_console': to_console, 'class_name': current_class, 'method_name': current_method})
223
+ elif level == logging.ERROR:
224
+ self.logger.error(message, extra={'to_console': to_console, 'class_name': current_class, 'method_name': current_method})
201
225
 
202
226
  def trace(self, message: str, to_console: Optional[bool] = None) -> None:
203
227
  """Write trace log entry.
@@ -206,8 +230,7 @@ class _Common(metaclass=abc.ABCMeta):
206
230
  message: Message to log
207
231
  to_console: If True, log to console instead of IRIS
208
232
  """
209
- self.logger.debug(message, extra={'to_console': to_console})
210
-
233
+ self._logging(message, logging.DEBUG, to_console)
211
234
 
212
235
  def log_info(self, message: str, to_console: Optional[bool] = None) -> None:
213
236
  """Write info log entry.
@@ -216,7 +239,7 @@ class _Common(metaclass=abc.ABCMeta):
216
239
  message: Message to log
217
240
  to_console: If True, log to console instead of IRIS
218
241
  """
219
- self.logger.info(message, extra={'to_console': to_console})
242
+ self._logging(message, logging.INFO, to_console)
220
243
 
221
244
  def log_alert(self, message: str, to_console: Optional[bool] = None) -> None:
222
245
  """Write alert log entry.
@@ -225,7 +248,7 @@ class _Common(metaclass=abc.ABCMeta):
225
248
  message: Message to log
226
249
  to_console: If True, log to console instead of IRIS
227
250
  """
228
- self.logger.critical(message, extra={'to_console': to_console})
251
+ self._logging(message, logging.CRITICAL, to_console)
229
252
 
230
253
  def log_warning(self, message: str, to_console: Optional[bool] = None) -> None:
231
254
  """Write warning log entry.
@@ -234,7 +257,7 @@ class _Common(metaclass=abc.ABCMeta):
234
257
  message: Message to log
235
258
  to_console: If True, log to console instead of IRIS
236
259
  """
237
- self.logger.warning(message, extra={'to_console': to_console})
260
+ self._logging(message, logging.WARNING, to_console)
238
261
 
239
262
  def log_error(self, message: str, to_console: Optional[bool] = None) -> None:
240
263
  """Write error log entry.
@@ -243,7 +266,7 @@ class _Common(metaclass=abc.ABCMeta):
243
266
  message: Message to log
244
267
  to_console: If True, log to console instead of IRIS
245
268
  """
246
- self.logger.error(message, extra={'to_console': to_console})
269
+ self._logging(message, logging.ERROR, to_console)
247
270
 
248
271
  def log_assert(self, message: str) -> None:
249
272
  """Write a log entry of type "assert". Log entries can be viewed in the management portal.
iop/_dispatch.py CHANGED
@@ -1,39 +1,9 @@
1
- import codecs
2
- import importlib
3
1
  from inspect import signature
4
- import json
5
- import pickle
6
- from typing import Any, Dict, List, Type
2
+ from typing import Any
7
3
 
8
- import iris
9
- from dacite import Config, from_dict
10
- from pydantic import BaseModel
11
-
12
- from iop._utils import _Utils
13
- from iop._serialization import IrisJSONEncoder, IrisJSONDecoder
4
+ from iop._serialization import serialize_message, serialize_pickle_message, deserialize_message, deserialize_pickle_message
14
5
  from iop._message_validator import is_message_instance, is_pickle_message_instance, is_iris_object_instance
15
6
 
16
- def serialize_pickle_message(message: Any) -> iris.cls:
17
- """Converts a python dataclass message into an iris iop.message.
18
-
19
- Args:
20
- message: The message to serialize, an instance of a class that is a subclass of Message.
21
-
22
- Returns:
23
- The message in json format.
24
- """
25
- pickle_string = codecs.encode(pickle.dumps(message), "base64").decode()
26
- module = message.__class__.__module__
27
- classname = message.__class__.__name__
28
-
29
- msg = iris.cls('IOP.PickleMessage')._New()
30
- msg.classname = module + "." + classname
31
-
32
- stream = _Utils.string_to_stream(pickle_string)
33
- msg.jstr = stream
34
-
35
- return msg
36
-
37
7
  def dispatch_serializer(message: Any) -> Any:
38
8
  """Serializes the message based on its type.
39
9
 
@@ -59,42 +29,6 @@ def dispatch_serializer(message: Any) -> Any:
59
29
 
60
30
  raise TypeError("The message must be an instance of a class that is a subclass of Message or IRISObject %Persistent class.")
61
31
 
62
- def serialize_message(message: Any) -> iris.cls:
63
- """Converts a python dataclass message into an iris iop.message.
64
-
65
- Args:
66
- message: The message to serialize, an instance of a class that is a subclass of Message.
67
-
68
- Returns:
69
- The message in json format.
70
- """
71
- json_string = json.dumps(message, cls=IrisJSONEncoder, ensure_ascii=False)
72
- module = message.__class__.__module__
73
- classname = message.__class__.__name__
74
-
75
- msg = iris.cls('IOP.Message')._New()
76
- msg.classname = module + "." + classname
77
-
78
- if hasattr(msg, 'buffer') and len(json_string) > msg.buffer:
79
- msg.json = _Utils.string_to_stream(json_string, msg.buffer)
80
- else:
81
- msg.json = json_string
82
-
83
- return msg
84
-
85
- def deserialize_pickle_message(serial: iris.cls) -> Any:
86
- """Converts an iris iop.message into a python dataclass message.
87
-
88
- Args:
89
- serial: The serialized message
90
-
91
- Returns:
92
- The deserialized message
93
- """
94
- string = _Utils.stream_to_string(serial.jstr)
95
- msg = pickle.loads(codecs.decode(string.encode(), "base64"))
96
- return msg
97
-
98
32
  def dispatch_deserializer(serial: Any) -> Any:
99
33
  """Deserializes the message based on its type.
100
34
 
@@ -125,62 +59,6 @@ def dispatch_deserializer(serial: Any) -> Any:
125
59
  else:
126
60
  return serial
127
61
 
128
- def deserialize_message(serial: iris.cls) -> Any:
129
- """Converts an iris iop.message into a python dataclass message.
130
-
131
- Args:
132
- serial: The serialized message
133
-
134
- Returns:
135
- The deserialized message
136
- """
137
- if (serial.classname is None):
138
- raise ValueError("JSON message malformed, must include classname")
139
- classname = serial.classname
140
-
141
- j = classname.rindex(".")
142
- if (j <= 0):
143
- raise ValueError("Classname must include a module: " + classname)
144
- try:
145
- module = importlib.import_module(classname[:j])
146
- msg = getattr(module, classname[j+1:])
147
- except Exception:
148
- raise ImportError("Class not found: " + classname)
149
-
150
- string = ""
151
- if (serial.type == 'Stream'):
152
- string = _Utils.stream_to_string(serial.json)
153
- else:
154
- string = serial.json
155
-
156
- jdict = json.loads(string, cls=IrisJSONDecoder)
157
- return dataclass_from_dict(msg, jdict)
158
-
159
- def dataclass_from_dict(klass: Type, dikt: Dict) -> Any:
160
- """Converts a dictionary to a dataclass instance.
161
-
162
- Args:
163
- klass: The dataclass to convert to
164
- dikt: The dictionary to convert to a dataclass
165
-
166
- Returns:
167
- A dataclass object with the fields of the dataclass and the fields of the dictionary.
168
- """
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
183
-
184
62
  def dispach_message(host, request: Any) -> Any:
185
63
  """Dispatches the message to the appropriate method.
186
64
 
iop/_log_manager.py CHANGED
@@ -1,3 +1,4 @@
1
+ import traceback
1
2
  import iris
2
3
  import logging
3
4
  from typing import Optional, Tuple
@@ -6,7 +7,7 @@ class LogManager:
6
7
  """Manages logging integration between Python's logging module and IRIS."""
7
8
 
8
9
  @staticmethod
9
- def get_logger(class_name: str, method_name: Optional[str] = None, to_console: bool = False) -> logging.Logger:
10
+ def get_logger(class_name: str, to_console: bool = False) -> logging.Logger:
10
11
  """Get a logger instance configured for IRIS integration.
11
12
 
12
13
  Args:
@@ -17,11 +18,11 @@ class LogManager:
17
18
  Returns:
18
19
  Logger instance configured for IRIS integration
19
20
  """
20
- logger = logging.getLogger(f"{class_name}.{method_name}" if method_name else class_name)
21
+ logger = logging.Logger(f"{class_name}")
21
22
 
22
23
  # Only add handler if none exists
23
24
  if not logger.handlers:
24
- handler = IRISLogHandler(class_name, method_name, to_console)
25
+ handler = IRISLogHandler(to_console=to_console)
25
26
  formatter = logging.Formatter('%(message)s')
26
27
  handler.setFormatter(formatter)
27
28
  logger.addHandler(handler)
@@ -33,17 +34,9 @@ class LogManager:
33
34
  class IRISLogHandler(logging.Handler):
34
35
  """Custom logging handler that routes Python logs to IRIS logging system."""
35
36
 
36
- def __init__(self, class_name: str, method_name: Optional[str] = None, to_console: bool = False):
37
- """Initialize the handler with context information.
38
-
39
- Args:
40
- class_name: Name of the class logging the message
41
- method_name: Optional name of the method logging the message
42
- console: If True, log to the console instead of IRIS
43
- """
37
+ def __init__(self, to_console: bool = False):
38
+ """Initialize the IRIS logging handler."""
44
39
  super().__init__()
45
- self.class_name = class_name
46
- self.method_name = method_name
47
40
  self.to_console = to_console
48
41
 
49
42
  # Map Python logging levels to IRIS logging methods
@@ -80,10 +73,11 @@ class IRISLogHandler(logging.Handler):
80
73
  Args:
81
74
  record: The logging record to emit
82
75
  """
83
-
84
- log_func = self.level_map.get(record.levelno, iris.cls("Ens.Util.Log").LogInfo)
76
+ class_name = record.class_name if hasattr(record, "class_name") else record.name
77
+ method_name = record.method_name if hasattr(record, "method_name") else record.funcName
85
78
  if self.to_console or (hasattr(record, "to_console") and record.to_console):
86
79
  iris.cls("%SYS.System").WriteToConsoleLog(self.format(record),
87
- 0,self.level_map_console.get(record.levelno, 0),record.name)
80
+ 0,self.level_map_console.get(record.levelno, 0),class_name+"."+method_name)
88
81
  else:
89
- log_func(self.class_name, self.method_name, self.format(record))
82
+ log_func = self.level_map.get(record.levelno, iris.cls("Ens.Util.Log").LogInfo)
83
+ log_func(class_name, method_name, self.format(record))
iop/_serialization.py CHANGED
@@ -7,9 +7,7 @@ import importlib
7
7
  import json
8
8
  import pickle
9
9
  import uuid
10
- from abc import ABC, abstractmethod
11
- from dataclasses import is_dataclass
12
- from typing import Any, Dict, Type, Optional
10
+ from typing import Any, Dict, Type
13
11
 
14
12
  from dacite import Config, from_dict
15
13
  import iris
iop/_utils.py CHANGED
@@ -7,6 +7,7 @@ import xmltodict
7
7
  import pkg_resources
8
8
  import importlib
9
9
  import json
10
+ from iop._message import _Message, _PydanticMessage
10
11
  from dc_schema import get_schema
11
12
 
12
13
  class _Utils():
@@ -42,7 +43,12 @@ class _Utils():
42
43
 
43
44
  :param cls: The class to register
44
45
  """
45
- schema = get_schema(cls)
46
+ if issubclass(cls,_PydanticMessage):
47
+ schema = cls.model_json_schema()
48
+ elif issubclass(cls,_Message):
49
+ schema = get_schema(cls)
50
+ else:
51
+ raise ValueError("The class must be a subclass of _Message or _PydanticMessage")
46
52
  schema_name = cls.__module__ + '.' + cls.__name__
47
53
  schema_str = json.dumps(schema)
48
54
  categories = schema_name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: iris_pex_embedded_python
3
- Version: 3.4.0b2
3
+ Version: 3.4.0b4
4
4
  Summary: Iris Interoperability based on Embedded Python
5
5
  Author-email: grongier <guillaume.rongier@intersystems.com>
6
6
  License: MIT License
@@ -98,19 +98,19 @@ iop/_business_operation.py,sha256=ml4BIn1BfrGx8AUGISFR71DZIUCP8vZ2yn9SQjaSzTM,30
98
98
  iop/_business_process.py,sha256=hj6nDIP5Mz5UYbm0vDjvs9lPSEYVQxGJl6tQRcDGTBk,8548
99
99
  iop/_business_service.py,sha256=lPTp3_tcLTOWvHlE_YwrcImLGf1PJBUgIOrV-8ctFLw,3851
100
100
  iop/_cli.py,sha256=IwvVxglSTVkCDXwANLMqnd8mfxGtWB6GjBSdEy8EMm0,7551
101
- iop/_common.py,sha256=E_Mn2t--klAtT4p1MzW1KtcKcLrB1g4Flq5H4JlV8Vs,11619
101
+ iop/_common.py,sha256=QT05YtQBzzJOZdrX62j8qJxlmClkzTnl2FisJ12dgU0,12905
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=q9oCE4b5FazW1t2oczvBGQtKzip_-yykY9WvXUp1urE,6775
104
+ iop/_dispatch.py,sha256=I3TAhvTuk8j4VcROI9vAitJ0a7Nk1BYAWKRrLeNsjr0,3203
105
105
  iop/_inbound_adapter.py,sha256=PS5ToqhrYcXq9ZdLbCBqAfVp8kCeRACm_KF66pwBO9U,1652
106
- iop/_log_manager.py,sha256=PZnGWsi-zvWo-bumQO5BK-8kHG2XW-WnZ6ShL7QeZ4c,3499
106
+ iop/_log_manager.py,sha256=f9T8yhcVJlCVNY7E_tb2e65QB_rJWYNF6J586OV2ukA,3240
107
107
  iop/_message.py,sha256=pJQOjRIdw4wSDoJamvItGODMe-UjDU71XihgWdtCAqc,1120
108
108
  iop/_message_validator.py,sha256=K6FxLe72gBHQXZTLVrFw87rABGM0F6CTaNtZ2MqJoss,1408
109
109
  iop/_outbound_adapter.py,sha256=YTAhLrRf9chEAd53mV6KKbpaHOKNOKJHoGgj5wakRR0,726
110
110
  iop/_private_session_duplex.py,sha256=mzlFABh-ly51X1uSWw9YwQbktfMvuNdp2ALlRvlDow4,5152
111
111
  iop/_private_session_process.py,sha256=todprfYFSDr-h-BMvWL_IGC6wbQqkMy3mPHWEWCUSE0,1686
112
- iop/_serialization.py,sha256=hGpFYHWjYRcDuQv4Ml9N16onW8vmHGhDwA3bv_NwFnM,8923
113
- iop/_utils.py,sha256=Aqtp9Jx3ghzkNs4f2cOZXYwv8cGsjmdBocnkP64fa3M,19574
112
+ iop/_serialization.py,sha256=RIBHjhrkAyfJJC5OXIlrwHcuXvPiDM63PtkVDyVKp1E,8840
113
+ iop/_utils.py,sha256=eNVxKGVQbYMoU43sFPkOjZIilN4OqRzycHV9l6rLDcU,19866
114
114
  iop/cls/IOP/BusinessOperation.cls,sha256=lrymqZ8wHl5kJjXwdjbQVs5sScV__yIWGh-oGbiB_X0,914
115
115
  iop/cls/IOP/BusinessProcess.cls,sha256=s3t38w1ykHqM26ETcbCYLt0ocjZyVVahm-_USZkuJ1E,2855
116
116
  iop/cls/IOP/BusinessService.cls,sha256=7ebn32J9PiZXUgXuh5Xxm_7X6zHBiqkJr9c_dWxbPO8,1021
@@ -135,9 +135,9 @@ iop/cls/IOP/Service/WSGI.cls,sha256=VLNCXEwmHW9dBnE51uGE1nvGX6T4HjhqePT3LVhsjAE,
135
135
  iop/wsgi/handlers.py,sha256=NrFLo_YbAh-x_PlWhAiWkQnUUN2Ss9HoEm63dDWCBpQ,2947
136
136
  irisnative/_IRISNative.py,sha256=HQ4nBhc8t8_5OtxdMG-kx1aa-T1znf2I8obZOPLOPzg,665
137
137
  irisnative/__init__.py,sha256=6YmvBLQSURsCPKaNg7LK-xpo4ipDjrlhKuwdfdNb3Kg,341
138
- iris_pex_embedded_python-3.4.0b2.dist-info/LICENSE,sha256=rZSiBFId_sfbJ6RL0GjjPX-InNLkNS9ou7eQsikciI8,1089
139
- iris_pex_embedded_python-3.4.0b2.dist-info/METADATA,sha256=wSmLx_zkXK9oTutFdot5ManhtmjC7_-eYrZLeCC4w_Q,4458
140
- iris_pex_embedded_python-3.4.0b2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
141
- iris_pex_embedded_python-3.4.0b2.dist-info/entry_points.txt,sha256=pj-i4LSDyiSP6xpHlVjMCbg1Pik7dC3_sdGY3Yp9Vhk,38
142
- iris_pex_embedded_python-3.4.0b2.dist-info/top_level.txt,sha256=VWDlX4YF4qFVRGrG3-Gs0kgREol02i8gIpsHNbhfFPw,42
143
- iris_pex_embedded_python-3.4.0b2.dist-info/RECORD,,
138
+ iris_pex_embedded_python-3.4.0b4.dist-info/LICENSE,sha256=rZSiBFId_sfbJ6RL0GjjPX-InNLkNS9ou7eQsikciI8,1089
139
+ iris_pex_embedded_python-3.4.0b4.dist-info/METADATA,sha256=SFK1Eke3STnTMMddK-npyOBkuEnajg-TJ0zY6McqHSA,4458
140
+ iris_pex_embedded_python-3.4.0b4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
141
+ iris_pex_embedded_python-3.4.0b4.dist-info/entry_points.txt,sha256=pj-i4LSDyiSP6xpHlVjMCbg1Pik7dC3_sdGY3Yp9Vhk,38
142
+ iris_pex_embedded_python-3.4.0b4.dist-info/top_level.txt,sha256=VWDlX4YF4qFVRGrG3-Gs0kgREol02i8gIpsHNbhfFPw,42
143
+ iris_pex_embedded_python-3.4.0b4.dist-info/RECORD,,