stompman 0.3.0__tar.gz → 0.3.1__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.1
2
2
  Name: stompman
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: Python STOMP client with pleasant API
5
5
  Home-page: https://github.com/vrslev/stompman
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "stompman"
3
- version = "0.3.0"
3
+ version = "0.3.1"
4
4
  description = "Python STOMP client with pleasant API"
5
5
  license = "MIT"
6
6
  authors = ["Lev Vereshchagin <mail@vrslev.com>"]
@@ -1,13 +1,20 @@
1
1
  import asyncio
2
2
  from collections.abc import AsyncGenerator, Iterator
3
3
  from dataclasses import dataclass, field
4
- from typing import Protocol, TypeVar, cast
4
+ from typing import Protocol, Self, TypedDict, TypeVar, cast
5
5
 
6
6
  from stompman.errors import ConnectionLostError
7
7
  from stompman.frames import AnyClientFrame, AnyServerFrame
8
8
  from stompman.protocol import NEWLINE, Parser, dump_frame
9
9
 
10
10
 
11
+ class _MultiHostHostLike(TypedDict):
12
+ username: str | None
13
+ password: str | None
14
+ host: str | None
15
+ port: int | None
16
+
17
+
11
18
  @dataclass
12
19
  class ConnectionParameters:
13
20
  host: str
@@ -15,6 +22,41 @@ class ConnectionParameters:
15
22
  login: str
16
23
  passcode: str = field(repr=False)
17
24
 
25
+ @classmethod
26
+ def from_pydantic_multihost_hosts(cls, hosts: list[_MultiHostHostLike]) -> list[Self]:
27
+ """Create connection parameters from a list of `MultiHostUrl` objects.
28
+
29
+ .. code-block:: python
30
+ import stompman.
31
+
32
+ ArtemisDsn = typing.Annotated[
33
+ pydantic_core.MultiHostUrl,
34
+ pydantic.UrlConstraints(
35
+ host_required=True,
36
+ allowed_schemes=["tcp"],
37
+ ),
38
+ ]
39
+
40
+ async with stompman.Client(
41
+ servers=stompman.ConnectionParameters.from_pydantic_multihost_hosts(
42
+ ArtemisDsn("tcp://lev:pass@host1:61616,host1:61617,host2:61616").hosts()
43
+ ),
44
+ ):
45
+ ...
46
+ """
47
+ servers: list[Self] = []
48
+ for host in hosts:
49
+ if host["host"] is None:
50
+ raise ValueError("host must be set")
51
+ if host["port"] is None:
52
+ raise ValueError("port must be set")
53
+ if host["username"] is None:
54
+ raise ValueError("username must be set")
55
+ if host["password"] is None:
56
+ raise ValueError("password must be set")
57
+ servers.append(cls(host=host["host"], port=host["port"], login=host["username"], passcode=host["password"]))
58
+ return servers
59
+
18
60
 
19
61
  FrameT = TypeVar("FrameT", bound=AnyClientFrame | AnyServerFrame)
20
62
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes