aboutsummaryrefslogtreecommitdiff
path: root/ouroboros/_qosspec.py
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-07-26 13:49:26 +0200
committerDimitri Staessens <dimitri@ouroboros.rocks>2026-07-26 14:50:26 +0200
commit33f3c6fc4ca8810cee4c517594be725a26eec70c (patch)
treec4b2f8c14357b1b4e979e01c3b516ddf254f3b98 /ouroboros/_qosspec.py
parent3947452e391b1f1fc3933b28ce97d86e3b555d84 (diff)
downloadpyouroboros-33f3c6fc4ca8810cee4c517594be725a26eec70c.tar.gz
pyouroboros-33f3c6fc4ca8810cee4c517594be725a26eec70c.zip
pyouroboros: Use consistent format docstringsHEADmaster
This is basically a clean up pass to make sure all docstrings are aligned. The copyright banners are replaced by SPDX statements. Also did a general clean up on the comments. Passes pylint. No structural changes. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Diffstat (limited to 'ouroboros/_qosspec.py')
-rw-r--r--ouroboros/_qosspec.py49
1 files changed, 20 insertions, 29 deletions
diff --git a/ouroboros/_qosspec.py b/ouroboros/_qosspec.py
index 6031c42..5c8b245 100644
--- a/ouroboros/_qosspec.py
+++ b/ouroboros/_qosspec.py
@@ -1,47 +1,35 @@
#
-# Ouroboros - Copyright (C) 2016 - 2026
-#
-# Internal helpers for translating QoSSpec <-> CFFI qosspec_t.
-#
-# Dimitri Staessens <dimitri@ouroboros.rocks>
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# version 2.1 as published by the Free Software Foundation.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., http://www.fsf.org/about/contact/.
+# SPDX-FileCopyrightText: 2016 - 2026 Dimitri Staessens
+# SPDX-License-Identifier: LGPL-2.1-only
#
-"""Shared QoSSpec <-> qosspec_t conversion helpers.
+"""
+Shared QoSSpec <-> qosspec_t conversion helpers.
-dev.py and irm.py each link against their own CFFI extension module
-(``_ouroboros_dev_cffi`` and ``_ouroboros_irm_cffi``), so they each
-have their own ``ffi`` instance and their own ``qosspec_t`` type.
-CFFI types are not interchangeable across modules, so these helpers
-take the caller's ``ffi`` instance as a parameter.
+CFFI types are not interchangeable across extension modules, so the
+caller passes its own ``ffi`` instance.
"""
from __future__ import annotations
-from typing import Optional
+from typing import TYPE_CHECKING, Any, Optional
from ouroboros.qos import QoSSpec
+if TYPE_CHECKING:
+ from cffi import FFI
-def qos_to_qosspec(ffi, qos: Optional[QoSSpec]):
- """Convert a :class:`QoSSpec` to a freshly-allocated ``qosspec_t *``.
+
+def qos_to_qosspec(ffi: FFI, qos: Optional[QoSSpec]) -> Any:
+ """
+ Convert a :class:`QoSSpec` to a freshly-allocated ``qosspec_t *``.
Returns ``ffi.NULL`` when *qos* is ``None``.
"""
+
if qos is None:
return ffi.NULL
+
return ffi.new("qosspec_t *",
[qos.service,
qos.delay,
@@ -53,13 +41,16 @@ def qos_to_qosspec(ffi, qos: Optional[QoSSpec]):
qos.timeout])
-def qosspec_to_qos(ffi, _qos) -> Optional[QoSSpec]:
- """Convert a ``qosspec_t *`` back to a :class:`QoSSpec`.
+def qosspec_to_qos(ffi: FFI, _qos: Any) -> Optional[QoSSpec]:
+ """
+ Convert a ``qosspec_t *`` back to a :class:`QoSSpec`.
Returns ``None`` when *_qos* is ``ffi.NULL``.
"""
+
if _qos == ffi.NULL:
return None
+
return QoSSpec(service=_qos.service,
delay=_qos.delay,
bandwidth=_qos.bandwidth,