mirth-client 4.2.0__tar.gz → 5.0.0__tar.gz

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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mirth-client
3
- Version: 4.2.0
3
+ Version: 5.0.0
4
4
  Summary: Basic Python interface for Mirth Connect
5
5
  License-File: LICENSE
6
6
  Author: Joel Collins
@@ -16,9 +16,9 @@ Classifier: Programming Language :: Python :: 3.14
16
16
  Provides-Extra: docs
17
17
  Requires-Dist: Sphinx (>=3.5.3,<8.0.0) ; extra == "docs"
18
18
  Requires-Dist: httpx (>=0.23,<0.28.2)
19
- Requires-Dist: pydantic (>=1.8.2,<3.0.0)
19
+ Requires-Dist: pydantic (>=2.0.0,<3.0.0)
20
20
  Requires-Dist: semver (>=2.13,<4.0)
21
- Requires-Dist: sphinx-rtd-theme (>=0.5.1,<2.1.0) ; extra == "docs"
21
+ Requires-Dist: sphinx-rtd-theme (>=0.5.1,<3.2.0) ; extra == "docs"
22
22
  Requires-Dist: typing-extensions (>=3.10,<5.0)
23
23
  Requires-Dist: xmltodict (>=0.12,<1.1)
24
24
  Description-Content-Type: text/markdown
@@ -20,32 +20,18 @@ from typing import (
20
20
  from uuid import UUID
21
21
 
22
22
  import xmltodict
23
- import typing
24
- import pydantic
25
- from packaging import version
26
23
  from xml.parsers.expat import ExpatError
27
24
 
28
- if typing.TYPE_CHECKING or version.parse(pydantic.__version__) >= version.parse("2.0"):
29
- from pydantic.v1 import (
30
- BaseModel,
31
- ValidationError,
32
- root_validator,
33
- validator,
34
- StrBytes,
35
- Protocol,
36
- )
37
- from pydantic.v1.error_wrappers import ErrorWrapper
38
- else:
39
- from pydantic import (
40
- BaseModel,
41
- Protocol,
42
- StrBytes,
43
- ValidationError,
44
- root_validator,
45
- validator,
46
- )
47
- from pydantic.error_wrappers import ErrorWrapper
48
-
25
+ from pydantic import (
26
+ BaseModel,
27
+ ConfigDict,
28
+ ValidationError,
29
+ field_validator,
30
+ model_validator,
31
+ )
32
+ from pydantic.deprecated.parse import Protocol as DeprecatedParseProtocol
33
+ from pydantic.main import IncEx
34
+ from pydantic_core import InitErrorDetails
49
35
 
50
36
  from typing_extensions import TypedDict
51
37
 
@@ -55,6 +41,9 @@ if TYPE_CHECKING:
55
41
  SetIntStr = Set[IntStr]
56
42
  DictIntStrAny = Dict[IntStr, Any]
57
43
 
44
+ # pydantic v1's `StrBytes` alias, kept for internal use
45
+ StrBytes = Union[str, bytes]
46
+
58
47
  _RawHashMapTypes = Union["OrderedDict[Any, Any]", List["OrderedDict[Any, Any]"]]
59
48
 
60
49
 
@@ -145,10 +134,7 @@ class MirthBaseModel(BaseModel):
145
134
  Base model which defaults to creating camelCase aliases for all fields
146
135
  """
147
136
 
148
- class Config:
149
- """Pydantic config class to set alias generator"""
150
-
151
- alias_generator = _to_camel
137
+ model_config = ConfigDict(alias_generator=_to_camel, populate_by_name=True)
152
138
 
153
139
 
154
140
  class XMLDict(OrderedDict):
@@ -169,7 +155,8 @@ class XMLBaseModel(MirthBaseModel):
169
155
  __root_element__: str = ""
170
156
  __force_list__: Union[Tuple, Tuple[str], bool] = tuple()
171
157
 
172
- @root_validator(pre=True)
158
+ @model_validator(mode="before")
159
+ @classmethod
173
160
  def strip_xml_root(cls, value):
174
161
  """Strips out the root key of a parsed XML message,
175
162
  if one is defined on the model.
@@ -187,7 +174,11 @@ class XMLBaseModel(MirthBaseModel):
187
174
  Returns:
188
175
  dict: Dictionary without root key
189
176
  """
190
- if cls.__root_element__ and cls.__root_element__ in value:
177
+ if (
178
+ cls.__root_element__
179
+ and isinstance(value, dict)
180
+ and cls.__root_element__ in value
181
+ ):
191
182
  return value[cls.__root_element__]
192
183
  return value
193
184
 
@@ -198,8 +189,8 @@ class XMLBaseModel(MirthBaseModel):
198
189
  *,
199
190
  content_type: Optional[str] = "xml",
200
191
  encoding: str = "utf8",
201
- proto: Optional[Protocol] = None,
202
- allow_pickle: bool = False,
192
+ proto: Optional["DeprecatedParseProtocol"] = None, # noqa: ARG003
193
+ allow_pickle: bool = False, # noqa: ARG003
203
194
  ) -> "Model":
204
195
  """Parse raw data into a Pydantic object.
205
196
 
@@ -207,6 +198,11 @@ class XMLBaseModel(MirthBaseModel):
207
198
  XML formatted input string, the XML is parsed to a dictionary object
208
199
  and send for validation by the Pydantic model.
209
200
 
201
+ Note:
202
+ `proto` and `allow_pickle` are accepted only to keep this
203
+ method's signature compatible with the deprecated
204
+ `BaseModel.parse_raw` it overrides; they are not used.
205
+
210
206
  Raises:
211
207
  ValidationError: Invalid XML or XML can not be validated against the model
212
208
 
@@ -221,40 +217,44 @@ class XMLBaseModel(MirthBaseModel):
221
217
  encoding="utf-8" if encoding == "utf8" else encoding,
222
218
  dict_constructor=XMLDict,
223
219
  )
224
- return cls.parse_obj(obj)
220
+ return cls.model_validate(obj)
225
221
  except (
226
222
  ValueError,
227
223
  TypeError,
228
224
  UnicodeDecodeError,
229
225
  ExpatError, # pylint: disable=no-member
230
226
  ) as e:
231
- raise ValidationError([ErrorWrapper(e, loc="__obj__")], cls) from e
232
- return super().parse_raw( # type: ignore
233
- b,
234
- content_type=content_type, # type: ignore
235
- encoding=encoding,
236
- proto=proto, # type: ignore
237
- allow_pickle=allow_pickle,
238
- )
227
+ raise ValidationError.from_exception_data(
228
+ cls.__name__,
229
+ [
230
+ InitErrorDetails(
231
+ type="value_error",
232
+ loc=("__obj__",),
233
+ input=b,
234
+ ctx={"error": e},
235
+ )
236
+ ],
237
+ ) from e
238
+ # Fall back to standard JSON parsing behaviour
239
+ return cls.model_validate_json(b)
239
240
 
240
241
  def xml(
241
242
  self,
242
243
  *,
243
- include: Union["SetIntStr", "DictIntStrAny", None] = None,
244
- exclude: Union["SetIntStr", "DictIntStrAny", None] = None,
244
+ include: "IncEx | None" = None,
245
+ exclude: "IncEx | None" = None,
245
246
  by_alias: bool = True,
246
247
  exclude_unset: bool = False,
247
248
  ) -> str:
248
249
  """Convert the Pydantic object into an XML string"""
250
+ root_key = self.__class__.__root_element__ or self.__class__.__name__
249
251
  xml_dict = {
250
- self.__class__.__root_element__
251
- or self.__class__.__name__: self.__config__.json_loads(
252
- self.json(
253
- include=include,
254
- exclude=exclude,
255
- by_alias=by_alias,
256
- exclude_unset=exclude_unset,
257
- )
252
+ root_key: self.model_dump(
253
+ mode="json",
254
+ include=include,
255
+ exclude=exclude,
256
+ by_alias=by_alias,
257
+ exclude_unset=exclude_unset,
258
258
  )
259
259
  }
260
260
  return xmltodict.unparse(xml_dict)
@@ -275,18 +275,29 @@ class MirthDatetime(datetime):
275
275
  """
276
276
 
277
277
  @classmethod
278
- def __get_validators__(cls):
279
- yield cls.validate
278
+ def __get_pydantic_core_schema__(cls, source_type, handler):
279
+ from pydantic_core import core_schema
280
+
281
+ return core_schema.json_or_python_schema(
282
+ json_schema=core_schema.str_schema(),
283
+ python_schema=core_schema.no_info_plain_validator_function(cls.validate),
284
+ serialization=core_schema.plain_serializer_function_ser_schema(
285
+ lambda v: v.isoformat(),
286
+ when_used="json",
287
+ ),
288
+ )
280
289
 
281
290
  @classmethod
282
- def validate(cls, value: _MirthDateTimeMap):
291
+ def validate(cls, value):
283
292
  """Extract timestamp and convert to a datetime"""
284
- if not isinstance(value, cls):
285
- timestamp = value.get("time")
286
- if not timestamp:
287
- raise ValueError("No `time` attribute found in input")
288
- return cls.fromtimestamp(int(timestamp) / 1000)
289
- return value
293
+ if isinstance(value, cls):
294
+ return value
295
+ if isinstance(value, datetime):
296
+ return value
297
+ timestamp = value.get("time")
298
+ if not timestamp:
299
+ raise ValueError("No `time` attribute found in input")
300
+ return cls.fromtimestamp(int(timestamp) / 1000)
290
301
 
291
302
 
292
303
  class GroupChannel(XMLBaseModel):
@@ -304,19 +315,20 @@ class ChannelGroup(XMLBaseModel):
304
315
 
305
316
  id: UUID
306
317
  name: str
307
- description: Optional[str]
318
+ description: Optional[str] = None
308
319
  revision: str
309
320
 
310
321
  channels: List[GroupChannel]
311
322
 
312
- @validator("channels", pre=True)
313
- def strip_channels_roots(cls, value): # pylint: disable=no-self-use
323
+ @field_validator("channels", mode="before")
324
+ @classmethod
325
+ def strip_channels_roots(cls, value):
314
326
  """
315
327
  Extract the actual GroupChannel elements from the parsed-XML dictionary.
316
328
  The 'GroupChannel' element contains an element 'channel', which contains
317
329
  a list of GroupChannel elements which we actually want.
318
330
  """
319
- if "channel" in value:
331
+ if isinstance(value, dict) and "channel" in value:
320
332
  return value["channel"]
321
333
  return value
322
334
 
@@ -336,7 +348,7 @@ class ChannelModel(XMLBaseModel):
336
348
  __root_element__ = "channel"
337
349
  id: UUID
338
350
  name: str
339
- description: Optional[str]
351
+ description: Optional[str] = None
340
352
  revision: str
341
353
 
342
354
 
@@ -387,8 +399,8 @@ class EventModel(XMLBaseModel):
387
399
  name: str
388
400
  outcome: str
389
401
  attributes: Dict
390
- user_id: Optional[str]
391
- ip_address: Optional[str]
402
+ user_id: Optional[str] = None
403
+ ip_address: Optional[str] = None
392
404
  date_time: datetime
393
405
 
394
406
 
@@ -428,12 +440,12 @@ class ConnectorMessageData(MirthBaseModel):
428
440
  """Object mapping for connectorMessage `raw` or `parsed` data"""
429
441
 
430
442
  channel_id: UUID
431
- content: Optional[str]
443
+ content: Optional[str] = None
432
444
  content_type: str
433
- data_type: Optional[str]
445
+ data_type: Optional[str] = None
434
446
  encrypted: bool
435
447
  message_id: str
436
- message_data_id: Optional[str]
448
+ message_data_id: Optional[str] = None
437
449
 
438
450
 
439
451
  class ConnectorMessageModel(XMLBaseModel):
@@ -445,27 +457,28 @@ class ConnectorMessageModel(XMLBaseModel):
445
457
  server_id: UUID
446
458
  channel_id: str
447
459
 
448
- status: Optional[str]
460
+ status: Optional[str] = None
449
461
 
450
462
  received_date: MirthDatetime
451
463
 
452
464
  channel_name: str
453
- connector_name: Optional[str]
465
+ connector_name: Optional[str] = None
454
466
 
455
467
  message_id: str
456
468
  error_code: int
457
469
  send_attempts: int
458
470
 
459
- raw: Optional[ConnectorMessageData]
460
- encoded: Optional[ConnectorMessageData]
461
- sent: Optional[ConnectorMessageData]
462
- response: Optional[ConnectorMessageData]
471
+ raw: Optional[ConnectorMessageData] = None
472
+ encoded: Optional[ConnectorMessageData] = None
473
+ sent: Optional[ConnectorMessageData] = None
474
+ response: Optional[ConnectorMessageData] = None
463
475
 
464
476
  meta_data_id: int
465
477
  meta_data_map: Dict[str, Optional[str]]
466
478
 
467
- @validator("meta_data_map", pre=True)
468
- def convert_hashmap(cls, value): # pylint: disable=no-self-use
479
+ @field_validator("meta_data_map", mode="before")
480
+ @classmethod
481
+ def convert_hashmap(cls, value):
469
482
  """Convert the XML hashmap into a Python dictionary"""
470
483
  return convert_hashmap(value)
471
484
 
@@ -483,8 +496,9 @@ class ChannelMessageModel(XMLBaseModel):
483
496
 
484
497
  connector_messages: Dict[int, ConnectorMessageModel]
485
498
 
486
- @validator("connector_messages", pre=True)
487
- def convert_hashmap(cls, value): # pylint: disable=no-self-use
499
+ @field_validator("connector_messages", mode="before")
500
+ @classmethod
501
+ def convert_hashmap(cls, value):
488
502
  """Convert the XML hashmap into a Python dictionary"""
489
503
  return convert_hashmap(value)
490
504
 
@@ -514,5 +528,5 @@ class MirthErrorMessageModel(XMLBaseModel):
514
528
 
515
529
  status: str
516
530
  message: str
517
- error: Optional[str]
518
- status_message: Optional[str]
531
+ error: Optional[str] = None
532
+ status_message: Optional[str] = None
@@ -6,15 +6,16 @@ packages = [
6
6
  {include = "mirth_client"},
7
7
  ]
8
8
  readme = "README.md"
9
- version = "4.2.0"
9
+ version = "5.0.0"
10
+
10
11
 
11
12
  [tool.poetry.dependencies]
12
13
  Sphinx = {version = ">=3.5.3,<8.0.0", optional = true}
13
14
  httpx = ">=0.23,<0.28.2"
14
- pydantic = ">=1.8.2,<3.0.0"
15
+ pydantic = ">=2.0.0,<3.0.0"
15
16
  python = "^3.9"
16
17
  semver = ">=2.13,<4.0"
17
- sphinx-rtd-theme = {version = ">=0.5.1,<2.1.0", optional = true}
18
+ sphinx-rtd-theme = {version = ">=0.5.1,<3.2.0", optional = true}
18
19
  typing-extensions = ">=3.10,<5.0"
19
20
  xmltodict = ">=0.12,<1.1"
20
21
 
File without changes
File without changes