Skip to content

Commit

Permalink
Change: Improve to_comma_list function signature
Browse files Browse the repository at this point in the history
Allow to pass any object that supports the __str__ protocol method.
  • Loading branch information
bjoernricks authored and greenbonebot committed Jun 14, 2024
1 parent ad84cb9 commit 8b00e03
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gvm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
import re
import warnings
from functools import wraps
from typing import Any, Callable, List, Optional, Type, Union
from typing import (
Any,
Callable,
Iterable,
List,
Optional,
Protocol,
Type,
Union,
)

from gvm.xml import XmlCommand, XmlError, parse_xml

Expand Down Expand Up @@ -146,8 +155,12 @@ def to_base64(value: str) -> str:
return base64.b64encode(value.encode("utf-8")).decode(encoding="utf-8")


def to_comma_list(value: List) -> str:
return ",".join(value)
class SupportsStr(Protocol):
def __str__(self) -> str: ...


def to_comma_list(value: Iterable[SupportsStr]) -> str:
return ",".join([str(value) for value in value])


@deprecated(since="24.3.0", reason="Please use XmlCommand.add_filter instead.")
Expand Down

0 comments on commit 8b00e03

Please sign in to comment.