sipmessage 0.1.1__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.
sipmessage/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ #
2
+ # Copyright (C) Spacinov SAS
3
+ # Distributed under the 2-clause BSD license
4
+ #
5
+
6
+ import importlib.metadata
7
+
8
+ __version__ = importlib.metadata.version("sipmessage")
@@ -0,0 +1,28 @@
1
+ #
2
+ # Copyright (C) Spacinov SAS
3
+ # Distributed under the 2-clause BSD license
4
+ #
5
+
6
+
7
+ class Parameters(dict[str, str | None]):
8
+ """
9
+ A dictionary describing URI parameters.
10
+ """
11
+
12
+ @classmethod
13
+ def parse(cls, val: str) -> "Parameters":
14
+ """
15
+ Parse the given string into a :class:`Parameters` instance.
16
+ """
17
+ p = cls()
18
+ if val:
19
+ for bit in val.split(";"):
20
+ if "=" in bit:
21
+ k, v = bit.split("=", 1)
22
+ else:
23
+ k, v = bit, None
24
+ p[k] = v
25
+ return p
26
+
27
+ def __str__(self) -> str:
28
+ return ";".join([k if v is None else (k + "=" + v) for k, v in self.items()])
sipmessage/uri.py ADDED
@@ -0,0 +1,98 @@
1
+ #
2
+ # Copyright (C) Spacinov SAS
3
+ # Distributed under the 2-clause BSD license
4
+ #
5
+
6
+ import dataclasses
7
+ import urllib.parse
8
+
9
+ from .parameters import Parameters
10
+
11
+
12
+ @dataclasses.dataclass
13
+ class URI:
14
+ """
15
+ A SIP or SIPS URL as described by RFC3261.
16
+ """
17
+
18
+ scheme: str
19
+ "The URL scheme specifier."
20
+
21
+ host: str
22
+ "The host providing the SIP resource."
23
+
24
+ user: str | None = None
25
+ "The identifier of a particular resource at the host being addressed."
26
+
27
+ password: str | None = None
28
+ "A password associated with the user."
29
+
30
+ port: int | None = None
31
+ "The port number where the request is to be sent."
32
+
33
+ parameters: Parameters = dataclasses.field(default_factory=Parameters)
34
+ "Parameters affecting a request constructed from the URI."
35
+
36
+ @classmethod
37
+ def parse(cls, value: str) -> "URI":
38
+ """
39
+ Parse the given string into a :class:`URI` instance.
40
+ """
41
+ parsed = urllib.parse.urlparse(value)
42
+ if "@" in parsed.path:
43
+ user_password, host_port = parsed.path.split("@")
44
+ if ":" in user_password:
45
+ user, password = user_password.split(":")
46
+ else:
47
+ user = user_password
48
+ password = None
49
+ else:
50
+ host_port = parsed.path
51
+ user = None
52
+ password = None
53
+ if ":" in host_port:
54
+ host, port_ = host_port.split(":")
55
+ port = int(port_)
56
+ else:
57
+ host = host_port
58
+ port = None
59
+ return cls(
60
+ scheme=parsed.scheme,
61
+ host=host,
62
+ port=port,
63
+ user=user,
64
+ password=password,
65
+ parameters=Parameters.parse(parsed.params),
66
+ )
67
+
68
+ @property
69
+ def global_phone_number(self) -> str | None:
70
+ """
71
+ The global phone number (E.164) of this URI, if described by the URI.
72
+
73
+ This is one of the possibilities for the `userinfo` part described in RFC3261,
74
+ with telephone-subscriber in RFC2806:
75
+
76
+ > userinfo = user | telephone-subscriber
77
+ > telephone-subscriber = global-phone-number | local-phone-number
78
+ """
79
+ if self.user is None:
80
+ return None
81
+ if self.user[0] == "+" and self.user[1:].isnumeric():
82
+ return self.user
83
+ else:
84
+ return None
85
+
86
+ def __str__(self) -> str:
87
+ s = self.scheme + ":"
88
+ if self.user is not None:
89
+ s += self.user
90
+ if self.password is not None:
91
+ s += ":" + self.password
92
+ s += "@"
93
+ s += self.host
94
+ if self.port is not None:
95
+ s += ":" + str(self.port)
96
+ if self.parameters:
97
+ s += ";" + str(self.parameters)
98
+ return s
@@ -0,0 +1,22 @@
1
+ Copyright (c) Spacinov SAS
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.1
2
+ Name: sipmessage
3
+ Version: 0.1.1
4
+ Summary: Pure python parsing of SIP messages and headers
5
+ Author-email: Spacinov Engineering <opensource@spacinov.com>
6
+ License: BSD License
7
+ Project-URL: Homepage, https://sipmessage.readthedocs.io/
8
+ Project-URL: Documentation, https://sipmessage.readthedocs.io/
9
+ Project-URL: Repository, https://github.com/spacinov/sipmessage
10
+ Project-URL: Issues, https://github.com/spacinov/sipmessage/issues
11
+ Keywords: SIP,RFC3261
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Intended Audience :: Telecommunications Industry
16
+ Classifier: License :: OSI Approved :: BSD License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Communications :: Telephony
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/x-rst
25
+ License-File: LICENSE
26
+ Provides-Extra: dev
27
+ Requires-Dist: check-manifest ; extra == 'dev'
28
+ Requires-Dist: coverage ; extra == 'dev'
29
+ Requires-Dist: mypy ; extra == 'dev'
30
+ Requires-Dist: pyroma ; extra == 'dev'
31
+ Requires-Dist: ruff ; extra == 'dev'
32
+
33
+ ==========
34
+ sipmessage
35
+ ==========
36
+
37
+
38
+ The ``sipmessage`` project provides a set of Python helpers and structures
39
+ for parsing SIP messages.
@@ -0,0 +1,8 @@
1
+ sipmessage/__init__.py,sha256=txJ3zZKGt-8aD8qiVAGoFjqrWiALQBAPDXyb6oyTc4g,161
2
+ sipmessage/parameters.py,sha256=MITFlK42TlWUMM_lY5uTzwu-vq4uNTz6Z9ffPlwka6M,704
3
+ sipmessage/uri.py,sha256=vQb1D9Rhd_Z7OFEXsO6y0BKj81N3xc7W8LIILU00bco,2740
4
+ sipmessage-0.1.1.dist-info/LICENSE,sha256=DD5LT_ZPvYNHlVtngdMvFLLM9BGMXkXOi511xl2C_Oo,1295
5
+ sipmessage-0.1.1.dist-info/METADATA,sha256=dufgN0pvrE2C8WqGyI5Wrkq-fFaqzmnqGQtPypm3vVY,1439
6
+ sipmessage-0.1.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
7
+ sipmessage-0.1.1.dist-info/top_level.txt,sha256=BYw0OcqRwUIAgRyDF3GmyU7-QGh83otmI4tmamhCc8E,11
8
+ sipmessage-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.43.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ sipmessage