Skip to content

Commit

Permalink
Add some documentation strings for URI and Parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed May 16, 2024
1 parent 04b22c3 commit 1f2e41f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []
extensions = [
"sphinx.ext.autodoc",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
Expand Down
9 changes: 9 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,14 @@ sipmessage
The ``sipmessage`` project provides a set of Python helpers and structures
for parsing SIP messages.

API Reference
-------------

.. automodule:: sipmessage.uri
:members:

.. automodule:: sipmessage.parameters
:members:

.. toctree::
:maxdepth: 2
7 changes: 7 additions & 0 deletions src/sipmessage/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@


class Parameters(dict[str, str | None]):
"""
A dictionary describing URI parameters.
"""

@classmethod
def parse(cls, val: str) -> "Parameters":
"""
Parse the given string into a :class:`Parameters` instance.
"""
p = cls()
if val:
for bit in val.split(";"):
Expand Down
18 changes: 18 additions & 0 deletions src/sipmessage/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,33 @@

@dataclasses.dataclass
class URI:
"""
A SIP or SIPS URL as described by RFC3261.
"""

scheme: str
"The URL scheme specifier."

host: str
"The host providing the SIP resource."

user: str | None = None
"The identifier of a particular resource at the host being addressed."

password: str | None = None
"A password associated with the user."

port: int | None = None
"The port number where the request is to be sent."

parameters: Parameters = dataclasses.field(default_factory=Parameters)
"Parameters affecting a request constructed from the URI."

@classmethod
def parse(cls, value: str) -> "URI":
"""
Parse the given string into a :class:`URI` instance.
"""
parsed = urllib.parse.urlparse(value)
if "@" in parsed.path:
user_password, host_port = parsed.path.split("@")
Expand Down

0 comments on commit 1f2e41f

Please sign in to comment.