Skip to content

Commit

Permalink
fix: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Dec 4, 2023
1 parent 4e421bf commit dbbc6b3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 44 deletions.
8 changes: 8 additions & 0 deletions src/dbus_fast/service.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ cdef class _Method:
cdef public SignatureTree in_signature_tree
cdef public SignatureTree out_signature_tree



cdef tuple _real_fn_result_to_body(
object result,
SignatureTree signature_tree,
bint replace_fds
)

cdef class ServiceInterface:

cdef public str name
Expand Down
75 changes: 31 additions & 44 deletions src/dbus_fast/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,35 @@ def decorator(fn):
return decorator


def _real_fn_result_to_body(
result: Optional[Any],
signature_tree: SignatureTree,
replace_fds: bool,
) -> Tuple[List[Any], List[int]]:
out_len = len(signature_tree.types)
if result is None:
final_result = []
else:
if out_len == 1:
final_result = [result]
else:
result_type = type(result)
if result_type is not list and result_type is not tuple:
raise SignatureBodyMismatchError(
"Expected signal to return a list or tuple of arguments"
)
final_result = result

if out_len != len(final_result):
raise SignatureBodyMismatchError(
f"Signature and function return mismatch, expected {len(signature_tree.types)} arguments but got {len(result)}"
)

if not replace_fds:
return final_result, []
return replace_fds_with_idx(signature_tree, final_result)


class ServiceInterface:
"""An abstract class that can be extended by the user to define DBus services.
Expand Down Expand Up @@ -526,28 +555,7 @@ def _fn_result_to_body(
signature_tree: SignatureTree,
replace_fds: bool = True,
) -> Tuple[List[Any], List[int]]:
out_len = len(signature_tree.types)
if result is None:
final_result = []
else:
if out_len == 1:
final_result = [result]
else:
result_type = type(result)
if result_type is not list and result_type is not tuple:
raise SignatureBodyMismatchError(
"Expected signal to return a list or tuple of arguments"
)
final_result = result

if out_len != len(final_result):
raise SignatureBodyMismatchError(
f"Signature and function return mismatch, expected {len(signature_tree.types)} arguments but got {len(result)}"
)

if not replace_fds:
return final_result, []
return replace_fds_with_idx(signature_tree, final_result)
return _real_fn_result_to_body(result, signature_tree, replace_fds)

@staticmethod
def _c_fn_result_to_body(
Expand All @@ -559,28 +567,7 @@ def _c_fn_result_to_body(
wrapped in a list to be a message body. Also they may return fds
directly for type 'h' which need to be put into an external list."""
# https://github.com/cython/cython/issues/3327
out_len = len(signature_tree.types)
if result is None:
final_result = []
else:
if out_len == 1:
final_result = [result]
else:
result_type = type(result)
if result_type is not list and result_type is not tuple:
raise SignatureBodyMismatchError(
"Expected signal to return a list or tuple of arguments"
)
final_result = result

if out_len != len(final_result):
raise SignatureBodyMismatchError(
f"Signature and function return mismatch, expected {len(signature_tree.types)} arguments but got {len(result)}"
)

if not replace_fds:
return final_result, []
return replace_fds_with_idx(signature_tree, final_result)
return _real_fn_result_to_body(result, signature_tree, replace_fds)

@staticmethod
def _handle_signal(
Expand Down

0 comments on commit dbbc6b3

Please sign in to comment.